tropo-provisioning 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,41 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tropo-provisioning (0.0.22)
4
+ tropo-provisioning (0.0.24)
5
5
  activesupport
6
6
  hashie (>= 0.2.1)
7
7
  i18n
8
- json
9
8
 
10
9
  GEM
11
10
  remote: http://rubygems.org/
12
11
  specs:
13
- activesupport (3.1.3)
12
+ activesupport (3.2.3)
13
+ i18n (~> 0.6)
14
14
  multi_json (~> 1.0)
15
- diff-lcs (1.1.2)
15
+ diff-lcs (1.1.3)
16
16
  fakeweb (1.3.0)
17
17
  hashie (1.2.0)
18
18
  i18n (0.6.0)
19
- json (1.6.5)
20
- json (1.6.5-java)
21
- multi_json (1.0.4)
22
- rdoc (3.9.4)
23
- rspec (2.3.0)
24
- rspec-core (~> 2.3.0)
25
- rspec-expectations (~> 2.3.0)
26
- rspec-mocks (~> 2.3.0)
27
- rspec-core (2.3.1)
28
- rspec-expectations (2.3.0)
29
- diff-lcs (~> 1.1.2)
30
- rspec-mocks (2.3.0)
31
- yard (0.7.2)
19
+ json (1.7.3)
20
+ multi_json (1.3.5)
21
+ rake (0.9.2.2)
22
+ rdoc (3.12)
23
+ json (~> 1.4)
24
+ rspec (2.10.0)
25
+ rspec-core (~> 2.10.0)
26
+ rspec-expectations (~> 2.10.0)
27
+ rspec-mocks (~> 2.10.0)
28
+ rspec-core (2.10.1)
29
+ rspec-expectations (2.10.0)
30
+ diff-lcs (~> 1.1.3)
31
+ rspec-mocks (2.10.1)
32
+ yard (0.8.1)
32
33
 
33
34
  PLATFORMS
34
- java
35
35
  ruby
36
36
 
37
37
  DEPENDENCIES
38
38
  fakeweb
39
+ rake
39
40
  rdoc
40
41
  rspec
41
42
  tropo-provisioning!
data/README.rdoc CHANGED
@@ -39,7 +39,7 @@ Any HTTP method can be accessed using the TropoProvisioning wrapper:
39
39
 
40
40
  ==== Add a New Application
41
41
 
