nuntium_api 0.2 → 0.3

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 +92 -0
  2. metadata +5 -5
data/lib/nuntium.rb ADDED
@@ -0,0 +1,92 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ # Provides access to the Nuntium Public API.
5
+ class Nuntium
6
+ include HTTParty
7
+
8
+ # Creates an application-authenticated Nuntium api access.
9
+ def initialize(url, account, application, password)
10
+ @url = url
11
+ @account = account
12
+ @application = application
13
+ @auth = {:username => "#{account}/#{application}", :password => password}
14
+ end
15
+
16
+ # Gets the list of countries known to Nuntium.
17
+ def countries
18
+ self.class.get "#{@url}/api/countries.json"
19
+ end
20
+
21
+ # Gets a country given its iso2 or iso3 code, or nil if a country with that iso does not exist.
22
+ def country(iso)
23
+ c = self.class.get "#{@url}/api/countries/#{iso}.json"
24
+ c.strip.empty? ? nil : c
25
+ end
26
+
27
+ # Gets the list of carriers known to Nuntium that belong to a country, given its
28
+ # iso2 or iso3 code.
29
+ def carriers(country_id = nil)
30
+ if country_id
31
+ self.class.get "#{@url}/api/carriers.json", :query => {:country_id => country_id}
32
+ else
33
+ self.class.get "#{@url}/api/carriers.json"
34
+ end
35
+ end
36
+
37
+ # Gets a carrier given its guid, or nil if a carrier with that guid does not exist.
38
+ def carrier(guid)
39
+ c = self.class.get "#{@url}/api/carriers/#{guid}.json"
40
+ c.strip.empty? ? nil : c
41
+ end
42
+
43
+ # Returns the list of channels belonging to the application or that don't
44
+ # belong to any application.
45
+ def channels
46
+ self.class.get "#{@url}/api/channels.json", :basic_auth => @auth
47
+ end
48
+
49
+ # Returns a chnanel given its name, or nil if the channel doesn't exist
50
+ def channel(name)
51
+ c = self.class.get "#{@url}/api/channels/#{name}.json", :basic_auth => @auth
52
+ c.class <= String ? nil : c
53
+ end
54
+
55
+ # Creates a channel.
56
+ # Example:
57
+ # create_channel :name => 'foo', :kind => 'qst_server', :protocol => 'sms',
58
+ # :configuration => [{:name => 'password', :value => 'bar'}]
59
+ def create_channel(channel)
60
+ self.class.post "#{@url}/api/channels.json", :basic_auth => @auth, :body => channel
61
+ end
62
+
63
+ # Creates a channel.
64
+ # Example:
65
+ # update_channel :name => 'foo', :kind => 'qst_server', :protocol => 'sms',
66
+ # :configuration => [{:name => 'password', :value => 'bar'}]
67
+ def update_channel(channel)
68
+ self.class.put "#{@url}/api/channels/#{channel['name']}.json", :basic_auth => @auth, :body => channel
69
+ end
70
+
71
+ # Deletes a chnanel given its name.
72
+ def delete_channel(name)
73
+ self.class.delete "#{@url}/api/channels/#{name}", :basic_auth => @auth
74
+ end
75
+
76
+ # Returns the list of candidate channels when simulating routing the given
77
+ # AO message.
78
+ # Example:
79
+ # candidate_channels_for_ao :from => 'sms://1', :to => 'sms://2',
80
+ # :subject => 'hello', :body => 'hi!'
81
+ def candidate_channels_for_ao(message)
82
+ self.class.get "#{@url}/api/candidate/channels.json", :basic_auth => @auth, :body => message
83
+ end
84
+
85
+ # Sends an AO message.
86
+ # Example:
87
+ # send_ao :from => 'sms://1', :to => 'sms://2', :subject => 'hello', :body => 'hi!'
88
+ def send_ao(message)
89
+ self.class.post "#{@url}/#{@account}/#{@application}/send_ao", :basic_auth => @auth, :body => message
90
+ end
91
+
92
+ 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: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- version: "0.2"
8
+ - 3
9
+ version: "0.3"
10
10
  platform: ruby
11
11
  authors:
12
12
  - InsTEDD
@@ -39,8 +39,8 @@ extensions: []
39
39
 
40
40
  extra_rdoc_files: []
41
41
 
42
- files: []
43
-
42
+ files:
43
+ - lib/nuntium.rb
44
44
  has_rdoc: true
45
45
  homepage: http://code.google.com/p/nuntium-api-ruby
46
46
  licenses: []