nuntium_api 0.7 → 0.8
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.
- data/lib/nuntium.rb +42 -37
 - metadata +18 -23
 
    
        data/lib/nuntium.rb
    CHANGED
    
    | 
         @@ -1,10 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Provides access to the Nuntium Public API.
         
     | 
| 
      
 2 
     | 
    
         
            +
            #
         
     | 
| 
      
 3 
     | 
    
         
            +
            # === Install
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            #   gem install nuntium_api
         
     | 
| 
      
 6 
     | 
    
         
            +
            #
         
     | 
| 
      
 7 
     | 
    
         
            +
            # === Example
         
     | 
| 
      
 8 
     | 
    
         
            +
            #
         
     | 
| 
      
 9 
     | 
    
         
            +
            #   api = Nuntium.new 'service_url', 'account_name', 'application_name', 'application_password'
         
     | 
| 
       1 
10 
     | 
    
         
             
            require 'rubygems'
         
     | 
| 
       2 
11 
     | 
    
         
             
            require 'httparty'
         
     | 
| 
      
 12 
     | 
    
         
            +
            require 'json'
         
     | 
| 
       3 
13 
     | 
    
         | 
| 
       4 
14 
     | 
    
         
             
            # Provides access to the Nuntium Public API.
         
     | 
| 
       5 
15 
     | 
    
         
             
            class Nuntium
         
     | 
| 
       6 
16 
     | 
    
         
             
              include HTTParty
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
       8 
18 
     | 
    
         
             
              # Creates an application-authenticated Nuntium api access.
         
     | 
| 
       9 
19 
     | 
    
         
             
              def initialize(url, account, application, password)
         
     | 
| 
       10 
20 
     | 
    
         
             
                @url = url
         
     | 
| 
         @@ -12,21 +22,21 @@ class Nuntium 
     | 
|
| 
       12 
22 
     | 
    
         
             
                @application = application
         
     | 
| 
       13 
23 
     | 
    
         
             
                @auth = {:username => "#{account}/#{application}", :password => password}
         
     | 
| 
       14 
24 
     | 
    
         
             
              end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
       16 
26 
     | 
    
         
             
              # Gets the list of countries known to Nuntium.
         
     | 
| 
       17 
27 
     | 
    
         
             
              def countries
         
     | 
| 
       18 
28 
     | 
    
         
             
                self.class.get "#{@url}/api/countries.json"
         
     | 
| 
       19 
29 
     | 
    
         
             
              end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
       21 
31 
     | 
    
         
             
              # Gets a country given its iso2 or iso3 code, or nil if a country with that iso does not exist.
         
     | 
| 
       22 
32 
     | 
    
         
             
              def country(iso)
         
     | 
| 
       23 
33 
     | 
    
         
             
                c = self.class.get "#{@url}/api/countries/#{iso}.json"
         
     | 
| 
       24 
34 
     | 
    
         
             
                return nil if c.class <= String
         
     | 
| 
       25 
35 
     | 
    
         
             
                c
         
     | 
| 
       26 
36 
     | 
    
         
             
              end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
       28 
38 
     | 
    
         
             
              # Gets the list of carriers known to Nuntium that belong to a country, given its
         
     | 
| 
       29 
     | 
    
         
            -
              # iso2 or iso3 code.
         
     | 
| 
      
 39 
     | 
    
         
            +
              # iso2 or iso3 code. Gets all carriers if no country is specified.
         
     | 
| 
       30 
40 
     | 
    
         
             
              def carriers(country_id = nil)
         
     | 
| 
       31 
41 
     | 
    
         
             
                if country_id
         
     | 
| 
       32 
42 
     | 
    
         
             
                  self.class.get "#{@url}/api/carriers.json", :query => {:country_id => country_id}
         
     | 
| 
         @@ -34,14 +44,14 @@ class Nuntium 
     | 
|
| 
       34 
44 
     | 
    
         
             
                  self.class.get "#{@url}/api/carriers.json"
         
     | 
| 
       35 
45 
     | 
    
         
             
                end
         
     | 
| 
       36 
46 
     | 
    
         
             
              end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
       38 
48 
     | 
    
         
             
              # Gets a carrier given its guid, or nil if a carrier with that guid does not exist.
         
     | 
| 
       39 
49 
     | 
    
         
             
              def carrier(guid)
         
     | 
| 
       40 
50 
     | 
    
         
             
                c = self.class.get "#{@url}/api/carriers/#{guid}.json"
         
     | 
