tropo-provisioning 0.0.21 → 0.0.22

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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tropo-provisioning (0.0.21)
5
+ activesupport
6
+ hashie (>= 0.2.1)
7
+ i18n
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ activesupport (3.1.0)
13
+ multi_json (~> 1.0)
14
+ diff-lcs (1.1.2)
15
+ fakeweb (1.3.0)
16
+ hashie (1.1.0)
17
+ i18n (0.6.0)
18
+ multi_json (1.0.3)
19
+ rdoc (3.9.4)
20
+ rspec (2.3.0)
21
+ rspec-core (~> 2.3.0)
22
+ rspec-expectations (~> 2.3.0)
23
+ rspec-mocks (~> 2.3.0)
24
+ rspec-core (2.3.1)
25
+ rspec-expectations (2.3.0)
26
+ diff-lcs (~> 1.1.2)
27
+ rspec-mocks (2.3.0)
28
+ yard (0.7.2)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ fakeweb
35
+ rdoc
36
+ rspec
37
+ tropo-provisioning!
38
+ yard
data/README.rdoc CHANGED
@@ -19,14 +19,17 @@ The Tropo Provisioning gem provides a library for convenient access to the Tropo
19
19
  == Requirements
20
20
 
21
21
  * Unit tests passed on: Ruby MRI v1.8.6/1.8.7, Ruby 1.9.2, JRuby 1.5.0 and MacRuby 0.6
22
- * RubyGems
22
+
23
+ * RubyGems: Check tropo-provisioning.gemspec
23
24
 
24
25
  == Installation
25
26
 
26
- $ sudo gem install tropo-provisioning
27
+ $ gem install tropo-provisioning
27
28
 
28
29
  == Usage
29
30
 
31
+ Any HTTP method can be accessed using the TropoProvisioning wrapper:
32
+
30
33
  require 'rubygems'
31
34
  require 'tropo-provisioning'
32
35
 
@@ -62,8 +65,11 @@ The Tropo Provisioning gem provides a library for convenient access to the Tropo
62
65
 
63
66
  ==== Tropo Provisioning API Documentation
64
67
 
65
- TBD
66
-
68
+ git clone https://github.com/tropo/tropo-provisioning
69
+ cd tropo-provisioning
70
+ bundle install
71
+ rake rdoc
72
+
67
73
  === Local & Generating Documentation
68
74
 
69
75
  ==== Developer
