Class: BoxcarAPI::Provider

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/boxcar_api.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider_key = {}, provider_secret = nil, screen_name = nil) ⇒ Provider

Returns a new instance of Provider.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/boxcar_api.rb', line 11

def initialize(provider_key ={}, provider_secret = nil, screen_name = nil)
  if provider_key.kind_of? Hash
    url = provider_key[:url]
    url.chop! if url.end_with? '/'

    @provider_key    =  url.match(/https?:\/\/\S+\/(.*)$/)[1]
    self.class.base_uri(url + "/notifications")
  else
    @provider_key    = provider_key
    @provider_secret = provider_secret
    @screen_name     = screen_name
    self.class.base_uri "https://boxcar.io/devices/providers/#{@provider_key}/notifications"
  end
end

Instance Attribute Details

#provider_keyObject

Returns the value of attribute provider_key.



9
10
11
# File 'lib/boxcar_api.rb', line 9

def provider_key
  @provider_key
end

#provider_secretObject

Returns the value of attribute provider_secret.



9
10
11
# File 'lib/boxcar_api.rb', line 9

def provider_secret
  @provider_secret
end

#screen_nameObject

Returns the value of attribute screen_name.



9
10
11
# File 'lib/boxcar_api.rb', line 9

def screen_name
  @screen_name
end

Instance Method Details

#batch_notify(emails, message, options = {:from_screen_name => screen_name, :from_remote_service_id => nil, :source_url => nil, :icon_url => nil}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/boxcar_api.rb', line 59

def batch_notify(emails, message, options = {:from_screen_name => screen_name, :from_remote_service_id => nil, :source_url => nil, :icon_url => nil})
  params = { :body => { :emails => emails,
    :notification => {
    :message => message,
    :from_screen_name => options[:from_screen_name],
    :from_remote_service_id => options[:from_remote_service_id],
    :source_url => options[:source_url],
    :icon_url => options[:icon_url]
  } 
  }}

  self.class.post("/", params)
end

#broadcast(message, options = {:from_screen_name => screen_name, :from_remote_service_id => nil, :source_url => nil, :icon_url => nil}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/boxcar_api.rb', line 31

def broadcast(message, options = {:from_screen_name => screen_name, :from_remote_service_id => nil, :source_url => nil, :icon_url => nil})
  params = { :body => { :secret => provider_secret,
    :notification => {
    :message => message,
    :from_screen_name => options[:from_screen_name],
    :from_remote_service_id => options[:from_remote_service_id],
    :source_url => options[:source_url],
    :icon_url => options[:icon_url]
  } 
  }}

  self.class.post("/broadcast", params)
end

#notify(email, message, options = {:from_screen_name => screen_name, :from_remote_service_id => nil, :source_url => nil, :icon_url => nil}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/boxcar_api.rb', line 45

def notify(email, message, options = {:from_screen_name => screen_name, :from_remote_service_id => nil, :source_url => nil, :icon_url => nil})
  params = { :body => { :email => email,
    :notification => {
    :message => message,
    :from_screen_name => options[:from_screen_name],
    :from_remote_service_id => options[:from_remote_service_id],
    :source_url => options[:source_url],
    :icon_url => options[:icon_url]
  } 
  }}

  self.class.post("/", params)
end

#subscribe(email) ⇒ Object



26
27
28
29
# File 'lib/boxcar_api.rb', line 26

def subscribe(email)
  params = { :body => { :email => email } }
  self.class.post("/subscribe", params)
end