| 
       41 
51 
     | 
    
         
             
                return nil if c.class <= String
         
     | 
| 
       42 
52 
     | 
    
         
             
                c
         
     | 
| 
       43 
53 
     | 
    
         
             
              end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
       45 
55 
     | 
    
         
             
              # Returns the list of channels belonging to the application or that don't
         
     | 
| 
       46 
56 
     | 
    
         
             
              # belong to any application.
         
     | 
| 
       47 
57 
     | 
    
         
             
              def channels
         
     | 
| 
         @@ -51,7 +61,7 @@ class Nuntium 
     | 
|
| 
       51 
61 
     | 
    
         
             
                  read_configuration channel
         
     | 
| 
       52 
62 
     | 
    
         
             
                end
         
     | 
| 
       53 
63 
     | 
    
         
             
              end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
       55 
65 
     | 
    
         
             
              # Returns a chnanel given its name, or nil if the channel doesn't exist
         
     | 
| 
       56 
66 
     | 
    
         
             
              def channel(name)
         
     | 
| 
       57 
67 
     | 
    
         
             
                channel = self.class.get "#{@url}/api/channels/#{name}.json", :basic_auth => @auth
         
     | 
| 
         @@ -59,35 +69,29 @@ class Nuntium 
     | 
|
| 
       59 
69 
     | 
    
         
             
                read_configuration channel
         
     | 
| 
       60 
70 
     | 
    
         
             
                channel
         
     | 
| 
       61 
71 
     | 
    
         
             
              end
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
       63 
73 
     | 
    
         
             
              # Creates a channel.
         
     | 
| 
       64 
     | 
    
         
            -
              #  
     | 
| 
       65 
     | 
    
         
            -
              #   create_channel :name => 'foo', :kind => 'qst_server', :protocol => 'sms',
         
     | 
| 
       66 
     | 
    
         
            -
              #     :configuration => {:password => 'bar'}
         
     | 
| 
      
 74 
     | 
    
         
            +
              #   create_channel :name => 'foo', :kind => 'qst_server', :protocol => 'sms', :configuration => {:password => 'bar'}
         
     | 
| 
       67 
75 
     | 
    
         
             
              def create_channel(channel)
         
     | 
| 
       68 
76 
     | 
    
         
             
                write_configuration channel
         
     | 
| 
       69 
     | 
    
         
            -
                self.class.post "#{@url}/api/channels.json", :basic_auth => @auth, :body => channel
         
     | 
| 
      
 77 
     | 
    
         
            +
                self.class.post "#{@url}/api/channels.json", :basic_auth => @auth, :body => channel.to_json
         
     | 
| 
       70 
78 
     | 
    
         
             
              end
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
              #  
     | 
| 
       73 
     | 
    
         
            -
              #  
     | 
| 
       74 
     | 
    
         
            -
              #   update_channel :name => 'foo', :kind => 'qst_server', :protocol => 'sms',
         
     | 
| 
       75 
     | 
    
         
            -
              #     :configuration => {:password => 'bar'}
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
              # Updates a channel.
         
     | 
| 
      
 81 
     | 
    
         
            +
              #   update_channel :name => 'foo', :kind => 'qst_server', :protocol => 'sms', :configuration => {:password => 'bar'}
         
     | 
| 
       76 
82 
     | 
    
         
             
              def update_channel(channel)
         
     | 
| 
       77 
83 
     | 
    
         
             
                write_configuration channel
         
     | 
| 
       78 
     | 
    
         
            -
                self.class.put "#{@url}/api/channels/#{channel['name']}.json", :basic_auth => @auth, :body => channel
         
     | 
| 
      
 84 
     | 
    
         
            +
                self.class.put "#{@url}/api/channels/#{channel['name']}.json", :basic_auth => @auth, :body => channel.to_json
         
     | 
| 
       79 
85 
     | 
    
         
             
              end
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
       81 
87 
     | 
    
         
             
              # Deletes a chnanel given its name.
         
     | 
| 
       82 
88 
     | 
    
         
             
              def delete_channel(name)
         
     | 
| 
       83 
89 
     | 
    
         
             
                self.class.delete "#{@url}/api/channels/#{name}", :basic_auth => @auth
         
     | 
| 
       84 
90 
     | 
    
         
             
              end
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
       86 
92 
     | 
    
         
             
              # Returns the list of candidate channels when simulating routing the given
         
     | 
| 
       87 
93 
     | 
    
         
             
              # AO message.
         
     | 
