nuntium_api 0.6 → 0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/nuntium.rb +40 -8
  2. metadata +3 -3
data/lib/nuntium.rb CHANGED
@@ -21,7 +21,8 @@ class Nuntium
21
21
  # Gets a country given its iso2 or iso3 code, or nil if a country with that iso does not exist.
22
22
  def country(iso)
23
23
  c = self.class.get "#{@url}/api/countries/#{iso}.json"
24
- c.class <= String ? nil : c
24
+ return nil if c.class <= String
25
+ c
25
26
  end
26
27
 
27
28
  # Gets the list of carriers known to Nuntium that belong to a country, given its
@@ -37,34 +38,43 @@ class Nuntium
37
38
  # Gets a carrier given its guid, or nil if a carrier with that guid does not exist.
38
39
  def carrier(guid)
39
40
  c = self.class.get "#{@url}/api/carriers/#{guid}.json"
40
- c.class <= String ? nil : c
41
+ return nil if c.class <= String
42
+ c
41
43
  end
42
44
 
43
45
  # Returns the list of channels belonging to the application or that don't
44
46
  # belong to any application.
45
47
  def channels
46
- self.class.get "#{@url}/api/channels.json", :basic_auth => @auth
48
+ chans = self.class.get "#{@url}/api/channels.json", :basic_auth => @auth
49
+ return nil if chans.class <= String
50
+ chans.each do |channel|
51
+ read_configuration channel
52
+ end
47
53
  end
48
54
 
49
55
  # Returns a chnanel given its name, or nil if the channel doesn't exist
50
56
  def channel(name)
51
- c = self.class.get "#{@url}/api/channels/#{name}.json", :basic_auth => @auth
52
- c.class <= String ? nil : c
57
+ channel = self.class.get "#{@url}/api/channels/#{name}.json", :basic_auth => @auth
58
+ return nil if channel.class <= String
59
+ read_configuration channel
60
+ channel
53
61
  end
54
62
 
55
63
  # Creates a channel.
56
64
  # Example:
57
65
  # create_channel :name => 'foo', :kind => 'qst_server', :protocol => 'sms',
58
- # :configuration => [{:name => 'password', :value => 'bar'}]
66
+ # :configuration => {:password => 'bar'}
59
67
  def create_channel(channel)
68
+ write_configuration channel
60
69
  self.class.post "#{@url}/api/channels.json", :basic_auth => @auth, :body => channel
61
70
  end
62
71
 
63
72
  # Creates a channel.
64
73
  # Example:
65
74
  # update_channel :name => 'foo', :kind => 'qst_server', :protocol => 'sms',
66
- # :configuration => [{:name => 'password', :value => 'bar'}]
75
+ # :configuration => {:password => 'bar'}
67
76
  def update_channel(channel)
77
+ write_configuration channel
68
78
  self.class.put "#{@url}/api/channels/#{channel['name']}.json", :basic_auth => @auth, :body => channel
69
79
  end
70
80
 
@@ -79,7 +89,11 @@ class Nuntium
79
89
  # candidate_channels_for_ao :from => 'sms://1', :to => 'sms://2',
80
90
  # :subject => 'hello', :body => 'hi!'
81
91
  def candidate_channels_for_ao(message)
82
- self.class.get "#{@url}/api/candidate/channels.json", :basic_auth => @auth, :body => message
92
+ chans = self.class.get "#{@url}/api/candidate/channels.json", :basic_auth => @auth, :body => message
93
+ return nil if chans.class <= String
94
+ chans.each do |channel|
95
+ read_configuration channel
96
+ end
83
97
  end
84
98
 
85
99
  # Sends an AO message.
@@ -89,4 +103,22 @@ class Nuntium
89
103
  self.class.post "#{@url}/#{@account}/#{@application}/send_ao", :basic_auth => @auth, :body => message
90
104
  end
91
105
 
106
+ private
107
+
108
+ def write_configuration(channel)
109
+ configuration = []
110
+ channel[:configuration].each do |name, value|
111
+ configuration << {:name => name, :value => value}
112
+ end
113
+ channel[:configuration] = configuration
114
+ end
115
+
116
+ def read_configuration(channel)
117
+ configuration = {}
118
+ channel['configuration'].each do |hash|
119
+ configuration[hash['name']] = hash['value']
120
+ end
121
+ channel['configuration'] = configuration
122
+ end
123
+
92
124
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nuntium_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- version: "0.6"
8
+ - 7
9
+ version: "0.7"
10
10
  platform: ruby
11
11
  authors:
12
12
  - InsTEDD