stretchr 1.0.0 → 1.2.2
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.
- checksums.yaml +7 -0
- data/lib/stretchr/bag.rb +52 -0
- data/lib/stretchr/client.rb +27 -194
- data/lib/stretchr/defaults.yaml +8 -0
- data/lib/stretchr/request.rb +194 -0
- data/lib/stretchr/response.rb +30 -0
- data/lib/stretchr/transporters/json_transporter.rb +47 -0
- data/lib/stretchr/transporters/test_transporter.rb +12 -23
- data/lib/stretchr.rb +25 -26
- data/test/stubs/get_collection_response.json +13 -0
- data/test/stubs/get_single_response.json +6 -0
- data/test/stubs/not_found_error.json +4 -0
- data/test/stubs/post_single_object.json +8 -0
- data/test/test_bag.rb +23 -0
- data/test/test_client.rb +32 -109
- data/test/test_config.rb +7 -0
- data/test/test_helper.rb +3 -53
- data/test/test_request.rb +184 -0
- data/test/test_response.rb +52 -0
- metadata +21 -27
- data/lib/stretchr/configuration.rb +0 -20
- data/lib/stretchr/exceptions.rb +0 -18
- data/lib/stretchr/resources/resource.rb +0 -129
- data/lib/stretchr/resources.rb +0 -1
- data/lib/stretchr/security/signatory.rb +0 -52
- data/lib/stretchr/security.rb +0 -1
- data/lib/stretchr/stretchr_request.rb +0 -16
- data/lib/stretchr/stretchr_response.rb +0 -39
- data/lib/stretchr/transporters/default_transporter.rb +0 -41
- data/lib/stretchr/transporters.rb +0 -2
- data/test/test_resources.rb +0 -187
- data/test/test_signatory.rb +0 -67
- data/test/test_stretchr_http_actions.rb +0 -190
- data/test/test_stretchr_request.rb +0 -26
- data/test/test_stretchr_response.rb +0 -47
- data/test/test_test_transporter.rb +0 -42
@@ -1,190 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'test_helper.rb'
|
3
|
-
|
4
|
-
class StretchrHttpActionsTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_create
|
7
|
-
|
8
|
-
stretchr = test_stretchr_object
|
9
|
-
|
10
|
-
test_response = Stretchr::Response.new(:json => '{"~s":200,"~d":{"name":"Ryan"}}')
|
11
|
-
stretchr.transporter.responses << test_response
|
12
|
-
|
13
|
-
response_from_post = stretchr.people(123).create({:name=>"Ryan"})
|
14
|
-
|
15
|
-
assert_equal(response_from_post, test_response, "response from get should be the response form the transporter")
|
16
|
-
|
17
|
-
if assert_equal(1, stretchr.transporter.requests.length)
|
18
|
-
|
19
|
-
request = stretchr.transporter.requests[0]
|
20
|
-
|
21
|
-
assert_equal(:post, request.http_method, "http_method")
|
22
|
-
assert_equal(request.body, {:name=>"Ryan"}.to_json)
|
23
|
-
assert_equal("http://project.company.stretchr.com/api/v1/people/123?%7Ekey=test&%7Esign=a2c48a40179fdd9db12f157d289e9ec79b00fe04", request.signed_uri.to_s)
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_update
|
30
|
-
|
31
|
-
stretchr = test_stretchr_object
|
32
|
-
|
33
|
-
test_response = Stretchr::Response.new(:json => '{"~s":200,"~d":{"name":"Ryan"}}')
|
34
|
-
stretchr.transporter.responses << test_response
|
35
|
-
|
36
|
-
response_from_put = stretchr.people(123).update({:name=>"Mat"})
|
37
|
-
|
38
|
-
assert_equal(response_from_put, test_response, "response from get should be the response form the transporter")
|
39
|
-
|
40
|
-
if assert_equal(1, stretchr.transporter.requests.length)
|
41
|
-
|
42
|
-
request = stretchr.transporter.requests[0]
|
43
|
-
|
44
|
-
assert_equal(:put, request.http_method, "http_method")
|
45
|
-
assert_equal(request.body, {:name=>"Mat"}.to_json)
|
46
|
-
assert_equal("http://project.company.stretchr.com/api/v1/people/123?%7Ekey=test&%7Esign=837147f09451a998c041c328821c6b72f88f3336", request.signed_uri.to_s)
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_replace
|
53
|
-
|
54
|
-
stretchr = test_stretchr_object
|
55
|
-
|
56
|
-
test_response = Stretchr::Response.new(:json => '{"~s":200,"~d":{"name":"Ryan"}}')
|
57
|
-
stretchr.transporter.responses << test_response
|
58
|
-
|
59
|
-
response_from_post = stretchr.people(123).replace({:name=>"Ryan"})
|
60
|
-
|
61
|
-
assert_equal(response_from_post, test_response, "response from get should be the response form the transporter")
|
62
|
-
|
63
|
-
if assert_equal(1, stretchr.transporter.requests.length)
|
64
|
-
|
65
|
-
request = stretchr.transporter.requests[0]
|
66
|
-
|
67
|
-
assert_equal(:post, request.http_method, "http_method")
|
68
|
-
assert_equal(request.body, {:name=>"Ryan"}.to_json)
|
69
|
-
assert_equal("http://project.company.stretchr.com/api/v1/people/123?%7Ekey=test&%7Esign=a2c48a40179fdd9db12f157d289e9ec79b00fe04", request.signed_uri.to_s)
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_read
|
76
|
-
|
77
|
-
stretchr = test_stretchr_object
|
78
|
-
|
79
|
-
test_response = Stretchr::Response.new(:json => '{"~s":200,"~d":{"name":"Ryan"}}')
|
80
|
-
stretchr.transporter.responses << test_response
|
81
|
-
|
82
|
-
response_from_get = stretchr.people(123).read
|
83
|
-
|
84
|
-
assert_equal(test_response, response_from_get, "response from get should be the response form the transporter")
|
85
|
-
|
86
|
-
if assert_equal(1, stretchr.transporter.requests.length)
|
87
|
-
|
88
|
-
request = stretchr.transporter.requests[0]
|
89
|
-
|
90
|
-
assert_equal(:get, request.http_method, "http_method")
|
91
|
-
assert_nil(request.body, "body")
|
92
|
-
assert_equal("http://project.company.stretchr.com/api/v1/people/123?%7Ekey=test&%7Esign=a6bfa773f9169dbeae077ba6a8ac3da07fc19db3", request.signed_uri.to_s)
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_get
|
99
|
-
|
100
|
-
stretchr = test_stretchr_object
|
101
|
-
|
102
|
-
test_response = Stretchr::Response.new(:json => '{"~s":200,"~d":{"name":"Ryan"}}')
|
103
|
-
stretchr.transporter.responses << test_response
|
104
|
-
|
105
|
-
response_from_get = stretchr.people(123).get
|
106
|
-
|
107
|
-
assert_equal(test_response, response_from_get, "response from get should be the response form the transporter")
|
108
|
-
|
109
|
-
if assert_equal(1, stretchr.transporter.requests.length)
|
110
|
-
|
111
|
-
request = stretchr.transporter.requests[0]
|
112
|
-
|
113
|
-
assert_equal(:get, request.http_method, "http_method")
|
114
|
-
assert_nil(request.body, "body")
|
115
|
-
assert_equal("http://project.company.stretchr.com/api/v1/people/123?%7Ekey=test&%7Esign=a6bfa773f9169dbeae077ba6a8ac3da07fc19db3", request.signed_uri.to_s)
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_post
|
122
|
-
|
123
|
-
stretchr = test_stretchr_object
|
124
|
-
|
125
|
-
test_response = Stretchr::Response.new(:json => '{"~s":200,"~d":{"name":"Ryan"}}')
|
126
|
-
stretchr.transporter.responses << test_response
|
127
|
-
|
128
|
-
response_from_post = stretchr.people(123).body({:name=>"Ryan"}).post
|
129
|
-
|
130
|
-
assert_equal(response_from_post, test_response, "response from get should be the response form the transporter")
|
131
|
-
|
132
|
-
if assert_equal(1, stretchr.transporter.requests.length)
|
133
|
-
|
134
|
-
request = stretchr.transporter.requests[0]
|
135
|
-
|
136
|
-
assert_equal(:post, request.http_method, "http_method")
|
137
|
-
assert_equal(request.body, {:name=>"Ryan"}.to_json)
|
138
|
-
assert_equal("http://project.company.stretchr.com/api/v1/people/123?%7Ekey=test&%7Esign=a2c48a40179fdd9db12f157d289e9ec79b00fe04", request.signed_uri.to_s)
|
139
|
-
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_put
|
145
|
-
|
146
|
-
stretchr = test_stretchr_object
|
147
|
-
|
148
|
-
test_response = Stretchr::Response.new(:json => '{"~s":200,"~d":{"name":"Ryan"}}')
|
149
|
-
stretchr.transporter.responses << test_response
|
150
|
-
|
151
|
-
response_from_put = stretchr.people(123).body({:name=>"Mat"}).put
|
152
|
-
|
153
|
-
assert_equal(response_from_put, test_response, "response from get should be the response form the transporter")
|
154
|
-
|
155
|
-
if assert_equal(1, stretchr.transporter.requests.length)
|
156
|
-
|
157
|
-
request = stretchr.transporter.requests[0]
|
158
|
-
|
159
|
-
assert_equal(:put, request.http_method, "http_method")
|
160
|
-
assert_equal(request.body, {:name=>"Mat"}.to_json)
|
161
|
-
assert_equal("http://project.company.stretchr.com/api/v1/people/123?%7Ekey=test&%7Esign=837147f09451a998c041c328821c6b72f88f3336", request.signed_uri.to_s)
|
162
|
-
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_delete
|
168
|
-
|
169
|
-
stretchr = test_stretchr_object
|
170
|
-
|
171
|
-
test_response = Stretchr::Response.new(:json => '{"~s":200,"~d":{"name":"Ryan"}}')
|
172
|
-
stretchr.transporter.responses << test_response
|
173
|
-
|
174
|
-
response_from_delete = stretchr.people(123).delete
|
175
|
-
|
176
|
-
assert_equal(response_from_delete, test_response, "response from get should be the response form the transporter")
|
177
|
-
|
178
|
-
if assert_equal(1, stretchr.transporter.requests.length)
|
179
|
-
|
180
|
-
request = stretchr.transporter.requests[0]
|
181
|
-
|
182
|
-
assert_equal(:delete, request.http_method, "http_method")
|
183
|
-
assert_nil(request.body, "body")
|
184
|
-
assert_equal("http://project.company.stretchr.com/api/v1/people/123?%7Ekey=test&%7Esign=7becba6ba04d40b7dd19408776f7f028c0d8f864", request.signed_uri.to_s)
|
185
|
-
|
186
|
-
end
|
187
|
-
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'test_helper.rb'
|
3
|
-
|
4
|
-
class StretchrRequestTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_new
|
7
|
-
|
8
|
-
uri = URI.parse("http://test.stretchr.com/api/v1")
|
9
|
-
r = Stretchr::Request.new(
|
10
|
-
:http_method => :get,
|
11
|
-
:signed_uri => uri,
|
12
|
-
:body => "This is the body",
|
13
|
-
:headers => {
|
14
|
-
"X-Custom-Header" => "Hello"
|
15
|
-
}
|
16
|
-
)
|
17
|
-
|
18
|
-
assert_equal(r.http_method, :get)
|
19
|
-
assert_equal(r.signed_uri, uri)
|
20
|
-
assert_equal(r.body, "This is the body")
|
21
|
-
assert_equal(r.headers["X-Custom-Header"], "Hello")
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'test_helper.rb'
|
3
|
-
|
4
|
-
class StretchrResponseTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_new_with_json
|
7
|
-
|
8
|
-
json_string = '{"~s":200,"~d":{"name":"Ryan"},"~x":"123","~e":[{"~m":"Something went wrong"}]}'
|
9
|
-
r = Stretchr::Response.new(:json => json_string)
|
10
|
-
|
11
|
-
assert_equal(json_string, r.json_string)
|
12
|
-
assert_equal(200, r.json_object["~s"])
|
13
|
-
|
14
|
-
assert_equal(200, r.status)
|
15
|
-
assert_equal("123", r.client_context)
|
16
|
-
assert_equal("Ryan", r.data["name"])
|
17
|
-
assert_equal(1, r.errors.length)
|
18
|
-
assert_equal("Something went wrong", r.errors[0])
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_change_info
|
23
|
-
json_string = '{"~s":200, "~ch" : {"~deltas" : "test"}}'
|
24
|
-
r = Stretchr::Response.new(:json => json_string)
|
25
|
-
assert_equal r.changed, "test", "Should have grabbed the change info"
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_was_successful
|
30
|
-
json_string = '{"~s":200,"~d":{"name":"Ryan"},"~x":"123","~e":[{"~m":"Something went wrong"}]}'
|
31
|
-
r = Stretchr::Response.new(:json => json_string)
|
32
|
-
assert_equal true, r.success?, "200 success"
|
33
|
-
|
34
|
-
json_string = '{"~s":201,"~d":{"name":"Ryan"},"~x":"123","~e":[{"~m":"Something went wrong"}]}'
|
35
|
-
r = Stretchr::Response.new(:json => json_string)
|
36
|
-
assert_equal true, r.success?, "201 success"
|
37
|
-
|
38
|
-
json_string = '{"~s":404,"~d":{"name":"Ryan"},"~x":"123","~e":[{"~m":"Something went wrong"}]}'
|
39
|
-
r = Stretchr::Response.new(:json => json_string, :supress_errors => true)
|
40
|
-
assert_equal false, r.success?, "404 success"
|
41
|
-
|
42
|
-
json_string = '{"~s":500,"~d":{"name":"Ryan"},"~x":"123","~e":[{"~m":"Something went wrong"}]}'
|
43
|
-
r = Stretchr::Response.new(:json => json_string, :supress_errors => true)
|
44
|
-
assert_equal false, r.success?, "500 success"
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'test_helper.rb'
|
3
|
-
|
4
|
-
class TestTransporterTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_test_transporter
|
7
|
-
|
8
|
-
t = Stretchr::TestTransporter.new
|
9
|
-
|
10
|
-
testRequest = Stretchr::Request.new
|
11
|
-
testResponse = Stretchr::Response.new
|
12
|
-
|
13
|
-
# queue up the repsonse
|
14
|
-
t.responses << testResponse
|
15
|
-
|
16
|
-
# make the request
|
17
|
-
returnedResponse = t.make_request(testRequest)
|
18
|
-
|
19
|
-
if assert_not_nil(t.requests, ".requests should be an array")
|
20
|
-
assert_equal(1, t.requests.length, "Should be one recorded request")
|
21
|
-
assert_equal(testRequest, t.requests[0], "Request should be added to .requests")
|
22
|
-
end
|
23
|
-
|
24
|
-
assert_equal(returnedResponse, testResponse, "Response in queue should be returned")
|
25
|
-
assert_equal(0, t.responses.length, ".responses should lose items as they're returned")
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_test_transporter_response
|
30
|
-
|
31
|
-
t = Stretchr::TestTransporter.new
|
32
|
-
|
33
|
-
testRequest = Stretchr::Request.new
|
34
|
-
|
35
|
-
# make the request
|
36
|
-
returnedResponse = t.make_request(testRequest)
|
37
|
-
|
38
|
-
assert_nil(returnedResponse)
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|