tropo_rest 0.0.3 → 0.0.4
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/lib/tropo_rest/client/session.rb +3 -2
- data/lib/tropo_rest/connection.rb +4 -5
- data/lib/tropo_rest/request.rb +2 -4
- data/lib/tropo_rest/version.rb +1 -1
- data/spec/spec_helper.rb +0 -8
- data/spec/tropo_rest/client/session_spec.rb +30 -19
- data/spec/tropo_rest/client_spec.rb +5 -5
- data/tropo_rest.gemspec +0 -1
- metadata +6 -21
@@ -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!
|
15
|
-
|
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,
|
11
|
+
def connection(url, resource)
|
12
12
|
options = {
|
13
|
-
:headers => {'Accept' => "application
|
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
|
18
|
+
connection.use Faraday::Request::SerializeJson
|
19
19
|
connection.adapter(adapter)
|
20
20
|
connection.basic_auth(username, password)
|
21
|
-
connection.use Faraday::Response::ParseJson
|
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
|
data/lib/tropo_rest/request.rb
CHANGED
@@ -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
|
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,
|
52
|
+
response = connection(url, resource).send(method) do |request|
|
55
53
|
case method
|
56
54
|
when :get, :delete
|
57
55
|
request.url(path, options)
|
data/lib/tropo_rest/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -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'
|
13
|
-
|
14
|
-
with(:
|
15
|
-
to_return(:body => <<-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
27
|
-
with(:
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
with(:
|
35
|
-
@client.create_session("TOKEN",
|
36
|
-
|
37
|
-
with(:
|
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.
|
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
|
125
|
-
params = {'
|
126
|
-
|
127
|
-
@client.
|
128
|
-
|
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
|
data/tropo_rest.gemspec
CHANGED
@@ -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
|
-
-
|
9
|
-
version: 0.0.
|
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-
|
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: &
|
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: *
|
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:
|
306
|
+
hash: 1625226992280391260
|
322
307
|
segments:
|
323
308
|
- 0
|
324
309
|
version: "0"
|