data/Rakefile CHANGED
@@ -1,46 +1,31 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "tropo-provisioning"
8
- gem.summary = "Library for interacting with the Tropo Provisioning API"
9
- gem.description = "Library for interacting with the Tropo Provisioning API"
10
- gem.email = "jsgoecke@voxeo.com"
11
- gem.homepage = "http://github.com/voxeo/tropo-provisioning"
12
- gem.authors = ["Jason Goecke"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- gem.add_dependency "hashie", ">= 0.2.1"
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
21
3
 
22
- require 'spec/rake/spectask'
23
- Spec::Rake::SpecTask.new(:spec) do |spec|
24
- spec.libs << 'lib' << 'spec'
25
- spec.spec_files = FileList['spec/**/*_spec.rb']
26
- end
4
+ task :default => [:test]
27
5
 
28
- Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- spec.libs << 'lib' << 'spec'
30
- spec.pattern = 'spec/**/*_spec.rb'
31
- spec.rcov = true
6
+ require 'rspec/core/rake_task'
7
+ require 'rake/rdoctask'
8
+ require 'tropo-provisioning/version'
9
+
10
+
11
+ RSpec::Core::RakeTask.new(:test) do |spec|
12
+ spec.skip_bundler = true
13
+ spec.pattern = ['spec/*_spec.rb']
14
+ spec.rspec_opts = '--color --format doc'
32
15
  end
33
16
 
34
- task :spec => :check_dependencies
35
17
 
36
- task :default => :spec
18
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
19
+ spec.pattern = 'spec/*_spec.rb'
20
+ spec.rcov = true
21
+ end
37
22
 
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
23
+ RDoc::Task.new do |rdoc|
41
24
 
42
25
  rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "tropo-provisioning #{version}"
26
+ rdoc.title = "tropo-provisioning #{TropoProvisioning::VERSION}"
27
+ rdoc.rdoc_files.include('LICENSE')
28
+ rdoc.options << '-c' << 'utf-8'
44
29
  rdoc.rdoc_files.include('README*')
45
30
  rdoc.rdoc_files.include('lib/**/*.rb')
46
31
  end
@@ -0,0 +1,3 @@
1
+ --- !map:Hashie::Mash
2
+ href: http://api.tropo.com/v1/applications/128973
3
+ application_id: "128973"
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+ require 'lib/tropo-provisioning'
4
+
5
+ config = YAML.load(File.open('examples/config.yml'))
6
+
7
+ # Create a new provisioning object with your Tropo credentials
8
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], :base_uri => 'http://172.16.10.125:8080/provisioning')
9
+
10
+ # Create an account
11
+ p provisioning.authenticate_account('jsgoecke', 'test123')
12
+
@@ -0,0 +1,5 @@
1
+ tropo:
2
+ username: jsgoecke
3
+ password: sancar119
4
+
5
+ filename: app_details.yml
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'lib/tropo-provisioning'
3
+
4
+ config = YAML.load(File.open('examples/config.yml'))
5
+ app_details = YAML.load(File.open("examples/#{config['filename']}"))
6
+
7
+ # Create a new provisioning object with your Tropo credentials
8
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], { :base_uri => 'http://api-smsified-eng.voxeo.net/v1'})
9
+
10
+ p provisioning.create_invitation({ :code => 'ABC457',
11
+ :count => 100,
12
+ :credit => 10 })
@@ -0,0 +1,25 @@
1
+ ## WARNING ##
2
+ # IF YOU RUN THIS SCRIPT, IT WILL DELETE ALL OF YOUR APPLICATIONS #
3
+ ## WARNING ##
4
+
5
+ require 'rubygems'
6
+ require 'lib/tropo-provisioning'
7
+
8
+ config = YAML.load(File.open('examples/config.yml'))
9
+
10
+ # Create a new provisioning object with your Tropo credentials
11
+ provisioning = TropoProvisioning.new(config['tropo']['username'],
12
+ config['tropo']['password'],
13
+ :base_uri => 'http://api.tropo.com/provisioning')
14
+
15
+ applications = provisioning.applications
16
+
17
+ p applications
18
+
19
+ applications.each do |app|
20
+ provisioning.delete_application(app.application_id)
21
+ end
22
+
23
+ ## WARNING ##
24
+ # IF YOU RUN THIS SCRIPT, IT WILL DELETE ALL OF YOUR APPLICATIONS #
25
+ ## WARNING ##
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+ require 'lib/tropo-provisioning'
4
+
5
+ config = YAML.load(File.open('examples/config.yml'))
6
+
7
+ # Create a new provisioning object with your Tropo credentials
8
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], :base_uri => 'http://api-smsified-eng.voxeo.net/v1')
9
+
10
+ # Create an account
11
+ p provisioning.balance('54228')
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'lib/tropo-provisioning'
3
+
4
+ config = YAML.load(File.open('examples/config.yml'))
5
+ app_details = YAML.load(File.open("examples/#{config['filename']}"))
6
+
7
+ # Create a new provisioning object with your Tropo credentials
8
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'])
9
+
10
+ # Then you may iterate through all of your configured applications
11
+ provisioning.applications_with_addresses.each do |app|
12
+ p app
13
+ puts '*'*10
14
+ end
15
+
16
+ # Now list a single application
17
+ p '<===============>'
18
+ p provisioning.application_with_address('124780')
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+ require 'lib/tropo-provisioning'
4
+
5
+ config = YAML.load(File.open('examples/config.yml'))
6
+
7
+ # Create a new provisioning object with your Tropo credentials
8
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], :base_uri => 'http://api-smsified-eng.voxeo.net/v1')
9
+
10
+ # List availble features
11
+ p provisioning.features
12
+
13
+ # List features configured for a user
14
+ p provisioning.user_features('54228')
15
+
16
+ p provisioning.user_enable_feature('54228', 'http://api-smsified-eng.voxeo.net/v1/users/12345/features/8')
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'lib/tropo-provisioning'
3
+
4
+ config = YAML.load(File.open('examples/config.yml'))
5
+ app_details = YAML.load(File.open("examples/#{config['filename']}"))
6
+
7
+ # Create a new provisioning object with your Tropo credentials
8
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], { :base_uri => 'http://api-smsified-eng.voxeo.net/v1'})
9
+
10
+ # Then you may iterate through all of your configured addresses
11
+ provisioning.invitations.each do |invitation|
12
+ p invitation
13
+ end
14
+
15
+ p provisioning.invitation('ABC456')
16
+
17
+ p provisioning.user_invitations '15909'
18
+
19
+ p provisioning.user_invitation '15909', 'ABC456'
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+ require 'lib/tropo-provisioning'
4
+ require 'json'
5
+
6
+ config = YAML.load(File.open('examples/config.yml'))
7
+
8
+ # Create a new provisioning object with your Tropo credentials
9
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], :base_uri => 'http://api-smsified-eng.voxeo.net/v1')
10
+
11
+ # Create an account
12
+ p provisioning.partitions
13
+ p provisioning.platforms('staging')
14
+
15
+
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+ require 'lib/tropo-provisioning'
4
+
5
+ config = YAML.load(File.open('examples/config.yml'))
6
+
7
+ # Create a new provisioning object with your Tropo credentials
8
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], :base_uri => 'http://api-smsified-eng.voxeo.net/v1')
9
+
10
+ # Create an account
11
+ p provisioning.user_payment_method('54240')
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+ require 'lib/tropo-provisioning'
4
+
5
+ config = YAML.load(File.open('examples/config.yml'))
6
+
7
+ # Create a new provisioning object with your Tropo credentials
8
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], :base_uri => 'http://api-smsified-eng.voxeo.net/v1')
9
+
10
+ # Create an account
11
+ p provisioning.available_payment_types
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+ require 'lib/tropo-provisioning'
4
+ require 'json'
5
+
6
+ config = YAML.load(File.open('examples/config.yml'))
7
+
8
+ # Create a new provisioning object with your Tropo credentials
9
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], :base_uri => 'http://api-smsified-eng.voxeo.net/v1')
10
+
11
+ # Create an account
12
+ #p provisioning.user('54238')
13
+ p provisioning.user('mcervantes')
14
+ #p provisioning.search_users('username=foobar')
15
+
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+ require 'lib/tropo-provisioning'
4
+ require 'json'
5
+
6
+ config = YAML.load(File.open('examples/config.yml'))
7
+
8
+ # Create a new provisioning object with your Tropo credentials
9
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], :base_uri => 'http://api-smsified-eng.voxeo.net/v1')
10
+
11
+ # Create an account
12
+ p provisioning.modify_user('54228', { :marketing_opt_in => false })
13
+
14
+
15
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'lib/tropo-provisioning'
3
+
4
+ config = YAML.load(File.open('examples/config.yml'))
5
+ app_details = YAML.load(File.open("examples/#{config['filename']}"))
6
+
7
+ # Create a new provisioning object with your Tropo credentials
8
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], { :base_uri => 'http://api-smsified-eng.voxeo.net/v1'})
9
+
10
+ p provisioning.update_invitation('ABC456', :count => '200')
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+ require 'lib/tropo-provisioning'
4
+ require 'json'
5
+
6
+ config = YAML.load(File.open('examples/config.yml'))
7
+
8
+ # Create a new provisioning object with your Tropo credentials
9
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], :base_uri => 'http://api.smsified.com/v1')
10
+
11
+ # Create an account
12
+ p provisioning.search_users 'username=jsg'
13
+
14
+ p provisioning.username_exists? 'jsgoecke'
15
+ p provisioning.username_exists? 'fooeyfooy'
@@ -1,2 +1,2 @@
1
- $: << File.expand_path(File.dirname(__FILE__))
2
- %w(net/http net/https uri active_support active_support/json active_support/inflector hashie tropo-provisioning/tropo-provisioning tropo-provisioning/error.rb).each { |lib| require lib }
1
+
2
+ require 'tropo-provisioning/tropo_provisioning'
@@ -0,0 +1,211 @@
1
+ require 'active_support'
2
+ require 'active_support/json'
3
+ require 'hashie'
4
+ require 'net/http'
5
+ require 'net/https'
6
+ require 'uri'
7
+
8
+ # This class is in charge of handling HTTP requests to the Tropo HTTP endpoint
9
+ class TropoClient
10
+
11
+ autoload :TropoError, 'tropo-provisioning/tropo_error'
12
+
13
+ # required HTTP headers
14
+ attr_accessor :headers
15
+ # Tropo provisioning API endpoint
16
+ attr_reader :base_uri
17
+ # Valid Tropo username
18
+ attr_reader :username
19
+ # password associated to :username
20
+ attr_reader :password
21
+
22
+ ##
23
+ # Creates a new TropoClient instance
24
+ #
25
+ # ==== Parameters
26
+ # * [required, String] *username* valid Tropo username
27
+ # * [required, String] *password* valid password
28
+ # * [optional, String] *base_uri* Tropo provisioning API endpoint
29
+ # * [optional, String] *headers* required HTTP headers
30
+ #
31
+ # ==== Return
32
+ # * new TropoClient instance
33
+ def initialize(username, password, base_uri = "http://api.tropo.com/v1", headers)
34
+ @base_uri = base_uri
35
+ @username = username
36
+ @password = password
37
+ @headers = headers.nil? ? {} : headers
38
+ end
39
+
40
+ ##
41
+ # Send a HTTP Get
42
+ #
43
+ # ==== Parameters
44
+ # * [optional, String] path URI
45
+ # * [optional, Hash] Query parameters
46
+ #
47
+ # ==== Return
48
+ # JSON decoded object
49
+ def get(resource = "", params = {})
50
+ uri = "#{base_uri}#{resource}"
51
+ params.empty? or uri = uri.concat('?').concat(params.collect { |k, v| "#{k}=#{v.to_s}" }.join("&"))
52
+ request(Net::HTTP::Get.new(uri))
53
+ end
54
+
55
+ ##
56
+ # Send a HTTP Post
57
+ #
58
+ # ==== Parameters
59
+ # * [optional, String] resource path URI
60
+ # * [optional, Hash] params body to be JSON encoded
61
+ #
62
+ # ==== Return
63
+ # JSON decoded object
64
+ def post(resource = "", params = {})
65
+ uri = "#{base_uri}#{resource}"
66
+ request(Net::HTTP::Post.new(uri), params)
67
+ end
68
+
69
+ ##
70
+ # Send a HTTP Delete
71
+ #
72
+ # ==== Parameters
73
+ # * [optional, String] resource path URI
74
+ # * [optional, Hash] Query parameters
75
+ #
76
+ # ==== Return
77
+ # JSON decoded object
78
+ def delete(resource = "", params = {})
79
+ uri = "#{base_uri}#{resource}"
80
+ params.empty? or uri = uri.concat('?').concat(params.collect { |k, v| "#{k}=#{v.to_s}" }.join("&"))
81
+ request(Net::HTTP::Delete.new(uri))
82
+ end
83
+
84
+ ##
85
+ # Send a HTTP Put
86
+ #
87
+ # ==== Parameters
88
+ # * [optional, String] resource path URI
89
+ # * [optional, Hash] params body to be JSON encoded
90
+ #
91
+ # ==== Return
92
+ # JSON decoded object
93
+ def put(resource = "", params = {})
94
+ uri = "#{base_uri}#{resource}"
95
+ request(Net::HTTP::Put.new(uri), params)
96
+ end
97
+
98
+ ##
99
+ # Format the parameters
100
+ #
101
+ # ==== Parameters
102
+ # * [required, Hash] request parameters
103
+ # ==== Return
104
+ # * camelized params
105
+ def camelize_params(params)
106
+ camelized = {}
107
+ params.each { |k,v| camelized.merge!(k.to_s.camelize(:lower).to_sym => v) }
108
+ camelized
109
+ end
110
+
111
+
112
+ ##
113
+ # Sets the HTTP REST type based on the method being called
114
+ #
115
+ # ==== Parameters
116
+ # * [required, ymbol] the HTTP method to use, may be :delete, :get, :post or :put
117
+ # * [Object] the uri object to create the request for
118
+ # * [Object] the request object to be used to operate on the resource
119
+ #
120
+ # ==== Return
121
+ # * Valid HTTP verb instance
122
+ def set_request_type(method, uri)
123
+ case method
124
+ when :delete
125
+ Net::HTTP::Delete.new(uri)
126
+ when :get
127
+ Net::HTTP::Get.new(uri)
128
+ when :post
129
+ Net::HTTP::Post.new(uri)
130
+ when :put
131
+ Net::HTTP::Put.new(uri)
132
+ end
133
+ end
134
+
135
+ private
136
+
137
+ ##
138
+ # Creates (one once) a HTTP client to the Tropo provisioning endpoint
139
+ #
140
+ # ==== Return
141
+ # * Net::HTTP instance
142
+ def http
143
+ @http ||= (
144
+ uri = URI.parse(base_uri)
145
+ http = Net::HTTP.new(uri.host, uri.port)
146
+ http.use_ssl = true if uri.scheme == 'https'
147
+ http
148
+ )
149
+ end
150
+
151
+ ##
152
+ # Send a request to the Tropo provisioning API
153
+ #
154
+ # ==== Parameters
155
+ # * [required, Symbol] http_request Net::HTTPRequest child
156
+ # * [required, Hash] params used to create the request
157
+ # * [String] :resource the resource to call on the base URL
158
+ # * [Hash] :body the details to use when posting, putting or deleting an object, converts into the appropriate JSON
159
+ #
160
+ # ==== Return
161
+ # * [Hash] the result of the request
162
+ # * [TropoError]
163
+ # if it can not connect to the API server or if the response.code is not 200
164
+ def request(http_request, params = {})
165
+ params[:body] and params[:body] = camelize_params(params[:body])
166
+
167
+ uri = params[:resource].nil? ? "" : params[:resource]
168
+
169
+ unless http_request.is_a?(Net::HTTPRequest)
170
+ raise TropoError.new("Invalid request type #{http_request}")
171
+ end
172
+
173
+ http_request.initialize_http_header(headers)
174
+ http_request.basic_auth username, password
175
+ http_request.body = ActiveSupport::JSON.encode params[:body] if params[:body]
176
+
177
+ begin
178
+ response = http.request(http_request)
179
+ rescue => e
180
+ raise TropoError.new, "Unable to connect to the Provisioning API server - #{e.to_s}"
181
+ end
182
+
183
+ response.code.eql?('200') or raise TropoError.new(response.code), "#{response.code}: #{response.message} - #{response.body}"
184
+
185
+ result = ActiveSupport::JSON.decode response.body
186
+ if result.instance_of? Array
187
+ self.class.hashie_array(result)
188
+ else
189
+ Hashie::Mash.new(result)
190
+ end
191
+ end
192
+
193
+ class << self
194
+ ##
195
+ # Converts the hashes inside the array to Hashie::Mash objects
196
+ #
197
+ # ==== Parameters
198
+ # * [required, Array] array to be Hashied
199
+ #
200
+ # ==== Return
201
+ # * [Array] array that is now Hashied
202
+ def hashie_array(array)
203
+ hashied_array = []
204
+ array.each do |ele|
205
+ hashied_array << Hashie::Mash.new(ele)
206
+ end
207
+ hashied_array
208
+ end
209
+ end
210
+
211
+ end