42
- app_id = tp.add_application({ :name => 'My Shiny New App',
42
+ app_id = tp.create_application({ :name => 'My Shiny New App',
43
43
  :voiceUrl => 'http://mydomain.com/voice_script.rb',
44
44
  :partition => 'staging',
45
45
  :messagingUrl => 'http://mydomain.com/message_script.rb',
@@ -7,7 +7,6 @@ require 'uri'
7
7
 
8
8
  # This class is in charge of handling HTTP requests to the Tropo HTTP endpoint
9
9
  class TropoClient
10
-
11
10
  autoload :TropoError, 'tropo-provisioning/tropo_error'
12
11
 
13
12
  # required HTTP headers
@@ -31,20 +30,20 @@ class TropoClient
31
30
  #
32
31
  # ==== Return
33
32
  # * new TropoClient instance
34
- def initialize(username, password, base_uri = "http://api.tropo.com/v1/", headers = nil, proxy = nil)
33
+ def initialize(username, password, base_uri = "https://api.tropo.com/v1/", headers = nil, proxy = nil)
35
34
  @base_uri = base_uri
36
35
  if RUBY_VERSION =~ /1.8/
37
36
  @base_uri << "/" if !@base_uri[-1].eql?(47)
38
37
  elsif RUBY_VERSION =~ /1.9/
39
38
  @base_uri << "/" if !@base_uri[-1].eql?("/")
40
39
  end
41
-
40
+
42
41
  @username = username
43
42
  @password = password
44
43
  @headers = headers.nil? ? {} : headers
45
44
  @proxy = proxy
46
45
  end
47
-
46
+
48
47
  ##
49
48
  # Send a HTTP Get
50
49
  #
@@ -59,7 +58,7 @@ class TropoClient
59
58
  params.empty? or uri = uri.concat('?').concat(params.collect { |k, v| "#{k}=#{v.to_s}" }.join("&"))
60
59
  request(Net::HTTP::Get.new(uri))
61
60
  end
62
-
61
+
63
62
  ##
64
63
  # Send a HTTP Post
65
64
  #
@@ -73,7 +72,7 @@ class TropoClient
73
72
  uri = "#{base_uri}#{resource}"
74
73
  request(Net::HTTP::Post.new(uri), params)
75
74
  end
76
-
75
+
77
76
  ##
78
77
  # Send a HTTP Delete
79
78
  #
@@ -115,11 +114,11 @@ class TropoClient
115
114
  params.each { |k,v| camelized.merge!(k.to_s.camelize(:lower).to_sym => v) }
116
115
  camelized
117
116
  end
118
-
119
-
117
+
118
+
120
119
  ##
121
120
  # Sets the HTTP REST type based on the method being called
122
- #
121
+ #
123
122
  # ==== Parameters
124
123
  # * [required, ymbol] the HTTP method to use, may be :delete, :get, :post or :put
125
124
  # * [Object] the uri object to create the request for
@@ -141,9 +140,9 @@ class TropoClient
141
140
  end
142
141
 
143
142
  private
144
-
143
+
145
144
  ##
146
- # Creates (one once) a HTTP client to the Tropo provisioning endpoint
145
+ # Creates a HTTP client to the Tropo provisioning endpoint
147
146
  #
148
147
  # ==== Return
149
148
  # * Net::HTTP instance
@@ -164,13 +163,13 @@ class TropoClient
164
163
  base = Net::HTTP
165
164
  end
166
165
  end
167
-
166
+
168
167
  http = base.new(uri.host, uri.port)
169
168
  http.use_ssl = true if uri.scheme == 'https'
170
169
  http
171
170
  )
172
171
  end
173
-
172
+
174
173
  ##
175
174
  # Send a request to the Tropo provisioning API
176
175
  #
@@ -181,18 +180,18 @@ class TropoClient
181
180
  # ==== Return
182
181
  # * [Hash] the result of the request
183
182
  # * [TropoError]
184
- # if it can not connect to the API server or if the response.code is not 200
183
+ # if it can not connect to the API server or if the response.code is not 200
185
184
  def request(http_request, body = {})
186
185
 
187
186
  unless http_request.is_a?(Net::HTTPRequest)
188
187
  raise TropoError.new("Invalid request type #{http_request}")
189
188
  end
190
-
189
+
191
190
  http_request.initialize_http_header(headers)
192
191
  http_request.basic_auth username, password
193
192
 
194
193
  # Include body if received
195
- body.empty? or http_request.body = ActiveSupport::JSON.encode(camelize_params(body))
194
+ body.empty? or http_request.body = ActiveSupport::JSON.encode(camelize_params(body))
196
195
 
197
196
  begin
198
197
  response = http.request(http_request)
@@ -201,13 +200,13 @@ class TropoClient
201
200
  end
202
201
 
203
202
  response.code.eql?('200') or raise TropoError.new(response.code), "#{response.code}: #{response.message} - #{response.body}"
204
-
203
+
205
204
  result = ActiveSupport::JSON.decode response.body
206
205
  if result.instance_of? Array
207
206
  self.class.hashie_array(result)
208
207
  else
209
208
  Hashie::Mash.new(result)
210
- end
209
+ end
211
210
  end
212
211
 
213
212
  class << self
@@ -227,5 +226,5 @@ class TropoClient
227
226
  hashied_array
228
227
  end
229
228
  end
230
-
231
- end
229
+
230
+ end