| 
       88 
     | 
    
         
            -
              #  
     | 
| 
       89 
     | 
    
         
            -
              #   candidate_channels_for_ao :from => 'sms://1', :to => 'sms://2', 
         
     | 
| 
       90 
     | 
    
         
            -
              #     :subject => 'hello', :body => 'hi!'
         
     | 
| 
      
 94 
     | 
    
         
            +
              #   candidate_channels_for_ao :from => 'sms://1', :to => 'sms://2', :subject => 'hello', :body => 'hi!'
         
     | 
| 
       91 
95 
     | 
    
         
             
              def candidate_channels_for_ao(message)
         
     | 
| 
       92 
96 
     | 
    
         
             
                chans = self.class.get "#{@url}/api/candidate/channels.json", :basic_auth => @auth, :body => message
         
     | 
| 
       93 
97 
     | 
    
         
             
                return nil if chans.class <= String
         
     | 
| 
         @@ -95,30 +99,31 @@ class Nuntium 
     | 
|
| 
       95 
99 
     | 
    
         
             
                  read_configuration channel
         
     | 
| 
       96 
100 
     | 
    
         
             
                end
         
     | 
| 
       97 
101 
     | 
    
         
             
              end
         
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
              # Sends  
     | 
| 
       100 
     | 
    
         
            -
              # Example:
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
              # Sends one or many AO messages. Returns an HTTParty::Response instance.
         
     | 
| 
       101 
104 
     | 
    
         
             
              #   send_ao :from => 'sms://1', :to => 'sms://2', :subject => 'hello', :body => 'hi!'
         
     | 
| 
       102 
     | 
    
         
            -
               
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
      
 105 
     | 
    
         
            +
              #   send_ao [{:from => 'sms://1', :to => 'sms://2', :subject => 'hello', :body => 'hi!'}, {...}]
         
     | 
| 
      
 106 
     | 
    
         
            +
              def send_ao(messages)
         
     | 
| 
      
 107 
     | 
    
         
            +
                body = messages.is_a?(Array) ? messages.to_json : messages
         
     | 
| 
      
 108 
     | 
    
         
            +
                self.class.post "#{@url}/#{@account}/#{@application}/send_ao.json", :basic_auth => @auth, :body => body
         
     | 
| 
       104 
109 
     | 
    
         
             
              end
         
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
              private 
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
              private
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
       108 
113 
     | 
    
         
             
              def write_configuration(channel)
         
     | 
| 
       109 
114 
     | 
    
         
             
                configuration = []
         
     | 
| 
       110 
115 
     | 
    
         
             
                channel[:configuration].each do |name, value|
         
     | 
| 
       111 
     | 
    
         
            -
                  configuration << {:name => name, :value => value} 
     | 
| 
      
 116 
     | 
    
         
            +
                  configuration << {:name => name, :value => value}
         
     | 
| 
       112 
117 
     | 
    
         
             
                end
         
     | 
| 
       113 
118 
     | 
    
         
             
                channel[:configuration] = configuration
         
     | 
| 
       114 
     | 
    
         
            -
              end 
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
      
 119 
     | 
    
         
            +
              end
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
       116 
121 
     | 
    
         
             
              def read_configuration(channel)
         
     | 
| 
       117 
122 
     | 
    
         
             
                configuration = {}
         
     | 
| 
       118 
123 
     | 
    
         
             
                channel['configuration'].each do |hash|
         
     | 
| 
       119 
     | 
    
         
            -
                  configuration[hash['name']] = hash['value'] 
     | 
| 
      
 124 
     | 
    
         
            +
                  configuration[hash['name']] = hash['value']
         
     | 
| 
       120 
125 
     | 
    
         
             
                end
         
     | 
| 
       121 
126 
     | 
    
         
             
                channel['configuration'] = configuration
         
     | 
| 
       122 
127 
     | 
    
         
             
              end
         
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
       124 
129 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,12 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: nuntium_api
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
              prerelease: false
         
     | 
| 
       6 
     | 
    
         
            -
              segments: 
         
     | 
| 
       7 
     | 
    
         
            -
              - 0
         
     | 
| 
       8 
     | 
    
         
            -
              - 7
         
     | 
| 
       9 
     | 
    
         
            -
              version: "0.7"
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: "0.8"
         
     | 
| 
       10 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       11 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       12 
7 
     | 
    
         
             
            - InsTEDD
         
     | 
| 
         @@ -14,23 +9,29 @@ autorequire: 
     | 
