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
data/test/test_bag.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe "Param Bag" do
|
4
|
+
it "should let me set basic parameters" do
|
5
|
+
b = Stretchr::Bag.new
|
6
|
+
b.set("param", "value")
|
7
|
+
assert_equal "value", b.get("param")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "Should let you merge parameters into a query string" do
|
11
|
+
b = Stretchr::Bag.new
|
12
|
+
b.set("include", "~parent")
|
13
|
+
b.set("key", "asdf")
|
14
|
+
assert_equal "include=~parent&key=asdf", URI.decode(b.query_string), "Should let you create a query string"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "Should let me specify a key to start the bag with" do
|
18
|
+
b = Stretchr::Bag.new({prefix: ":"})
|
19
|
+
b.set("age", "21")
|
20
|
+
assert_equal "21", b.get("age"), "Should have set the age"
|
21
|
+
assert_equal ":age=21", URI.decode(b.query_string), "Should have added a prefix to the bag"
|
22
|
+
end
|
23
|
+
end
|
data/test/test_client.rb
CHANGED
@@ -1,132 +1,55 @@
|
|
1
|
-
require 'test/unit'
|
2
1
|
require 'test_helper.rb'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
def test_new_with_missing_fields
|
7
|
-
assert_raise Stretchr::MissingAttributeError do
|
8
|
-
stretchr = Stretchr::Client.new({})
|
9
|
-
end
|
10
|
-
assert_raise Stretchr::MissingAttributeError do
|
11
|
-
stretchr = Stretchr::Client.new({public_key: "test", project: "project.company"})
|
12
|
-
end
|
13
|
-
assert_raise Stretchr::MissingAttributeError do
|
14
|
-
stretchr = Stretchr::Client.new({private_key: 'ABC123-private', project: "project.company"})
|
15
|
-
end
|
16
|
-
assert_raise Stretchr::MissingAttributeError do
|
17
|
-
stretchr = Stretchr::Client.new({private_key: 'ABC123-private', public_key: "test"})
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_new_defaults
|
23
|
-
|
24
|
-
stretchr = test_stretchr_object
|
25
|
-
assert_not_nil stretchr.signatory, "stretchr.signatory"
|
26
|
-
assert_not_nil stretchr.transporter, "stretchr.transporter"
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_new_custom_transporter
|
31
|
-
|
3
|
+
describe "Client" do
|
4
|
+
it "Should let you pass in the transporter you want" do
|
32
5
|
transporter = Object.new
|
33
|
-
stretchr = Stretchr::Client.new({transporter: transporter
|
34
|
-
assert_equal transporter, stretchr.transporter
|
35
|
-
|
6
|
+
stretchr = Stretchr::Client.new({transporter: transporter})
|
7
|
+
assert_equal transporter, stretchr.transporter, "Should have let me pass in a transporter"
|
36
8
|
end
|
37
9
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
assert_equal
|
43
|
-
|
10
|
+
it "Should return a request object whenever you try to do something" do
|
11
|
+
stretchr = Stretchr::Client.new
|
12
|
+
r = stretchr.people
|
13
|
+
assert_equal Stretchr::Request, r.class, "Should have returned a request object"
|
14
|
+
assert_equal "people", r.path, "Should have started building the url"
|
44
15
|
end
|
45
16
|
|
46
|
-
|
47
|
-
|
48
|
-
stretchr
|
49
|
-
stretchr.people(123).books
|
50
|
-
|
51
|
-
stretchr.http_method = :get
|
52
|
-
|
53
|
-
request = stretchr.generate_request
|
54
|
-
|
55
|
-
assert_equal true, request.is_a?(Stretchr::Request)
|
56
|
-
|
57
|
-
assert_equal(stretchr.http_method, request.http_method)
|
58
|
-
assert_equal(stretchr.signed_uri, request.signed_uri)
|
59
|
-
|
17
|
+
it "Should let you specify the version of the api you want to work with" do
|
18
|
+
stretchr = Stretchr::Client.new({api_version: "1.1"})
|
19
|
+
assert_equal "1.1", stretchr.api_version, "Should let me specify the api version that I want"
|
60
20
|
end
|
61
21
|
|
62
|
-
|
63
|
-
stretchr =
|
64
|
-
assert_equal
|
22
|
+
it "Should let me specify the project and key" do
|
23
|
+
stretchr = Stretchr::Client.new({project: "asdf", key: "asdf2"})
|
24
|
+
assert_equal "asdf", stretchr.project, "Should have let me pass in the project"
|
25
|
+
assert_equal "asdf2", stretchr.key, "Should have let me pass in the key"
|
65
26
|
end
|
66
27
|
|
67
|
-
|
68
|
-
stretchr =
|
69
|
-
stretchr.people
|
70
|
-
assert_equal
|
71
|
-
assert_equal true, stretchr.uri.validate_param_value("~skip", "10"), "skip not set"
|
72
|
-
|
73
|
-
stretchr = test_stretchr_object
|
74
|
-
stretchr.people.limit(10).page(2)
|
75
|
-
assert_equal true, stretchr.uri.validate_param_value("~limit", "10"), "limit not set"
|
76
|
-
assert_equal true, stretchr.uri.validate_param_value("~skip", "10"), "skip not set"
|
28
|
+
it "Should pass the client to the request" do
|
29
|
+
stretchr = Stretchr::Client.new({project: "asdf", api_version: "v1.1"})
|
30
|
+
r = stretchr.people
|
31
|
+
assert_equal stretchr, r.client, "Should have passed the client into the request"
|
77
32
|
end
|
78
33
|
|
79
|
-
|
80
|
-
stretchr =
|
81
|
-
stretchr.
|
82
|
-
assert_equal true, stretchr.uri.validate_param_value("~order", "-age")
|
83
|
-
|
84
|
-
stretchr = test_stretchr_object
|
85
|
-
stretchr.people.order("-age,name")
|
86
|
-
assert_equal true, stretchr.uri.validate_param_value("~order", "-age,name")
|
34
|
+
it "Should have a default api_version" do
|
35
|
+
stretchr = Stretchr::Client.new
|
36
|
+
assert stretchr.api_version, "Should have set a default api version"
|
87
37
|
end
|
88
38
|
|
89
|
-
|
90
|
-
Stretchr.
|
91
|
-
|
92
|
-
s.public_key = "test_public"
|
93
|
-
s.project = "test"
|
94
|
-
end
|
95
|
-
|
96
|
-
assert_equal Stretchr.instance_eval {@configuration.private_key}, "test_private", "Should have setup configuration for the module"
|
97
|
-
assert_nothing_raised do
|
98
|
-
client = Stretchr::Client.new
|
99
|
-
end
|
100
|
-
|
101
|
-
assert_raise Stretchr::UnknownConfiguration, "Should raise an error when we pass an unknown configuration in" do
|
102
|
-
Stretchr.config do |s|
|
103
|
-
s.fake_param = "what"
|
104
|
-
end
|
105
|
-
end
|
106
|
-
#FIXME : this is a hack to reset the client!
|
107
|
-
Stretchr.instance_eval {@configuration = Stretchr::Configuration.new}
|
39
|
+
it "Should let me specify the hostname I want" do
|
40
|
+
stretchr = Stretchr::Client.new({hostname: "ryon.com"})
|
41
|
+
assert_equal "ryon.com", stretchr.hostname, "Should have let me specify the hostname I want"
|
108
42
|
end
|
109
43
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
44
|
+
it "Should default to the stretchr hostname" do
|
45
|
+
stretchr = Stretchr::Client.new
|
46
|
+
assert_equal 'stretchr.com', stretchr.hostname, "Should have defaulted to the correct hostname"
|
114
47
|
end
|
115
48
|
|
116
|
-
|
117
|
-
stretchr =
|
118
|
-
stretchr.
|
119
|
-
assert_raises Stretchr::NotFound, "Should have returned not found!" do
|
120
|
-
stretchr.transporter.responses << Stretchr::Response.new({json: ({"~s" => 404}).to_json})
|
121
|
-
stretchr.get
|
122
|
-
end
|
49
|
+
it "Should set a default transporter if I don't" do
|
50
|
+
stretchr = Stretchr::Client.new
|
51
|
+
assert_equal Stretchr::JSONTransporter, stretchr.transporter.class, "Should have defaulted to JSON transport"
|
123
52
|
end
|
124
53
|
|
125
|
-
def test_query
|
126
|
-
stretchr = test_stretchr_object
|
127
|
-
stretchr.where("name" => "ryan", "age" => ">21")
|
128
|
-
assert stretchr.uri.validate_param_value(":name", "ryan"), "Should have searched for a name"
|
129
|
-
assert stretchr.uri.validate_param_value(":age", ">21"), "Should search for an age"
|
130
|
-
end
|
131
54
|
|
132
55
|
end
|
data/test/test_config.rb
ADDED
data/test/test_helper.rb
CHANGED
@@ -1,59 +1,9 @@
|
|
1
1
|
require "cgi" unless defined? CGI
|
2
2
|
require_relative "../lib/stretchr"
|
3
|
+
require "minitest/autorun"
|
3
4
|
|
4
|
-
def
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
module Stretchr
|
9
|
-
class GenerateResponse
|
10
|
-
class << self
|
11
|
-
def get_single_response(params = {})
|
12
|
-
response = {
|
13
|
-
"~s" => params[:status] || 200,
|
14
|
-
"~d" => params[:data],
|
15
|
-
}
|
16
|
-
response["~e"] = params[:errors] if params[:errors]
|
17
|
-
response["~x"] = params[:context] if params[:context]
|
18
|
-
response["~ch"] = params[:change_info] if params[:change_info]
|
19
|
-
response.to_json
|
20
|
-
end
|
21
|
-
|
22
|
-
def get_collection_response(params = {})
|
23
|
-
response = {
|
24
|
-
"~s" => params[:status] || 200,
|
25
|
-
"~d" => {
|
26
|
-
"~t" => params[:total] || 10,
|
27
|
-
"~c" => params[:in_response] || 0
|
28
|
-
},
|
29
|
-
}
|
30
|
-
if params[:objects]
|
31
|
-
response["~d"]["~i"] = params[:objects]
|
32
|
-
response["~d"]["~c"] = params[:objects].length
|
33
|
-
end
|
34
|
-
response["~e"] = params[:errors] if params[:errors]
|
35
|
-
response["~x"] = params[:context] if params[:context]
|
36
|
-
response["~ch"] = params[:change_info] if params[:change_info]
|
37
|
-
response.to_json
|
38
|
-
end
|
39
|
-
|
40
|
-
def post_response(params = {})
|
41
|
-
response = {
|
42
|
-
"~s" => params[:status] || 200,
|
43
|
-
"~ch" => {"~c" => 1, "~u" => 1, "~d" => 0 }
|
44
|
-
}
|
45
|
-
response["~ch"]["~deltas"] = params[:deltas] if params[:deltas]
|
46
|
-
response.to_json
|
47
|
-
end
|
48
|
-
|
49
|
-
def put_response(params = {})
|
50
|
-
{
|
51
|
-
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
5
|
+
def load_api_response(filename)
|
6
|
+
File.open(File.join(Dir.pwd, "test", "stubs", filename)) {|f| f.read }
|
57
7
|
end
|
58
8
|
|
59
9
|
module URI
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe "Request Object" do
|
4
|
+
it "Should let you build up a url" do
|
5
|
+
r = Stretchr::Request.new
|
6
|
+
r.people(1).cars
|
7
|
+
assert_equal "people/1/cars", r.path, "Should have built up a path"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "Should know how to build a complete url including path" do
|
11
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1"})
|
12
|
+
r = Stretchr::Request.new({client: c})
|
13
|
+
assert_equal "http://project.stretchr.com/api/v1.1/people/1/cars", r.people(1).cars.to_url, "Should have built the url properly"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "Should let you pass in params" do
|
17
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1"})
|
18
|
+
r = Stretchr::Request.new({client: c})
|
19
|
+
r.param("key", "asdf")
|
20
|
+
assert r.to_url.include?("?key=asdf"), "Should have added the params"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should let you chain params" do
|
24
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1"})
|
25
|
+
r = Stretchr::Request.new({client: c})
|
26
|
+
r.param("key", "asdf").param("key2", "asdf2")
|
27
|
+
uri = r.to_uri
|
28
|
+
assert_equal "asdf", uri.get_param("key").first, "should have set key"
|
29
|
+
assert_equal "asdf2", uri.get_param("key2").first, "Should have set key2"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should let you add filters" do
|
33
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1"})
|
34
|
+
r = Stretchr::Request.new({client: c})
|
35
|
+
r.where("name", "ryan").where("age", "21")
|
36
|
+
assert_equal ["ryan"], r.to_uri.get_param(":name"), "Should have added filters"
|
37
|
+
assert_equal ["21"], r.to_uri.get_param(":age"), "Should have added filter for age"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Should let you add multiple filters" do
|
41
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1"})
|
42
|
+
r = Stretchr::Request.new({client: c})
|
43
|
+
r.where("age", [">21", "<40"])
|
44
|
+
assert_equal [">21", "<40"], r.to_uri.get_param(":age"), "Should have added multiple ages"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "Should let you get objects" do
|
48
|
+
t = Stretchr::TestTransporter.new
|
49
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
50
|
+
r = Stretchr::Request.new({client: c})
|
51
|
+
r.people.get
|
52
|
+
assert_equal :get, t.requests.first[:method], "Should have performed a get request"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "Should let you create new objects" do
|
56
|
+
t = Stretchr::TestTransporter.new
|
57
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
58
|
+
r = Stretchr::Request.new({client: c})
|
59
|
+
r.people.create({name: "ryan"})
|
60
|
+
assert_equal :post, t.requests.first[:method], "Should have performed a post"
|
61
|
+
assert_equal "ryan", t.requests.first[:body][:name], "Should have sent the body to the transporter"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "Should let you replace an existing object" do
|
65
|
+
t = Stretchr::TestTransporter.new
|
66
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
67
|
+
r = Stretchr::Request.new({client: c})
|
68
|
+
r.people(1).replace({name: "ryan"})
|
69
|
+
assert_equal :put, t.requests.first[:method], "Should have performed a put"
|
70
|
+
assert_equal "ryan", t.requests.first[:body][:name], "Should have sent the body to the transporter"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "Should let you update an existing object" do
|
74
|
+
t = Stretchr::TestTransporter.new
|
75
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
76
|
+
r = Stretchr::Request.new({client: c})
|
77
|
+
r.people(1).update({name: "ryan"})
|
78
|
+
assert_equal :patch, t.requests.first[:method], "Should have performed a put"
|
79
|
+
assert_equal "ryan", t.requests.first[:body][:name], "Should have sent the body to the transporter"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "Should let you remove an object or collection" do
|
83
|
+
t = Stretchr::TestTransporter.new
|
84
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
85
|
+
r = Stretchr::Request.new({client: c})
|
86
|
+
r.people(1).remove
|
87
|
+
assert_equal :delete, t.requests.first[:method], "Should have performed a put"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "Should set a default api version" do
|
91
|
+
r = Stretchr::Request.new
|
92
|
+
assert r.api_version, "it should have set a default api version"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "Should let me pass in a client" do
|
96
|
+
client = Object.new
|
97
|
+
r = Stretchr::Request.new({client: client})
|
98
|
+
assert_equal client, r.client, "Should have passed the client to the request"
|
99
|
+
end
|
100
|
+
|
101
|
+
it "Should pass the client to the transporter" do
|
102
|
+
t = Stretchr::TestTransporter.new
|
103
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
104
|
+
r = Stretchr::Request.new({client: c})
|
105
|
+
r.people.get
|
106
|
+
assert_equal c, t.requests.first[:client], "Should have passed the client to the transporter"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should pass the correct uri to the transporter" do
|
110
|
+
t = Stretchr::TestTransporter.new
|
111
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
112
|
+
r = Stretchr::Request.new({client: c})
|
113
|
+
r.people.get
|
114
|
+
assert_equal "http://project.stretchr.com/api/v1.1/people", r.to_url, "Should have saved the right url in the request"
|
115
|
+
assert_equal "http://project.stretchr.com/api/v1.1/people", t.requests.first[:uri].to_s, "Should have created the right URL and sent it to the transporter"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "Should know how to handle paging" do
|
119
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1"})
|
120
|
+
r = Stretchr::Request.new({client: c})
|
121
|
+
r.people.limit(10).skip(10)
|
122
|
+
assert r.to_uri.validate_param_value("limit", "10"), "should have added limit"
|
123
|
+
assert r.to_uri.validate_param_value("skip", "10"), "should have added skip"
|
124
|
+
|
125
|
+
r2 = Stretchr::Request.new({client: c})
|
126
|
+
r2.people.limit(10).page(2)
|
127
|
+
assert r2.to_uri.validate_param_value("limit", "10"), "should have added limit"
|
128
|
+
assert r2.to_uri.validate_param_value("skip", "10"), "should have added skip from paging"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "Should understand how to do ordering" do
|
132
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1"})
|
133
|
+
r = Stretchr::Request.new({client: c})
|
134
|
+
r.order("-name,age")
|
135
|
+
assert r.to_uri.validate_param_value("order", "-name,age"), "should have added order attribute"
|
136
|
+
end
|
137
|
+
|
138
|
+
it "Should support the necessary convenience methods" do
|
139
|
+
# READ/GET
|
140
|
+
t = Stretchr::TestTransporter.new
|
141
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
142
|
+
r = Stretchr::Request.new({client: c})
|
143
|
+
r.people.get
|
144
|
+
assert_equal :get, t.requests.first[:method], "Should have performed a get request"
|
145
|
+
r.people.read
|
146
|
+
assert_equal :get, t.requests[1][:method], "Should have performed a get request"
|
147
|
+
|
148
|
+
# REPLACE/PUT
|
149
|
+
t = Stretchr::TestTransporter.new
|
150
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
151
|
+
r = Stretchr::Request.new({client: c})
|
152
|
+
r.people.replace({name: "ryan"})
|
153
|
+
assert_equal :put, t.requests.first[:method], "Should have performed a put request"
|
154
|
+
r.people.put({name: "ryan"})
|
155
|
+
assert_equal :put, t.requests[1][:method], "Should have performed a put request"
|
156
|
+
|
157
|
+
# UPDATE/PATCH
|
158
|
+
t = Stretchr::TestTransporter.new
|
159
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
160
|
+
r = Stretchr::Request.new({client: c})
|
161
|
+
r.people.update({name: "ryan"})
|
162
|
+
assert_equal :patch, t.requests.first[:method], "Should have performed a patch request"
|
163
|
+
r.people.patch({name: "ryan"})
|
164
|
+
assert_equal :patch, t.requests[1][:method], "Should have performed a patch request"
|
165
|
+
|
166
|
+
# CREATE/POST
|
167
|
+
t = Stretchr::TestTransporter.new
|
168
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
169
|
+
r = Stretchr::Request.new({client: c})
|
170
|
+
r.people.create({name: "ryan"})
|
171
|
+
assert_equal :post, t.requests.first[:method], "Should have performed a post request"
|
172
|
+
r.people.post({name: "ryan"})
|
173
|
+
assert_equal :post, t.requests[1][:method], "Should have performed a post request"
|
174
|
+
|
175
|
+
# REMOVE/DELETE
|
176
|
+
t = Stretchr::TestTransporter.new
|
177
|
+
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
178
|
+
r = Stretchr::Request.new({client: c})
|
179
|
+
r.people.remove
|
180
|
+
assert_equal :delete, t.requests.first[:method], "Should have performed a delete request"
|
181
|
+
r.people.delete
|
182
|
+
assert_equal :delete, t.requests[1][:method], "Should have performed a delete request"
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe "Response" do
|
4
|
+
it "Should take in and store a response" do
|
5
|
+
d = {name: "ryon"}.to_json
|
6
|
+
r = Stretchr::Response.new(d)
|
7
|
+
assert_equal d, r.raw, "Should have saved the raw response"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "Should know if the response was successfull" do
|
11
|
+
r = Stretchr::Response.new(load_api_response("get_collection_response.json"))
|
12
|
+
assert r.success?, "Should have registered response as success"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "Should parse out the json data" do
|
16
|
+
d = {name: "ryon"}.to_json
|
17
|
+
r = Stretchr::Response.new(d)
|
18
|
+
assert_equal "ryon", r.parsed["name"], "Should have parsed out the data"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "Should no how to pull out data from a stretchr response" do
|
22
|
+
r = Stretchr::Response.new(load_api_response("get_single_response.json"))
|
23
|
+
assert_equal "value", r.data["field"], "Should have pulled actual data from stretchr standard response"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "Should let me specify my own api_version" do
|
27
|
+
d = {name: "ryon"}.to_json
|
28
|
+
r = Stretchr::Response.new(d, {api_version: "v2"})
|
29
|
+
assert_equal "v2", r.api_version, "Should have let me specify the api version"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "Should know how to extract errors out" do
|
33
|
+
r = Stretchr::Response.new(load_api_response("not_found_error.json"))
|
34
|
+
assert_equal false, r.success?, "Should have registered as a failure"
|
35
|
+
assert_equal "one", r.errors.first["~message"], "Should have returned the errors as an array"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "Should be able to return the changes" do
|
39
|
+
r = Stretchr::Response.new(load_api_response("post_single_object.json"))
|
40
|
+
assert_equal 1, r.changes["~created"], "Should have returned the changes"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "Should give me access to the status" do
|
44
|
+
r = Stretchr::Response.new(load_api_response("get_single_response.json"))
|
45
|
+
assert_equal 200, r.status, "Should have pulled out the response"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "Should know how to pull items out of a response" do
|
49
|
+
r = Stretchr::Response.new(load_api_response("get_collection_response.json"))
|
50
|
+
assert_equal "Mat", r.items.first["name"], "Should know how to pull items from response"
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretchr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.2.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ryan Quinn
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: A gem for interacting with your stretchr data
|
15
14
|
email: ryan@mazondo.com
|
@@ -17,50 +16,45 @@ executables: []
|
|
17
16
|
extensions: []
|
18
17
|
extra_rdoc_files: []
|
19
18
|
files:
|
19
|
+
- lib/stretchr/bag.rb
|
20
20
|
- lib/stretchr/client.rb
|
21
|
-
- lib/stretchr/
|
22
|
-
- lib/stretchr/
|
23
|
-
- lib/stretchr/
|
24
|
-
- lib/stretchr/
|
25
|
-
- lib/stretchr/security/signatory.rb
|
26
|
-
- lib/stretchr/security.rb
|
27
|
-
- lib/stretchr/stretchr_request.rb
|
28
|
-
- lib/stretchr/stretchr_response.rb
|
29
|
-
- lib/stretchr/transporters/default_transporter.rb
|
21
|
+
- lib/stretchr/defaults.yaml
|
22
|
+
- lib/stretchr/request.rb
|
23
|
+
- lib/stretchr/response.rb
|
24
|
+
- lib/stretchr/transporters/json_transporter.rb
|
30
25
|
- lib/stretchr/transporters/test_transporter.rb
|
31
|
-
- lib/stretchr/transporters.rb
|
32
26
|
- lib/stretchr.rb
|
27
|
+
- test/stubs/get_collection_response.json
|
28
|
+
- test/stubs/get_single_response.json
|
29
|
+
- test/stubs/not_found_error.json
|
30
|
+
- test/stubs/post_single_object.json
|
31
|
+
- test/test_bag.rb
|
33
32
|
- test/test_client.rb
|
33
|
+
- test/test_config.rb
|
34
34
|
- test/test_helper.rb
|
35
|
-
- test/
|
36
|
-
- test/
|
37
|
-
|
38
|
-
- test/test_stretchr_request.rb
|
39
|
-
- test/test_stretchr_response.rb
|
40
|
-
- test/test_test_transporter.rb
|
41
|
-
homepage: http://www.stretchr.com
|
35
|
+
- test/test_request.rb
|
36
|
+
- test/test_response.rb
|
37
|
+
homepage: https://github.com/stretchr/sdk-ruby
|
42
38
|
licenses: []
|
39
|
+
metadata: {}
|
43
40
|
post_install_message:
|
44
41
|
rdoc_options: []
|
45
42
|
require_paths:
|
46
43
|
- lib
|
47
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
45
|
requirements:
|
50
|
-
- -
|
46
|
+
- - '>='
|
51
47
|
- !ruby/object:Gem::Version
|
52
48
|
version: '0'
|
53
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
50
|
requirements:
|
56
|
-
- -
|
51
|
+
- - '>='
|
57
52
|
- !ruby/object:Gem::Version
|
58
53
|
version: '0'
|
59
54
|
requirements: []
|
60
55
|
rubyforge_project:
|
61
|
-
rubygems_version:
|
56
|
+
rubygems_version: 2.0.3
|
62
57
|
signing_key:
|
63
|
-
specification_version:
|
58
|
+
specification_version: 4
|
64
59
|
summary: A gem for managing your stretchr data
|
65
60
|
test_files: []
|
66
|
-
has_rdoc:
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Stretchr
|
2
|
-
|
3
|
-
class Configuration
|
4
|
-
|
5
|
-
def self.add_option(name, default_value = nil)
|
6
|
-
attr_accessor name
|
7
|
-
@name = default_value
|
8
|
-
end
|
9
|
-
|
10
|
-
add_option :private_key
|
11
|
-
add_option :public_key
|
12
|
-
add_option :project
|
13
|
-
add_option :noisy_errors
|
14
|
-
|
15
|
-
def method_missing(name, *params)
|
16
|
-
raise Stretchr::UnknownConfiguration
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/lib/stretchr/exceptions.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#FIXME : Right now we just define some errors that users can implement if they wish. Should we implement them for them?
|
2
|
-
module Stretchr
|
3
|
-
#basic stretchr error namespace
|
4
|
-
class StretchrError < StandardError; end
|
5
|
-
|
6
|
-
#Configuration
|
7
|
-
class MissingAttributeError < StretchrError; end #thrown when initializing client without params
|
8
|
-
class UnknownConfiguration < StretchrError; end #thrown when we try to set an unknown configuration option
|
9
|
-
|
10
|
-
#stretchr status errors
|
11
|
-
class NotFound < StretchrError; end
|
12
|
-
class InternalServerError < StretchrError; end
|
13
|
-
class BadRequest < StretchrError; end
|
14
|
-
class Unathorized < StretchrError; end
|
15
|
-
class Forbidden < StretchrError; end
|
16
|
-
class Unknown < StretchrError; end
|
17
|
-
|
18
|
-
end
|