tropo-provisioning 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+ .document
4
+ .yardoc
5
+
6
+ ## TEXTMATE
7
+ *.tmproj
8
+ tmtags
9
+
10
+ ## EMACS
11
+ *~
12
+ \#*
13
+ .\#*
14
+
15
+ ## VIM
16
+ *.swp
17
+
18
+ ## PROJECT::GENERAL
19
+ coverage
20
+ rdoc
21
+ pkg
22
+ doc
23
+
24
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Voxeo, Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,85 @@
1
+ = Tropo Provisioning API Ruby Library
2
+
3
+ A Ruby library for interaction with the Tropo Provisioning API (http://tropo.com) using JSON.
4
+
5
+ == Tropo Provisioning API Overview
6
+
7
+ The Provisioning API provides a programmatic method to access the Tropo Provisioning Database, which is the centralized server that contains all of your applications, phone numbers, IM network information, tokens and so on. Previously, in order to create/delete applications, add/remove addresses (phone and SMS numbers, IM Accounts and tokens), or view available exchanges (area codes and their associated regions) you would need to log into the Tropo website and make your changes through your web browser. That poses a problem for an external program that needs access to your account and applications.
8
+
9
+ As an example, say you're a phone system provider - someone who creates and hosts an IVR system for doctor's offices, school systems and so on. If you wanted to provide your customers with a method to purchase additional phone numbers via a website or similar portal, you would need to provide your purchasing system with access to our Provisioning Server to create and publish the new phone number. Without the Provisioning API, you would have to manually log into the Tropo website, add the phone number to the application, then provide the customer with the new number directly. With the Provisioning API, you're able to send the request directly to the Provisioning Server through your portal, create the phone number, publish it and provide it back to your customer without any manual interaction whatsoever.
10
+
11
+ == How it works
12
+
13
+ The Provisioning API is a RESTful Web Service that utilizes HTTP and JSON to allow for communication back and forth between an application and the Provisioning Server.
14
+
15
+ == Gem Overview
16
+
17
+ The Tropo Provisioning gem provides a library for convenient access to the Tropo Provisioning API.
18
+
19
+ == Requirements
20
+
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
23
+
24
+ == Installation
25
+
26
+ $ sudo gem install tropo-provisioning
27
+
28
+ == Usage
29
+
30
+ require 'rubygems'
31
+ require 'tropo-provisioning'
32
+
33
+ tp = TropoProvisioning.new('username', 'password')
34
+
35
+ === Examples
36
+
37
+ ==== Add a New Application
38
+
39
+ app_id = tp.add_application({ :name => 'My Shiny New App',
40
+ :voiceUrl => 'http://mydomain.com/voice_script.rb',
41
+ :partition => 'staging',
42
+ :messagingUrl => 'http://mydomain.com/message_script.rb',
43
+ :platform => 'scripting' })
44
+
45
+ ==== Add a Address to an Application
46
+
47
+ address_data = tp.create_address(app_id, { :type => 'did', :prefix => '1415' })
48
+
49
+ ==== Delete a Address to an Application
50
+
51
+ result = tp.delete_address(app_id, address_data['number'])
52
+
53
+ ==== Delete an Application
54
+
55
+ tp.delete_application(app_id)
56
+
57
+ == Documentation
58
+
59
+ ==== API Documentation:
60
+
61
+ http://voxeo.github.com/tropo-webapi-ruby
62
+
63
+ ==== Tropo Provisioning API Documentation
64
+
65
+ TBD
66
+
67
+ === Local & Generating Documentation
68
+
69
+ ==== Developer
70
+
71
+ $ gemserver
72
+
73
+ ==== Project Developer
74
+
75
+ Install the Yard Doc (http://yardoc.org) gem:
76
+
77
+ $ sudo gem install yardoc
78
+
79
+ From within the project:
80
+
81
+ $ yardoc
82
+
83
+ == Copyright
84
+
85
+ Copyright (c) 2010 Voxeo, Corporation. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
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
21
+
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
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "tropo-provisioning #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.19
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+ require 'lib/tropo-provisioning'
4
+
5
+ config = YAML.load(File.open('examples/config.yml'))
6
+ app_details = YAML.load(File.open("examples/#{config['filename']}"))
7
+
8
+ # Create a new provisioning object with your Tropo credentials
9
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], :base_uri => 'https://api.voxeo.com/v1')
10
+
11
+ # Add a address by prefix
12
+ p provisioning.create_address(app_details.application_id, { :type => 'number', :prefix => provisioning.exchanges[0]['prefix'] })
13
+
14
+ # Add a address with a specific numbers
15
+ # p provisioning.add_address(app_details.application_id, { :type => 'number', :number => '13035551212' })
16
+
17
+ # Add an instant messaging address
18
+ p provisioning.create_address(app_details.application_id, { :type => 'jabber', :username => 'xyz123@bot.im' })
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+ require 'yaml'
4
+ require 'lib/tropo-provisioning'
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'])
10
+
11
+ # Then create the application you would like to
12
+ result = provisioning.create_application({ :name => 'Provisioning Test',
13
+ :voiceUrl => 'http://mydomain.com/voice_script.rb',
14
+ :partition => 'staging',
15
+ :messagingUrl => 'http://mydomain.com/message_script.rb',
16
+ :platform => 'scripting' })
17
+
18
+ File.open("examples/#{config['filename']}", 'w') do |f|
19
+ f.write(result.to_yaml)
20
+ end
21
+
22
+ p result
@@ -0,0 +1,22 @@
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
+ r = provisioning.create_user({ :username => 'foobar' + rand(10000).to_s,
12
+ :first_name => 'Count',
13
+ :last_name => 'Dracula',
14
+ :password => 'test124',
15
+ :email => 'jsgoecke@voxeo.com',
16
+ :status => 'active' })
17
+
18
+ p r
19
+
20
+ p provisioning.confirm_user(r['user_id'], r['confirmation_key'], '127.0.0.1')
21
+
22
+ #p provisioning.modify_user('54238', { :first_name => 'Dolly' })
@@ -0,0 +1,11 @@
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 create the application you would like to
11
+ p provisioning.delete_application(app_details.application_id)
@@ -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 addresses
11
+ provisioning.addresses(app_details.application_id).each do |address|
12
+ p address
13
+ puts '*'*10
14
+ end
15
+
16
+ # Then, lets fetch a single address where the first param is the application ID and the second the associated address ID
17
+ p provisioning.address(app_details.application_id, '883510001812716')
18
+ p provisioning.address(app_details.application_id, 'xyz123')
@@ -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.net/v1')
9
+
10
+ p provisioning.applications
11
+
12
+ # Then you may iterate through all of your configured applications
13
+ provisioning.applications.each do |app|
14
+ p app
15
+ puts '*'*10
16
+ end
17
+
18
+ # Now list a single application
19
+ p provisioning.application(app_details.application_id)
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'lib/tropo-provisioning'
3
+
4
+ config = YAML.load(File.open('examples/config.yml'))
5
+
6
+ # Create a new provisioning object with your Tropo credentials
7
+ provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'])
8
+
9
+ # Then you may iterate through all of the available exchanges
10
+ provisioning.exchanges.each do |exchange|
11
+ p exchange
12
+ puts '*'*10
13
+ end
File without changes
@@ -0,0 +1,17 @@
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
+ # First, get the application in question
11
+ application = provisioning.application(app_details.application_id)
12
+
13
+ # Set the name we want to change to
14
+ application['name'] = 'My Awesome App'
15
+
16
+ # Then create the application you would like to
17
+ p provisioning.update_application(app_details.application_id, application)
@@ -0,0 +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 }
@@ -0,0 +1,7 @@
1
+ class ProvisioningApiRuntimeError < RuntimeError
2
+ attr_reader :http_status
3
+
4
+ def initialize(http_status)
5
+ @http_status = http_status
6
+ end
7
+ end
@@ -0,0 +1,864 @@
1
+ class TropoProvisioning
2
+
3
+ # Defaults for the creation of applications
4
+ DEFAULT_OPTIONS = { :partition => 'staging', :platform => 'scripting' }
5
+
6
+ attr_reader :user_data
7
+
8
+ ##
9
+ # Creates a new TropoProvisioning object
10
+ #
11
+ # @param [required, String] username for your Tropo user
12
+ # @param [required, String] password for your Tropo user
13
+ # @param [optional, Hash] params
14
+ # @option params [optional, String] :base_uri to use for accessing the provisioning API if you would like a custom one
15
+ # @return [Object] a TropoProvisioning object
16
+ def initialize(username, password, params={})
17
+ @username = username
18
+ @password = password
19
+ @base_uri = params[:base_uri] || "http://api.tropo.com/v1"
20
+ @headers = { 'Content-Type' => 'application/json' }
21
+ user(username)
22
+ end
23
+
24
+ def account(username, password)
25
+ case current_method_name
26
+ when 'account'
27
+ action = 'get'
28
+ when 'authenticate_account'
29
+ action = 'authenticate'
30
+ end
31
+ temp_request(:get, "/#{action}.jsp?username=#{username}&password=#{password}")
32
+ end
33
+ alias :authenticate_account :account
34
+
35
+ ##
36
+ # Obtain information about a user
37
+ #
38
+ # @param [required, String] the user ID or username to obtain the account details of
39
+ # @return [Hash]
40
+ # contains the information on the user
41
+ def user(user_identifier)
42
+ result = request(:get, { :resource => 'users/' + user_identifier })
43
+ if result['username']
44
+ # Only add/update this if we are fetching the user we are logged in as
45
+ @user_data = result if result['username'].downcase == @username.downcase
46
+ end
47
+ result
48
+ end
49
+
50
+ ##
51
+ # Confirms a user after they have been created. For example, you may want to email your user to make
52
+ # sure they are real before activating the user.
53
+ #
54
+ # @param [required, String] user_id returned when you created the user you now want to confirm
55
+ # @param [required, String] confirmation_key returned when you created the user you now want to confirm
56
+ # @param [required, String] the ip_address of the user client that did the confirmation
57
+ # @return [Hash]
58
+ # contains a message key confirming the confirmation was successful
59
+ def confirm_user(user_id, confirmation_key, ip_address)
60
+ params = { :key => confirmation_key, :endUserHost => ip_address }
61
+ request(:post, { :resource => 'users/' + user_id + '/confirmations', :body => params })
62
+ end
63
+
64
+ ##
65
+ # Creates a new user in a pending state. Once you receive the href/user_id/confirmation_key
66
+ # you may then invoke the confirm_user method once you have taken appropriate steps to confirm the
67
+ # user
68
+ #
69
+ # @param [required, Hash] params to create the user
70
+ # @option params [required, String] :username the name of the user to create the user for
71
+ # @option params [required, String] :password the password to use for the user
72
+ # @option params [required, String] :email the email address to use
73
+ # @option params [optional, String] :first_name of the user
74
+ # @option params [optional, String] :last_name of the user
75
+ # @option params [optional, String] :website the URL of the user's website
76
+ # @option params [optional, String] :organization of the user, such as a company name
77
+ # @option params [optional, String] :job_title of the user
78
+ # @option params [optional, String] :address of the user
79
+ # @option params [optional, String] :address2 second live of the address of the user
80
+ # @option params [optional, String] :city of the user
81
+ # @option params [optional, String] :state of the user
82
+ # @option params [optional, String] :postal_code of the user
83
+ # @option params [optional, String] :country of the user
84
+ # @option params [optional, String] :marketing_opt_in
85
+ # @option params [optional, String] :twitter_id
86
+ # @option params [optional, String] :joined_from_host IP address of the host they signed up from
87
+ # @return [Hash] details of the user created
88
+ # includes the href, user_id and confirmation_key
89
+ # @raise [ArgumentError]
90
+ # if missing the :username, :password or :email parameters
91
+ def create_user(params={})
92
+ validate_params(params, %w(username password email))
93
+
94
+ # Set the Company Branding ID, or use default
95
+ params[:website] = 'tropo' unless params[:website]
96
+
97
+ result = request(:post, { :resource => 'users', :body => params })
98
+ result[:user_id] = get_element(result.href)
99
+ result[:confirmation_key] = result['confirmationKey']
100
+ result.delete('confirmationKey')
101
+ result
102
+ end
103
+
104
+ ##
105
+ # Modify/update an existing user
106
+ #
107
+ # @param [required, String] user_id of the user you would like to update
108
+ # @param [required, Hash] the parameters of the user you would like to update
109
+ # @return [Hash]
110
+ # the href of the resource that was modified/updated
111
+ def modify_user(user_id, params={})
112
+ result = request(:put, { :resource => 'users/' + user_id, :body => params })
113
+ if result['href']
114
+ # Only add/update this if we are fetching the user we are logged in as
115
+ @user_data.merge!(params) if user_id == @user_data['id']
116
+ end
117
+ result
118
+ end
119
+
120
+ ##
121
+ # Allows you to search users to find a list of users
122
+ #
123
+ # @param [required, String] a key/value of the search term you would like to use, such as 'username=foobar', or 'city=Orlando'
124
+ # @return [Array]
125
+ # a hash containing an array of hashes with the qualifying account details
126
+ def search_users(search_term)
127
+ request(:get, { :resource => 'users/?' + search_term })
128
+ end
129
+
130
+ ##
131
+ # Allows you to search if a username exists or not
132
+ #
133
+ # @param [required, String] a username to check
134
+ # @return [Array]
135
+ # a hash containing an array of hashes with the qualifying account details
136
+ def username_exists?(username)
137
+ request(:get, { :resource => 'usernames/' + username })
138
+ end
139
+
140
+ ##
141
+ # Fetches the payment information for a user
142
+ #
143
+ # @param [required, String] user_id to fetch the payment details for
144
+ # @return [Hash]
145
+ # a hash containing the accountNumber, paymentType, paymentTypeName, rechargeAmount and rechargeThreshold
146
+ def user_payment_method(user_id)
147
+ result = request(:get, { :resource => 'users/' + user_id + '/payment/method'})
148
+ result.merge!({ :id => get_element(result.paymentType) })
149
+ result
150
+ end
151
+
152
+ ##
153
+ # Lists the available payment types
154
+ #
155
+ # @return [Hash]
156
+ # an array of available payment types that each include an id, href and name
157
+ def available_payment_types
158
+ request(:get, { :resource => 'types/payment' })
159
+ end
160
+
161
+ ##
162
+ # Obtain the current balance of a user
163
+ #
164
+ # @param [required, String] user_id of the user to obtain the balance for
165
+ # @return [Hash]
166
+ # the balance, pendingRechargeAmount and pendingUsageAmount for the user account
167
+ def balance(user_id)
168
+ request(:get, { :resource => 'users/' + user_id + '/usage'})
169
+ end
170
+
171
+ ##
172
+ # Return the list of available countries
173
+ #
174
+ # @return [Hash]
175
+ # returns an Array of hashes that include the country details available
176
+ def countries
177
+ result = request(:get, { :resource => 'countries' })
178
+ add_ids(result)
179
+ end
180
+
181
+ ##
182
+ # Return the list of available states for a country
183
+ #
184
+ # @return [Hash]
185
+ # returns an Array of hashes that include the state details for a country that are available
186
+ def states(id)
187
+ result = request(:get, { :resource => 'countries' + "/#{id}/" + 'states' })
188
+ add_ids(result)
189
+ end
190
+
191
+ ##
192
+ # Lists the available features
193
+ #
194
+ # @return [Hash]
195
+ # an array of available features that each include an id, href, name and description
196
+ def features
197
+ request(:get, { :resource => 'features' })
198
+ end
199
+
200
+ ##
201
+ # Lists the features configured for a user
202
+ #
203
+ # @return [Hash]
204
+ # an array of available features that each include an href, feature and featureName
205
+ def user_features(user_id)
206
+ request(:get, { :resource => 'users/' + user_id + '/features' })
207
+ end
208
+
209
+ ##
210
+ # Enable a particular feature for a user
211
+ #
212
+ # @param [required, String] user_id of the user to add the feature to
213
+ # @param [required, String] feature identifier of the feature you want to add
214
+ # @return [Hash]
215
+ # the href of the feature added
216
+ def user_enable_feature(user_id, feature)
217
+ request(:post, { :resource => 'users/' + user_id + '/features', :body => { :feature => feature } })
218
+ end
219
+
220
+ ##
221
+ # Disable a particular feature for a user
222
+ #
223
+ # @param [required, String] user_id of the user to disable the feature to
224
+ # @param [required, String] feature number of the feature you want to disable
225
+ # @return [Hash]
226
+ # the href of the feature disable
227
+ def user_disable_feature(user_id, feature_number)
228
+ request(:delete, { :resource => 'users/' + user_id + '/features/' + feature_number })
229
+ end
230
+
231
+ ##
232
+ # Add/modify payment info for a user
233
+ #
234
+ # @param [required, String] user_id to add the payment details for
235
+ # @param [require, Hash] params the params to add the payment info
236
+ # @option params [required, String] :account_number the credit card number
237
+ # @option params [required, String] :payment_type the type, such as visa, mastercard, etc
238
+ # @option params [required, String] :address
239
+ # @option params [optional, String] :address2
240
+ # @option params [required, String] :city
241
+ # @option params [required, String] :state
242
+ # @option params [required, String] :postal_code
243
+ # @option params [required, String] :country
244
+ # @option params [optional, String] :email
245
+ # @option params [required, String] :name_on_account name on the credit card
246
+ # @option params [required, String] :expiration_date expiration date of the credit card
247
+ # @option params [required, String] :security_code back panel/front panel (Amex) code on the card
248
+ # @option params [optional, String] :phone_number
249
+ # @return [Hash]
250
+ # the href of the payment method added
251
+ # @raise [ArgumentError]
252
+ # if a required param is not present
253
+ def add_payment_info(user_id, params={})
254
+ #validate_params(params, %w(account_number payment_type address city state postal_code country name_on_account expiration_date security_code recharge_amount email phone_number))
255
+
256
+ result = request(:put, { :resource => 'users/' + user_id + '/payment/method', :body => params })
257
+ result
258
+ end
259
+ alias :modify_payment_info :add_payment_info
260
+
261
+ ##
262
+ # Add/modify recurring fund amount and threshold
263
+ #
264
+ # @param [required, String] user_id to add the payment details for
265
+ # @param [require, Hash] params the params to add the recurrence
266
+ # @option params [required, Float] :recharge_amount
267
+ # @option params [required, Float] :recharge_threshold
268
+ #
269
+ # @return [Hash]
270
+ def update_recurrence(user_id, params={})
271
+ validate_params(params, %w(recharge_amount threshold_percentage))
272
+
273
+ result = request(:put, { :resource => 'users/' + user_id + '/payment/recurrence', :body => params })
274
+ end
275
+
276
+ ##
277
+ # Add/modify recurring fund amount and threshold
278
+ #
279
+ # @param [required, String] user_id to get the recurrence info for
280
+ #
281
+ # @return [Hash]
282
+ def get_recurrence(user_id)
283
+ result = request(:get, { :resource => 'users/' + user_id + '/payment/recurrence' })
284
+ end
285
+
286
+ ##
287
+ # Makes a payment on behalf of a user
288
+ #
289
+ # @param [required, String] the user_id to make the payment for
290
+ # @param [required, Float] the amount, in US Dollars to make the payment for
291
+ # @return [Hash]
292
+ # a message with the success or failure of the payment
293
+ def make_payment(user_id, amount)
294
+ raise ArgumentError, 'amount must be of type Float' if amount.instance_of?(Float) == false
295
+
296
+ request(:post, { :resource => 'users/' + user_id + '/payments', :body => { :amount => amount } })
297
+ end
298
+
299
+ ##
300
+ # Creates an address to an existing application
301
+ #
302
+ # @param [required, String] application_id to add the address to
303
+ # @param [required, Hash] params the parameters used to request the address
304
+ # @option params [String] :type this defines the type of address. The possibles types are number (phone numbers), pin (reserved), token, aim, jabber, msn, yahoo, gtalk & skype
305
+ # @option params [String] :prefix this defines the country code and area code for phone numbers
306
+ # @option params [String] :username the messaging/IM account's username
307
+ # @option params [String] :password the messaging/IM account's password
308
+ # @return [Hash] params the key/values that make up the application
309
+ # @option params [String] :href identifies the address that was added, refer to address method for details
310
+ # @option params [String] :address the address that was created
311
+ def create_address(application_id, params={})
312
+ validate_address_parameters(params)
313
+
314
+ result = request(:post, { :resource => 'applications/' + application_id.to_s + '/addresses', :body => params })
315
+ result[:address] = get_element(result.href)
316
+ result
317
+ end
318
+
319
+ ##
320
+ # Get a specific application
321
+ #
322
+ # @param [required, String] application_id of the application to get
323
+ # @return [Hash] params the key/values that make up the application
324
+ # @option params [String] :href the REST address for the application
325
+ # @option params [String] :name the name of the application
326
+ # @option params [String] :voiceUrl the URL that powers voice calls for your application
327
+ # @option params [String] :messagingUrl the URL that powers the SMS/messaging calls for your session
328
+ # @option params [String] :platform defines whether the application will use the Scripting API or the Web API
329
+ # @option params [String] :partition defines whether the application is in staging/development or production
330
+ def application(application_id)
331
+ app = request(:get, { :resource => 'applications/' + application_id.to_s })
332
+ app.merge!({ :application_id => get_element(app.href) })
333
+ end
334
+
335
+ ##
336
+ # Fetches all of the applications configured for a user
337
+ #
338
+ # @return [Hash] contains the results of the inquiry with a list of applications for the authenticated user, refer to the application method for details
339
+ def applications
340
+ results = request(:get, { :resource => 'applications' })
341
+ result_with_ids = []
342
+ results.each do |app|
343
+ result_with_ids << app.merge!({ :application_id => get_element(app.href) })
344
+ end
345
+ result_with_ids
346
+ end
347
+
348
+ ##
349
+ # Fetches the application(s) with the associated addresses in the hash
350
+ #
351
+ # @param [optional, String] application_id will return a single application with addresses if present
352
+ # @return [Hash] contains the results of the inquiry with a list of applications for the authenticated user, refer to the application method for details
353
+ def applications_with_addresses(application_id=nil)
354
+ if application_id
355
+ associate_addresses_to_application(application(application_id))
356
+ else
357
+ apps = []
358
+ applications.each do |app|
359
+ apps << associate_addresses_to_application(app)
360
+ end
361
+ apps
362
+ end
363
+ end
364
+ alias :application_with_address :applications_with_addresses
365
+
366
+ ##
367
+ # Create a new application
368
+ #
369
+ # @param [required, Hash] params to create the application
370
+ # @option params [required, String] :name the name to assign to the application
371
+ # @option params [required, String] :partition this defines whether the application is in staging/development or production
372
+ # @option params [required, String] :platform (scripting) whether to use scripting or the webapi
373
+ # @option params [required, String] :messagingUrl or :messaging_url The URL that powers the SMS/messages sessions for your application
374
+ # @option params [optional, String] :voiceUrl or :voice_url the URL that powers voices calls for your application
375
+ # @return [Hash] returns the href of the application created and the application_id of the application created
376
+ def create_application(params={})
377
+ merged_params = DEFAULT_OPTIONS.merge(camelize_params(params))
378
+ validate_application_params(merged_params)
379
+ result = request(:post, { :resource => 'applications', :body => params })
380
+ result[:application_id] = get_element(result.href)
381
+ result
382
+ end
383
+
384
+ ##
385
+ # Deletes an application
386
+ #
387
+ # @param [required, String] application_id to be deleted
388
+ # @return [Hash] not sure since it does 204 now, need to check with Cervantes, et al
389
+ def delete_application(application_id)
390
+ request(:delete, { :resource => 'applications/' + application_id.to_s })
391
+ end
392
+
393
+ ##
394
+ # Deletes a address from a specific application
395
+ #
396
+ # @param [String] application_id that the address is associated to
397
+ # @param [String] address_id for the address
398
+ # @return
399
+ def delete_address(application_id, address_id)
400
+ address_to_delete = address(application_id, address_id)
401
+
402
+ request(:delete, { :resource => 'applications/' + application_id.to_s + '/addresses/' + address_to_delete['type'] + '/' + address_id.to_s })
403
+ end
404
+
405
+ ##
406
+ # Provides a list of available exchanges to obtain Numbers from
407
+ #
408
+ # @return [Array] the list of available exchanges
409
+ def exchanges
410
+ request(:get, { :resource => 'exchanges' })
411
+ end
412
+
413
+ ##
414
+ # Used to move a address between one application and another
415
+ #
416
+ # @param [Hash] params contains a hash of the applications and address to move
417
+ # @option params [required, String] :from
418
+ # @option params [required, String] :to
419
+ # @option params [required, String] :address
420
+ def move_address(params={})
421
+ validate_params(params, %w(from to address))
422
+
423
+ begin
424
+ address_to_move = address(params[:from], params[:address])
425
+ delete_address(params[:from], params[:address])
426
+ request(:post, { :resource => 'applications/' + params[:to] + '/addresses/' + address_to_move['type'] + '/' + params[:address]})
427
+ rescue
428
+ raise RuntimeError, 'Unable to move the address'
429
+ end
430
+ end
431
+
432
+ ##
433
+ # Get a specific address for an application
434
+ #
435
+ # @param [required, String] application_id to obtain the address for
436
+ # @param [required, String] address_id of the address to obtain the details for
437
+ # @return [Hash] the details of the address
438
+ # @option params [String] :href the REST address for the application
439
+ # @option params [String] :name the name of the application
440
+ # @option params [String] :voiceUrl the URL that powers voices calls for your application
441
+ # @option params [String] :messagingUrl The URL that powers the SMS/messages sessions for your application
442
+ # @option params [String] :partition this defines whether the application is in staging/development or production
443
+ # @option params [String] :type this defines the type of address. The possibles types are number (phone numbers), pin (reserved), token, aim, jabber, msn, yahoo, gtalk & skype
444
+ # @option params [String] :prefix this defines the country code and area code for phone numbers
445
+ # @option params [String] :number the phone number assigned to the application
446
+ # @option params [String] :city the city associated with the assigned phone number
447
+ # @option params [String] :state the state associated with the assigned phone number
448
+ # @option params [String] :channel idenifites the type of channel, maybe 'voice' or 'messaging'
449
+ # @option params [String] :username the messaging/IM account's username
450
+ # @option params [String] :password the messaging/IM account's password
451
+ # @option params [String] :token alphanumeric string that identifies your Tropo application, used with the Session API
452
+ def address(application_id, address_id)
453
+ addresses(application_id).each { |address| return address if address['number'] == address_id ||
454
+ address['username'] == address_id ||
455
+ address['pin'] == address_id ||
456
+ address['token'] == address_id }
457
+ raise RuntimeError, 'Address not found with that application.'
458
+ end
459
+
460
+ ##
461
+ # Get all of the configured addresses for an application
462
+ #
463
+ # @param [required, String] application_id to fetch the addresses for
464
+ # @return [Hash] all of the addresses configured for the application
465
+ def addresses(application_id)
466
+ request(:get, { :resource => 'applications/' + application_id.to_s + '/addresses' })
467
+ end
468
+
469
+ ##
470
+ # Updated an existing application
471
+ #
472
+ # @param [required, String] the application id to update
473
+ # @param [required, Hash] params the parameters used to create the application
474
+ # @option params [optional, String] :name the name of the application
475
+ # @option params [optional, String] :voiceUrl the URL that powers voices calls for your application
476
+ # @option params [optional, String] :messagingUrl The URL that powers the SMS/messages sessions for your application
477
+ # @option params [optional, String] :partition whether to create in staging or production
478
+ # @option params [optional, String] :platform whehter to use scripting or the webapi
479
+ # @return [Hash] returns the href of the application created
480
+ def update_application(application_id, params={})
481
+ request(:put, { :resource => 'applications/' + application_id.to_s, :body => params })
482
+ end
483
+
484
+ ##
485
+ # Fetch all invitations, or invitations by user
486
+ #
487
+ # @overload def invitations()
488
+ # @overload def user_inivitations(user_id)
489
+ # @param [optional, String] the user_id to fetch the invitations for, if not present, will fetch all invitations
490
+ # @return [Hash] returns a list of the invitations
491
+ def invitations(user_id=nil)
492
+ if user_id
493
+ request(:get, { :resource => 'users' + "/#{user_id}" + '/invitations'})
494
+ else
495
+ request(:get, { :resource => 'invitations' })
496
+ end
497
+ end
498
+ alias :user_invitations :invitations
499
+
500
+ ##
501
+ # Fetch an invitation
502
+ #
503
+ # @overload def invitation(invitation_id)
504
+ # @param [required, String] the invitation id to fetch
505
+ # @overload def user_invitation(user_id, invitation_id)
506
+ # @param [required, String] the invitation id to fetch
507
+ # @param [optional, String] the user id to fetch the invitation for
508
+ # @return [Hash] return an invitation
509
+ def invitation(*args)
510
+ if args.length == 1
511
+ request(:get, { :resource => 'invitations' + "/#{args[0]}" })
512
+ elsif args.length == 2
513
+ request(:get, { :resource => 'users' + "/#{args[1]}" + '/invitations' + "/#{args[0]}" })
514
+ else
515
+ raise ArgumentError, 'Only accepts two arguments, invitation_id and user_id'
516
+ end
517
+ end
518
+ alias :user_invitation :invitation
519
+
520
+ ##
521
+ # Fetch an invitation
522
+ #
523
+ # @overload def delete_invitation(invitation_id)
524
+ # @param [required, String] the invitation id to delete
525
+ # @overload def delete_user_invitation(invitation_id, user_id)
526
+ # @param [required, String] the invitation id to delete
527
+ # @param [required, String] the user id to delete
528
+ # @return [Hash] return an invitation
529
+ def delete_invitation(*args)
530
+ if args.length == 1
531
+ request(:delete, { :resource => 'invitations' + "/#{args[0]}" })
532
+ elsif args.length == 2
533
+ request(:delete, { :resource => 'users' + "/#{args[1]}" + '/invitations' + "/#{args[0]}" })
534
+ end
535
+ end
536
+ alias :delete_user_invitation :delete_invitation
537
+
538
+ ##
539
+ # Create an invitation
540
+ #
541
+ # @overload def create_invitation(options)
542
+ # @param [required, Hash] params the parameters used to create the application
543
+ # @option params [optional, String] :code the invitation code (defaults to a random alphanum string of length 6 if not specified on POST)
544
+ # @option params [optional, String] :count the number of accounts that may signup with this code (decrements on each signup)
545
+ # @option params [optional, String] :credit starting account balance for users who signup with this code (replaces the default for the brand)
546
+ # @option params [optional, String] :partition whether to create in staging or production
547
+ # @option params [optional, String] :owner URI identifying the user to which this invite code belongs (optional - null implies this is a "global" code)
548
+ # @overload def create_user_invitation(user_id, options)
549
+ # @param [requried, String] user_id to create the invitation for
550
+ # @param [required, Hash] params the parameters used to create the application
551
+ # @option params [optional, String] :code the invitation code (defaults to a random alphanum string of length 6 if not specified on POST)
552
+ # @option params [optional, String] :count the number of accounts that may signup with this code (decrements on each signup)
553
+ # @option params [optional, String] :credit starting account balance for users who signup with this code (replaces the default for the brand)
554
+ # @option params [optional, String] :partition whether to create in staging or production
555
+ # @option params [optional, String] :owner URI identifying the user to which this invite code belongs (optional - null implies this is a "global" code)
556
+ # @return [Hash] returns the href of the invitation created
557
+ def create_invitation(*args)
558
+ if args.length == 1
559
+ request(:post, { :resource => 'invitations', :body => args[0] })
560
+ elsif args.length == 2
561
+ request(:post, { :resource => 'users' + "/#{args[0]}" + '/invitations', :body => args[1] })
562
+ end
563
+ end
564
+ alias :create_user_invitation :create_invitation
565
+
566
+ ##
567
+ # Update an invitation
568
+ #
569
+ # @overload def update_invitation(invitation_id, options)
570
+ # @param [required, String] id of the invitation to udpate (code)
571
+ # @param [required, Hash] params the parameters used to update the application
572
+ # @option params [optional, String] :count the number of accounts that may signup with this code (decrements on each signup)
573
+ # @option params [optional, String] :credit starting account balance for users who signup with this code (replaces the default for the brand)
574
+ # @option params [optional, String] :partition whether to create in staging or production
575
+ # @option params [optional, String] :owner URI identifying the user to which this invite code belongs (optional - null implies this is a "global" code)
576
+ # @overload def updated_user_invitation(invitation_id, user_id, options)
577
+ # @param [required, String] id of the invitation to udpate (code)
578
+ # @param [required, String] id of the user to update the invitation code for
579
+ # @param [required, Hash] params the parameters used to update the application
580
+ # @option params [optional, String] :count the number of accounts that may signup with this code (decrements on each signup)
581
+ # @option params [optional, String] :credit starting account balance for users who signup with this code (replaces the default for the brand)
582
+ # @option params [optional, String] :partition whether to create in staging or production
583
+ # @option params [optional, String] :owner URI identifying the user to which this invite code belongs (optional - null implies this is a "global" code)
584
+ # @return [Hash] returns the href of the invitation created
585
+ def update_invitation(*args)
586
+ if args.length == 2
587
+ request(:put, { :resource => 'invitations' + "/#{args[0]}", :body => args[1] })
588
+ elsif args.length == 3
589
+ request(:put, { :resource => 'users' + "/#{args[1]}" + '/invitations' + "/#{args[0]}", :body => args[2] })
590
+ end
591
+ end
592
+ alias :update_user_invitation :update_invitation
593
+
594
+ ##
595
+ # Get the available partitions available
596
+ #
597
+ # @return [Array]
598
+ # an array of hashes containing the partitions available
599
+ def partitions
600
+ request(:get, { :resource => 'partitions' })
601
+ end
602
+
603
+ ##
604
+ # Get the available platforms available under a certain partition
605
+ #
606
+ # @return [Array]
607
+ # an array of hashes containing the platforms available
608
+ def platforms(partition)
609
+ request(:get, { :resource => 'partitions/' + partition + '/platforms' })
610
+ end
611
+
612
+ ##
613
+ # Get the whitelist of the numbers on a particular users list
614
+ #
615
+ # @param [required, String] user_id of the user you would like to update
616
+ # @return [Hash]
617
+ # the href and value containing the number on the whitelist
618
+ def whitelist(user_id=nil)
619
+ if user_id
620
+ resource = 'users/' + user_id + '/partitions/production/platforms/sms/whitelist'
621
+ else
622
+ resource = 'users/partitions/production/platforms/sms/whitelist'
623
+ end
624
+
625
+ request(:get, { :resource => resource })
626
+ end
627
+
628
+ ##
629
+ # Add to a whitelist for a particular user
630
+ #
631
+ # @param [Hash] params contains a hash of the user_id and value to add
632
+ # @option params [optional, String] :user_id if present the user_id to add to, if not it will add to the user logged in as
633
+ # @option params [required, String] :value the value to add to the whitelist
634
+ # @return [Hash]
635
+ # the href
636
+ def add_whitelist(params={})
637
+ if params[:user_id]
638
+ resource = 'users/' + params[:user_id] + '/partitions/production/platforms/sms/whitelist'
639
+ else
640
+ resource = 'users/partitions/production/platforms/sms/whitelist'
641
+ end
642
+
643
+ request(:post, { :resource => resource, :body => { :value => params[:value] } })
644
+ end
645
+
646
+ ##
647
+ # Delete from a whitelist for a particular user
648
+ #
649
+ # @param [Hash] params contains a hash of the user_id and value to delete
650
+ # @option params [optional, String] :user_id if present the user_id to delete from, if not it will add to the user logged in as
651
+ # @option params [required, String] :value the value to delete from the whitelist
652
+ # @return [Hash]
653
+ # the href
654
+ def delete_whitelist(params={})
655
+ if params[:user_id]
656
+ resource = 'users/' + params[:user_id] + '/partitions/production/platforms/sms/whitelist/'
657
+ else
658
+ resource = 'users/partitions/production/platforms/sms/whitelist/'
659
+ end
660
+
661
+ request(:delete, { :resource => resource + params[:value] })
662
+ end
663
+
664
+ private
665
+
666
+ ##
667
+ #
668
+ def camelize_params(params)
669
+ camelized = {}
670
+ params.each { |k,v| camelized.merge!(k.to_s.camelize(:lower).to_sym => v) }
671
+ camelized
672
+ end
673
+
674
+ ##
675
+ # Returns the current method name
676
+ #
677
+ # @return [String] current method name
678
+ def current_method_name
679
+ caller[0] =~ /`([^']*)'/ and $1
680
+ end
681
+
682
+ ##
683
+ # Converts the hashes inside the array to Hashie::Mash objects
684
+ #
685
+ # @param [required, Array] array to be Hashied
686
+ # @param [Array] array that is now Hashied
687
+ def hashie_array(array)
688
+ hashied_array = []
689
+ array.each do |ele|
690
+ hashied_array << Hashie::Mash.new(ele)
691
+ end
692
+ hashied_array
693
+ end
694
+
695
+ ##
696
+ # Adds the IDs to an Array of Hashes if no ID is present
697
+ #
698
+ # @param [required, Array] array of hashes to add IDs to
699
+ #
700
+ # @return [Array]
701
+ # the array of hashes with ID added
702
+ def add_ids(array)
703
+ array.each do |element|
704
+ element[:id] = get_element(element.href) if element[:id].nil?
705
+ end
706
+ array
707
+ end
708
+
709
+ ##
710
+ # Parses the URL and returns the last element
711
+ #
712
+ # @param [required, String] the URL to parse for the application ID
713
+ # @return [String] the application id parsed from the URL
714
+ def get_element(url)
715
+ url.split('/').last
716
+ end
717
+
718
+ ##
719
+ # Associates the addresses to an application
720
+ #
721
+ # @param [Object] application object to associate the address to
722
+ # @return [Object] returns the application object with the associated addresses embedded
723
+ def associate_addresses_to_application(app)
724
+ add = addresses(app.application_id)
725
+ app.merge!({ :addresses => add })
726
+ end
727
+
728
+ ##
729
+ # Creates the appropriate URI and HTTP handlers for our request
730
+ #
731
+ # @param [required, Symbol] the HTTP action to use :delete, :get, :post or :put
732
+ # @param [required, Hash] params used to create the request
733
+ # @option params [String] :resource the resource to call on the base URL
734
+ # @option params [Hash] :body the details to use when posting, putting or deleting an object, converts into the appropriate JSON
735
+ # @return [Hash] the result of the request
736
+ # @raise [RuntimeError]
737
+ # if it can not connect to the API server or if the response.code is not 200
738
+ def request(method, params={})
739
+ params[:body] = camelize_params(params[:body]) if params[:body]
740
+
741
+ if params[:resource]
742
+ uri = URI.parse(@base_uri + '/' + params[:resource])
743
+ else
744
+ uri = URI.parse(@base_uri)
745
+ end
746
+ http = Net::HTTP.new(uri.host, uri.port)
747
+ http.use_ssl = true if uri.scheme == 'https'
748
+
749
+ request = set_request_type(method, uri)
750
+ request.initialize_http_header(@headers)
751
+ request.basic_auth @username, @password
752
+ request.body = ActiveSupport::JSON.encode params[:body] if params[:body]
753
+
754
+ begin
755
+ response = http.request(request)
756
+ rescue => e
757
+ raise RuntimeError, "Unable to connect to the Provisioning API server - #{e.to_s}"
758
+ end
759
+
760
+ raise ProvisioningApiRuntimeError.new(response.code), "#{response.code}: #{response.message} - #{response.body}" unless response.code == '200'
761
+
762
+ result = ActiveSupport::JSON.decode response.body
763
+ if result.instance_of? Array
764
+ hashie_array(result)
765
+ else
766
+ Hashie::Mash.new(result)
767
+ end
768
+ end
769
+
770
+ ##
771
+ # Creates the appropriate request for the temporary Evolution account API
772
+ #
773
+ # @return [Hash] the result of the request
774
+ def temp_request(method, fields)
775
+ #base_uri = 'http://evolution.voxeo.com/api/account'
776
+ base_uri = 'http://web141.supernonstop.com/api/account'
777
+ uri = URI.parse(base_uri + fields)
778
+ http = Net::HTTP.new(uri.host, uri.port)
779
+
780
+ request = set_request_type(method, uri)
781
+ request.initialize_http_header(@headers)
782
+
783
+ response = http.request(request)
784
+ raise RuntimeError, "#{response.code} - #{response.message}" unless response.code == '200'
785
+
786
+ result = ActiveSupport::JSON.decode response.body
787
+ if result.instance_of? Array
788
+ hashie_array(result)
789
+ else
790
+ Hashie::Mash.new(result)
791
+ end
792
+ end
793
+
794
+ ##
795
+ # Sets the HTTP REST type based on the method being called
796
+ #
797
+ # @param [required, ymbol] the HTTP method to use, may be :delete, :get, :post or :put
798
+ # @param [Object] the uri object to create the request for
799
+ # @return [Object] the request object to be used to operate on the resource
800
+ def set_request_type(method, uri)
801
+ case method
802
+ when :delete
803
+ Net::HTTP::Delete.new(uri.request_uri)
804
+ when :get
805
+ Net::HTTP::Get.new(uri.request_uri)
806
+ when :post
807
+ Net::HTTP::Post.new(uri.request_uri)
808
+ when :put
809
+ Net::HTTP::Put.new(uri.request_uri)
810
+ end
811
+ end
812
+
813
+ ##
814
+ # Used to validate required params in either underscore or camelCase formats
815
+ #
816
+ # @param [required, Hash] params to be checked
817
+ # @param [required, Array] requirements of which fields much be present
818
+ # @raise ArgumentError
819
+ # if a param is not present that is required
820
+ def validate_params(params, requirements)
821
+ requirements.each do |requirement|
822
+ if params[requirement.to_sym].nil? && params[requirement.to_s.camelize(:lower).to_sym].nil? && params[requirement].nil? && params[requirement.to_s.camelize(:lower)].nil?
823
+ raise ArgumentError, ":#{requirement} is a required parameter"
824
+ break
825
+ end
826
+ end
827
+ end
828
+
829
+ ##
830
+ # Validates that we have all of the appropriate params when creating an application
831
+ #
832
+ # @param [Hash] params to create the application
833
+ # @option params [required, String] :name the name to assign to the application
834
+ # @option params [required, String] :partition whether to create in staging or production
835
+ # @option params [required, String] :platform whehter to use scripting or the webapi
836
+ # @option params [String] :messagingUrl the Url to use for handiling messaging requests
837
+ # @option params [String] :voiceUrl the Url to use for handling voice requests
838
+ # @return nil
839
+ def validate_application_params(params={})
840
+ # Make sure all of the arguments are present
841
+ raise ArgumentError, ':name is a required parameter' unless params[:name] || params['name']
842
+
843
+ # Make sure the arguments have valid values
844
+ raise ArgumentError, ":platform must be 'scripting' or 'webapi'" unless params[:platform] == 'scripting' || params[:platform] == 'webapi' || params['platform'] == 'scripting' || params['platform'] == 'webapi'
845
+ raise ArgumentError, ":partiion must be 'staging' or 'production'" unless params[:partition] == 'staging' || params[:partition] == 'production' || params['partition'] == 'staging' || params['partition'] == 'production'
846
+ end
847
+
848
+ def validate_address_parameters(params={})
849
+ raise ArgumentError, ":type is a required parameter" unless params[:type] || params['type']
850
+
851
+ case params[:type].downcase
852
+ when 'number'
853
+ raise ArgumentError, ':prefix required to add a number address' unless params[:prefix] || params[:number] || params['prefix'] || params['number']
854
+ when 'aim', 'msn', 'yahoo', 'gtalk'
855
+ raise ArgumentError, ':username is a required parameter' unless params[:username] || params['username']
856
+ raise ArgumentError, ':password is a required parameter' unless params[:password] || params ['password']
857
+ when 'jabber'
858
+ raise ArgumentError, ':username is a required parameter' unless params[:username] || params['username']
859
+ when 'token'
860
+ raise ArgumentError, ':channel is a required parameter' unless params[:channel] || params['channel']
861
+ raise ArgumentError, ':channel must be voice or messaging' unless params[:channel] == 'voice' || params[:channel] == 'messaging' || params['channel'] == 'voice' || params['channel'] == 'messaging'
862
+ end
863
+ end
864
+ end