Class: Trumpet::Listener

Inherits:
Resource show all
Defined in:
lib/trumpet/listener.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(options) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/trumpet/listener.rb', line 4

def self.create(options)
  if options[:parameters][:receiver_id]
    Listener.new(Trumpet::Request.post("/receivers/#{options[:parameters][:receiver_id]}/listeners", options))
  else
    raise Trumpet::BadRequest, "Must specify a receiver id when creating a listener"
  end
end

.find(id, options = {}) ⇒ Object



12
13
14
# File 'lib/trumpet/listener.rb', line 12

def self.find(id, options={})
  Listener.new(Trumpet::Request.get("/listeners/#{id}", options))
end

Instance Method Details

#delete(options = {}) ⇒ Object



16
17
18
19
20
# File 'lib/trumpet/listener.rb', line 16

def delete(options={})
  options[:credentials] ||= @credentials
  options[:parse_response] = false
  !!Trumpet::Request.delete("/listeners/#{@id}", options)
end

#delivery_addressObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/trumpet/listener.rb', line 39

def delivery_address
  case URI.parse(uri).scheme
			when 'mailto' then URI.parse(uri).to
			when 'tel' then URI.parse(uri).opaque
			when 'twitter' then URI.parse(uri).opaque
when 'irc'
  url = URI.parse(uri)
    "#{url.host}##{url.fragment}"
			when 'im'
 url = URI.parse(uri)
    "#{url.user}@#{url.host}"
			end
end

#delivery_methodObject



29
30
31
32
33
34
35
36
37
# File 'lib/trumpet/listener.rb', line 29

def delivery_method
  case URI.parse(uri).scheme
			when 'mailto' then 'Email'
			when 'tel' then 'SMS'
			when 'twitter' then 'Twitter'
when 'irc' then 'IRC'
			when 'im' then 'IM'
			end
end

#receiver(options = {}) ⇒ Object



22
23
24
25
26
27
# File 'lib/trumpet/listener.rb', line 22

def receiver(options={})
  @receiver ||= begin
    options[:credentials] ||= @credentials
    Trumpet::Receiver.new(Trumpet::Request.get("/receivers/#{receiver_id}", options))
  end
end