|
| 
       14 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       15 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       16 
11 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
            date: 2010-06-08 00:00:00 + 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2010-06-08 00:00:00 +08:00
         
     | 
| 
       18 
13 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       19 
14 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       20 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       21 
16 
     | 
    
         
             
              name: httparty
         
     | 
| 
       22 
     | 
    
         
            -
               
     | 
| 
       23 
     | 
    
         
            -
               
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 18 
     | 
    
         
            +
              version_requirement: 
         
     | 
| 
      
 19 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement 
         
     | 
| 
       25 
20 
     | 
    
         
             
                requirements: 
         
     | 
| 
       26 
21 
     | 
    
         
             
                - - ">="
         
     | 
| 
       27 
22 
     | 
    
         
             
                  - !ruby/object:Gem::Version 
         
     | 
| 
       28 
     | 
    
         
            -
                    hash: 3
         
     | 
| 
       29 
     | 
    
         
            -
                    segments: 
         
     | 
| 
       30 
     | 
    
         
            -
                    - 0
         
     | 
| 
       31 
23 
     | 
    
         
             
                    version: "0"
         
     | 
| 
      
 24 
     | 
    
         
            +
                version: 
         
     | 
| 
      
 25 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 26 
     | 
    
         
            +
              name: json
         
     | 
| 
       32 
27 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       33 
     | 
    
         
            -
               
     | 
| 
      
 28 
     | 
    
         
            +
              version_requirement: 
         
     | 
| 
      
 29 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: "0"
         
     | 
| 
      
 34 
     | 
    
         
            +
                version: 
         
     | 
| 
       34 
35 
     | 
    
         
             
            description: Access the Nuntium API in ruby. Nuntium is an open source and free platform -developed by InSTEDD- that allows applications to send and receive all type of messages. Examples of messages are sms, emails and twitter direct messages.
         
     | 
| 
       35 
36 
     | 
    
         
             
            email: aborenszweig@manas.com.ar
         
     | 
| 
       36 
37 
     | 
    
         
             
            executables: []
         
     | 
| 
         @@ -51,27 +52,21 @@ rdoc_options: [] 
     | 
|
| 
       51 
52 
     | 
    
         
             
            require_paths: 
         
     | 
| 
       52 
53 
     | 
    
         
             
            - lib
         
     | 
| 
       53 
54 
     | 
    
         
             
            required_ruby_version: !ruby/object:Gem::Requirement 
         
     | 
| 
       54 
     | 
    
         
            -
              none: false
         
     | 
| 
       55 
55 
     | 
    
         
             
              requirements: 
         
     | 
| 
       56 
56 
     | 
    
         
             
              - - ">="
         
     | 
| 
       57 
57 
     | 
    
         
             
                - !ruby/object:Gem::Version 
         
     | 
| 
       58 
     | 
    
         
            -
                  hash: 3
         
     | 
| 
       59 
     | 
    
         
            -
                  segments: 
         
     | 
| 
       60 
     | 
    
         
            -
                  - 0
         
     | 
| 
       61 
58 
     | 
    
         
             
                  version: "0"
         
     | 
| 
      
 59 
     | 
    
         
            +
              version: 
         
     | 
| 
       62 
60 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
       63 
     | 
    
         
            -
              none: false
         
     | 
| 
       64 
61 
     | 
    
         
             
              requirements: 
         
     | 
| 
       65 
62 
     | 
    
         
             
              - - ">="
         
     | 
| 
       66 
63 
     | 
    
         
             
                - !ruby/object:Gem::Version 
         
     | 
| 
       67 
     | 
    
         
            -
                  hash: 3
         
     | 
| 
       68 
     | 
    
         
            -
                  segments: 
         
     | 
| 
       69 
     | 
    
         
            -
                  - 0
         
     | 
| 
       70 
64 
     | 
    
         
             
                  version: "0"
         
     | 
| 
      
 65 
     | 
    
         
            +
              version: 
         
     | 
| 
       71 
66 
     | 
    
         
             
            requirements: []
         
     | 
| 
       72 
67 
     | 
    
         | 
| 
       73 
68 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       74 
     | 
    
         
            -
            rubygems_version: 1.3. 
     | 
| 
      
 69 
     | 
    
         
            +
            rubygems_version: 1.3.5
         
     | 
| 
       75 
70 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       76 
71 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       77 
72 
     | 
    
         
             
            summary: Access the Nuntium API in ruby
         
     |