tropo_rest 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,8 +11,9 @@ module TropoRest
11
11
  # @return [Hashie::Mash] The session object.
12
12
  # @see https://www.tropo.com/docs/rest/starting_session.htm
13
13
  def create_session(token, params={})
14
- params.merge! 'action' => 'create', 'token' => token
15
- get(PLURAL_PATH, params)
14
+ params.merge!('token' => token)
15
+ params.merge!(params) { |k,v| v.to_s } # custom parameters must be strings
16
+ post(PLURAL_PATH, params)
16
17
  end
17
18
 
18
19
  end
@@ -8,18 +8,17 @@ module TropoRest
8
8
  module Connection
9
9
  private
10
10
 
11
- def connection(url, format, resource)
11
+ def connection(url, resource)
12
12
  options = {
13
- :headers => {'Accept' => "application/#{format}", 'User-Agent' => user_agent},
13
+ :headers => {'Accept' => "application/json", 'User-Agent' => user_agent},
14
14
  :url => url
15
15
  }
16
16
 
17
17
  Faraday::Connection.new(options) do |connection|
18
- connection.use Faraday::Request::SerializeJson if format.to_sym == :json
18
+ connection.use Faraday::Request::SerializeJson
19
19
  connection.adapter(adapter)
20
20
  connection.basic_auth(username, password)
21
- connection.use Faraday::Response::ParseJson if format.to_sym == :json
22
- connection.use Faraday::Response::ParseXml if format.to_sym == :xml
21
+ connection.use Faraday::Response::ParseJson
23
22
  connection.use Faraday::Response::Resource, resource
24
23
  connection.use Faraday::Response::RaiseHttpErrors
25
24
  end
@@ -47,11 +47,9 @@ module TropoRest
47
47
  path, resource, options = extract_request_args!(*args)
48
48
 
49
49
  # Do we need the session endpoint?
50
- url = path =~ /^\/?sessions/ ? session_endpoint : endpoint
51
- # Need to parse XML for creating a session, but JSON for signals and everything else
52
- format = path =~ /^\/?sessions$/ ? :xml : :json
50
+ url = path =~ /^\/?sessions/ ? session_endpoint : endpoint
53
51
 
54
- response = connection(url, format, resource).send(method) do |request|
52
+ response = connection(url, resource).send(method) do |request|
55
53
  case method
56
54
  when :get, :delete
57
55
  request.url(path, options)
@@ -1,3 +1,3 @@
1
1
  module TropoRest
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -39,18 +39,10 @@ def stub_put(path)
39
39
  stub_request(:put, tropo_url_for(path))
40
40
  end
41
41
 
42
- def a_session_get(path)
43
- a_request(:get, tropo_session_url_for(path))
44
- end
45
-
46
42
  def a_session_post(path)
47
43
  a_request(:post, tropo_session_url_for(path))
48
44
  end
49
45
 
50
- def stub_session_get(path)
51
- stub_request(:get, tropo_session_url_for(path))
52
- end
53
-
54
46
  def stub_session_post(path)
55
47
  stub_request(:post, tropo_session_url_for(path))
56
48
  end
@@ -9,37 +9,48 @@ describe TropoRest::Client do
9
9
  describe "#create_session" do
10
10
 
11
11
  before do
