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 +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +38 -0
- data/README.rdoc +10 -4
- data/Rakefile +20 -35
- data/examples/app_details.yml +3 -0
- data/examples/authenticate_account.rb +12 -0
- data/examples/config.yml +5 -0
- data/examples/create_invitation.rb +12 -0
- data/examples/delete_applications.rb +25 -0
- data/examples/get_balance.rb +11 -0
- data/examples/list_applications_with_addresses.rb +18 -0
- data/examples/list_features.rb +16 -0
- data/examples/list_invitations.rb +19 -0
- data/examples/list_partitions_platforms.rb +15 -0
- data/examples/list_payment_method.rb +11 -0
- data/examples/list_payment_methods.rb +11 -0
- data/examples/list_user.rb +15 -0
- data/examples/modify_user.rb +15 -0
- data/examples/update_invitation.rb +10 -0
- data/examples/users_search.rb +15 -0
- data/lib/tropo-provisioning.rb +2 -2
- data/lib/tropo-provisioning/tropo_client.rb +211 -0
- data/lib/tropo-provisioning/tropo_error.rb +12 -0
- data/lib/tropo-provisioning/tropo_provisioning.rb +930 -0
- data/lib/tropo-provisioning/version.rb +5 -0
- data/spec/live-tropo-provisioning_spec.rb +221 -26
- data/spec/spec_helper.rb +3 -7
- data/spec/tropo-provisioning_spec.rb +176 -162
- data/tropo-provisioning.gemspec +25 -60
- metadata +110 -33
- data/VERSION +0 -1
- data/lib/tropo-provisioning/error.rb +0 -7
- data/lib/tropo-provisioning/tropo-provisioning.rb +0 -864
data/tropo-provisioning.gemspec
CHANGED
@@ -1,70 +1,35 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
4
|
+
|
5
|
+
require 'tropo-provisioning/version'
|
6
|
+
|
6
7
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version =
|
8
|
+
s.name = "tropo-provisioning"
|
9
|
+
s.version = TropoProvisioning::VERSION
|
9
10
|
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
|
11
|
+
s.authors = ["Jason Goecke", "Juan de Bravo"]
|
12
|
+
s.email = ["jsgoecke@voxeo.com", "juandebravo@gmail.com"]
|
13
|
+
|
14
|
+
s.date = %q{2011-09-05}
|
13
15
|
s.description = %q{Library for interacting with the Tropo Provisioning API}
|
14
|
-
s.email = %q{jsgoecke@voxeo.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".gitignore",
|
21
|
-
"LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"lib/tropo-provisioning.rb",
|
26
|
-
"lib/tropo-provisioning/tropo-provisioning.rb",
|
27
|
-
"lib/tropo-provisioning/error.rb",
|
28
|
-
"tropo-provisioning.gemspec"
|
29
|
-
]
|
30
|
-
s.homepage = %q{http://github.com/tropo/tropo-provisioning}
|
31
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
-
s.require_paths = ["lib"]
|
33
|
-
s.rubygems_version = %q{1.3.7}
|
34
16
|
s.summary = %q{Library for interacting with the Tropo Provisioning API}
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
"examples/create_address.rb",
|
41
|
-
"examples/create_user.rb",
|
42
|
-
"examples/create_application.rb",
|
43
|
-
"examples/delete_application.rb",
|
44
|
-
"examples/list_addresses.rb",
|
45
|
-
"examples/list_applications.rb",
|
46
|
-
"examples/list_exchanges.rb",
|
47
|
-
"examples/list_pin.rb",
|
48
|
-
"examples/update_application.rb"
|
49
|
-
]
|
17
|
+
|
18
|
+
s.rubyforge_project = "tropo-provisioning"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {examples,test,spec,features}/*`.split("\n")
|
50
22
|
|
51
|
-
|
52
|
-
|
53
|
-
s.specification_version = 3
|
23
|
+
s.homepage = %q{http://github.com/tropo/tropo-provisioning}
|
24
|
+
s.require_paths = ["lib"]
|
54
25
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
else
|
65
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
66
|
-
s.add_dependency(%q<hashie>, [">= 0.2.1"])
|
67
|
-
s.add_dependency(%q<activesupport>)
|
68
|
-
end
|
26
|
+
s.add_development_dependency("rspec")
|
27
|
+
s.add_development_dependency("fakeweb")
|
28
|
+
s.add_development_dependency("yard")
|
29
|
+
s.add_development_dependency("rdoc")
|
30
|
+
|
31
|
+
s.add_runtime_dependency("hashie", ">= 0.2.1")
|
32
|
+
s.add_runtime_dependency("activesupport")
|
33
|
+
s.add_runtime_dependency("i18n")
|
69
34
|
end
|
70
35
|
|
metadata
CHANGED
@@ -1,31 +1,64 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tropo-provisioning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jason Goecke
|
9
|
+
- Juan de Bravo
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
13
|
+
date: 2011-09-05 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &70361391690020 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70361391690020
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: fakeweb
|
28
|
+
requirement: &70361391688520 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70361391688520
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: yard
|
39
|
+
requirement: &70361391687380 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70361391687380
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rdoc
|
50
|
+
requirement: &70361391686800 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
23
56
|
type: :development
|
24
57
|
prerelease: false
|
25
|
-
version_requirements: *
|
58
|
+
version_requirements: *70361391686800
|
26
59
|
- !ruby/object:Gem::Dependency
|
27
60
|
name: hashie
|
28
|
-
requirement: &
|
61
|
+
requirement: &70361391686000 !ruby/object:Gem::Requirement
|
29
62
|
none: false
|
30
63
|
requirements:
|
31
64
|
- - ! '>='
|
@@ -33,10 +66,21 @@ dependencies:
|
|
33
66
|
version: 0.2.1
|
34
67
|
type: :runtime
|
35
68
|
prerelease: false
|
36
|
-
version_requirements: *
|
69
|
+
version_requirements: *70361391686000
|
37
70
|
- !ruby/object:Gem::Dependency
|
38
71
|
name: activesupport
|
39
|
-
requirement: &
|
72
|
+
requirement: &70361391685240 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *70361391685240
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: i18n
|
83
|
+
requirement: &70361391684580 !ruby/object:Gem::Requirement
|
40
84
|
none: false
|
41
85
|
requirements:
|
42
86
|
- - ! '>='
|
@@ -44,42 +88,60 @@ dependencies:
|
|
44
88
|
version: '0'
|
45
89
|
type: :runtime
|
46
90
|
prerelease: false
|
47
|
-
version_requirements: *
|
91
|
+
version_requirements: *70361391684580
|
48
92
|
description: Library for interacting with the Tropo Provisioning API
|
49
|
-
email:
|
93
|
+
email:
|
94
|
+
- jsgoecke@voxeo.com
|
95
|
+
- juandebravo@gmail.com
|
50
96
|
executables: []
|
51
97
|
extensions: []
|
52
|
-
extra_rdoc_files:
|
53
|
-
- LICENSE
|
54
|
-
- README.rdoc
|
98
|
+
extra_rdoc_files: []
|
55
99
|
files:
|
56
100
|
- .gitignore
|
101
|
+
- .rspec
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
57
104
|
- LICENSE
|
58
105
|
- README.rdoc
|
59
106
|
- Rakefile
|
60
|
-
-
|
61
|
-
-
|
62
|
-
-
|
63
|
-
- lib/tropo-provisioning/error.rb
|
64
|
-
- tropo-provisioning.gemspec
|
65
|
-
- spec/live-tropo-provisioning_spec.rb
|
66
|
-
- spec/spec_helper.rb
|
67
|
-
- spec/tropo-provisioning_spec.rb
|
107
|
+
- examples/app_details.yml
|
108
|
+
- examples/authenticate_account.rb
|
109
|
+
- examples/config.yml
|
68
110
|
- examples/create_address.rb
|
69
|
-
- examples/create_user.rb
|
70
111
|
- examples/create_application.rb
|
112
|
+
- examples/create_invitation.rb
|
113
|
+
- examples/create_user.rb
|
71
114
|
- examples/delete_application.rb
|
115
|
+
- examples/delete_applications.rb
|
116
|
+
- examples/get_balance.rb
|
72
117
|
- examples/list_addresses.rb
|
73
118
|
- examples/list_applications.rb
|
119
|
+
- examples/list_applications_with_addresses.rb
|
74
120
|
- examples/list_exchanges.rb
|
121
|
+
- examples/list_features.rb
|
122
|
+
- examples/list_invitations.rb
|
123
|
+
- examples/list_partitions_platforms.rb
|
124
|
+
- examples/list_payment_method.rb
|
125
|
+
- examples/list_payment_methods.rb
|
75
126
|
- examples/list_pin.rb
|
127
|
+
- examples/list_user.rb
|
128
|
+
- examples/modify_user.rb
|
76
129
|
- examples/update_application.rb
|
77
|
-
|
130
|
+
- examples/update_invitation.rb
|
131
|
+
- examples/users_search.rb
|
132
|
+
- lib/tropo-provisioning.rb
|
133
|
+
- lib/tropo-provisioning/tropo_client.rb
|
134
|
+
- lib/tropo-provisioning/tropo_error.rb
|
135
|
+
- lib/tropo-provisioning/tropo_provisioning.rb
|
136
|
+
- lib/tropo-provisioning/version.rb
|
137
|
+
- spec/live-tropo-provisioning_spec.rb
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
- spec/tropo-provisioning_spec.rb
|
140
|
+
- tropo-provisioning.gemspec
|
78
141
|
homepage: http://github.com/tropo/tropo-provisioning
|
79
142
|
licenses: []
|
80
143
|
post_install_message:
|
81
|
-
rdoc_options:
|
82
|
-
- --charset=UTF-8
|
144
|
+
rdoc_options: []
|
83
145
|
require_paths:
|
84
146
|
- lib
|
85
147
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -95,22 +157,37 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
157
|
- !ruby/object:Gem::Version
|
96
158
|
version: '0'
|
97
159
|
requirements: []
|
98
|
-
rubyforge_project:
|
99
|
-
rubygems_version: 1.6
|
160
|
+
rubyforge_project: tropo-provisioning
|
161
|
+
rubygems_version: 1.8.6
|
100
162
|
signing_key:
|
101
163
|
specification_version: 3
|
102
164
|
summary: Library for interacting with the Tropo Provisioning API
|
103
165
|
test_files:
|
104
|
-
-
|
105
|
-
-
|
106
|
-
-
|
107
|
-
- spec/live-tropo-provisioning_spec.rb
|
166
|
+
- examples/app_details.yml
|
167
|
+
- examples/authenticate_account.rb
|
168
|
+
- examples/config.yml
|
108
169
|
- examples/create_address.rb
|
109
|
-
- examples/create_user.rb
|
110
170
|
- examples/create_application.rb
|
171
|
+
- examples/create_invitation.rb
|
172
|
+
- examples/create_user.rb
|
111
173
|
- examples/delete_application.rb
|
174
|
+
- examples/delete_applications.rb
|
175
|
+
- examples/get_balance.rb
|
112
176
|
- examples/list_addresses.rb
|
113
177
|
- examples/list_applications.rb
|
178
|
+
- examples/list_applications_with_addresses.rb
|
114
179
|
- examples/list_exchanges.rb
|
180
|
+
- examples/list_features.rb
|
181
|
+
- examples/list_invitations.rb
|
182
|
+
- examples/list_partitions_platforms.rb
|
183
|
+
- examples/list_payment_method.rb
|
184
|
+
- examples/list_payment_methods.rb
|
115
185
|
- examples/list_pin.rb
|
186
|
+
- examples/list_user.rb
|
187
|
+
- examples/modify_user.rb
|
116
188
|
- examples/update_application.rb
|
189
|
+
- examples/update_invitation.rb
|
190
|
+
- examples/users_search.rb
|
191
|
+
- spec/live-tropo-provisioning_spec.rb
|
192
|
+
- spec/spec_helper.rb
|
193
|
+
- spec/tropo-provisioning_spec.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.19
|
@@ -1,864 +0,0 @@
|
|
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
|