12
- @params = {'token' => 'TOKEN', 'action' => 'create'}
13
- stub_session_get("sessions").
14
- with(:query => @params).
15
- to_return(:body => <<-XML
16
- <session>
17
- <success>true</success>
18
- <token>TOKEN</token>
19
- </session>
20
- XML
12
+ @params = {'token' => 'TOKEN'}
13
+ stub_session_post("sessions").
14
+ with(:body => @params).
15
+ to_return(:body => <<-JSON
16
+ {
17
+ "success": true,
18
+ "token": "TOKEN",
19
+ "id": "ID"
20
+ }
21
+ JSON
21
22
  )
22
23
  end
23
24
 
24
25
  it "should make the request" do
25
26
  @client.create_session("TOKEN")
26
- a_session_get("sessions").
27
- with(:query => @params).should have_been_made
27
+ a_session_post("sessions").
28
+ with(:body => @params).should have_been_made
28
29
  end
29
30
 
30
31
  it "should make the request with parameters" do
31
- params = {'phone_number' => '+19995551234', 'name' => 'Billy Gnosis'}
32
- query = params.merge('action' => 'create', 'token' => 'TOKEN')
33
- stub_session_get("sessions").
34
- with(:query => query)
35
- @client.create_session("TOKEN", params)
36
- a_session_get("sessions").
37
- with(:query => query).should have_been_made
32
+ args = {'phone_number' => '+19995551234', 'name' => 'Billy Gnosis'}
33
+ params = args.merge('token' => 'TOKEN')
34
+ stub_session_post("sessions").
35
+ with(:body => params)
36
+ @client.create_session("TOKEN", args)
37
+ a_session_post("sessions").
38
+ with(:body => params).should have_been_made
39
+ end
40
+
41
+ it "should convert all parameters to strings" do
42
+ args = {'dollars' => 123.45, 'count' => 1}
43
+ params = {'dollars' => '123.45', 'count' => '1', 'token' => 'TOKEN'}
44
+ stub_session_post("sessions").
45
+ with(:body => params)
46
+ @client.create_session("TOKEN", args)
47
+ a_session_post("sessions").
48
+ with(:body => params).should have_been_made
38
49
  end
39
50
 
40
51
  it "should return the session object" do
41
52
  res = @client.create_session("TOKEN")
42
- res.session.should == {'success' => 'true', 'token' => 'TOKEN'}
53
+ res.should == {'success' => true, 'token' => 'TOKEN', 'id' => 'ID'}
43
54
  end
44
55
 
45
56
  end
@@ -121,11 +121,11 @@ describe TropoRest::Client do
121
121
  a_request(:get, "https://api.tropo.com/1.0/sessions").should have_been_made
122
122
  end
123
123
 
124
- it "should send XML Accept header for session requests" do
125
- params = {'action' => 'create', 'token' => 'TOKEN'}
126
- stub_session_get("sessions").with(:query => params)
127
- @client.get("sessions", params)
128
- a_session_get("sessions").with(:query => params, :headers => {"Accept" => "application/xml"}).should have_been_made
124
+ it "should send JSON Accept header for session requests" do
125
+ params = {'token' => 'TOKEN'}
126
+ stub_session_post("sessions").with(:body => params)
127
+ @client.post("sessions", params)
128
+ a_session_post("sessions").with(:body => params, :headers => {"Accept" => "application/json"}).should have_been_made
129
129
  end
130
130
 
131
131
  context "signals" do
@@ -41,7 +41,6 @@ Gem::Specification.new do |s|
41
41
  s.add_runtime_dependency "faraday", "~> 0.5.3"
42
42
  s.add_runtime_dependency "faraday_middleware", "~> 0.3.1"
43
43
  s.add_runtime_dependency "multi_json", "~> 0.0.5"
44
- s.add_runtime_dependency "multi_xml", "~> 0.2.0"
45
44
  s.add_runtime_dependency "hashie", "~> 0.4.0"
46
45
 
47
46
  s.files = `git ls-files`.split("\n")
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Christopher Durtschi
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-09 00:00:00 -07:00
17
+ date: 2011-02-13 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -224,24 +224,9 @@ dependencies:
224
224
  type: :runtime
225
225
  prerelease: false
226
226
  version_requirements: *id014
227
- - !ruby/object:Gem::Dependency
228
- name: multi_xml
229
- requirement: &id015 !ruby/object:Gem::Requirement
230
- none: false
231
- requirements:
232
- - - ~>
233
- - !ruby/object:Gem::Version
234
- segments:
235
- - 0
236
- - 2
237
- - 0
238
- version: 0.2.0
239
- type: :runtime
240
- prerelease: false
241
- version_requirements: *id015
242
227
  - !ruby/object:Gem::Dependency
243
228
  name: hashie
244
- requirement: &id016 !ruby/object:Gem::Requirement
229
+ requirement: &id015 !ruby/object:Gem::Requirement
245
230
  none: false
246
231
  requirements:
247
232
  - - ~>
@@ -253,7 +238,7 @@ dependencies:
253
238
  version: 0.4.0
254
239
  type: :runtime
255
240
  prerelease: false
256
- version_requirements: *id016
241
+ version_requirements: *id015
257
242
  description: A simple wrapper for the Tropo REST API to manipulate applications, addresses, exchanges, sessions.
258
243
  email:
259
244
  - christopher.durtschi@gmail.com
@@ -318,7 +303,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
318
303
  requirements:
319
304
  - - ">="
320
305
  - !ruby/object:Gem::Version
321
- hash: -2424205396918740897
306
+ hash: 1625226992280391260
322
307
  segments:
323
308
  - 0
324
309
  version: "0"