octoparts 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -11
- data/lib/octoparts/client.rb +5 -1
- data/lib/octoparts/error.rb +27 -0
- data/lib/octoparts/version.rb +1 -1
- data/lib/octoparts.rb +1 -0
- data/octoparts.gemspec +2 -0
- data/test/fixtures/vcr/invoke_example.yml +33 -0
- data/test/fixtures/vcr/invoke_with_2_requests.yml +34 -0
- data/test/fixtures/vcr/invoke_with_invalid_parameters.yml +32 -0
- data/test/helper.rb +8 -0
- data/test/test_client.rb +87 -0
- metadata +39 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 158d78c413e947f7fd3f43a8a889e36e7569c2d8
|
4
|
+
data.tar.gz: dad9e133b9fe95ecacc1cb9255a7feb14c6527b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef61d18776ed079e6c6793ee627f30cf76575b90aecfaa6e38365d7bab1329ef05bbba4987ebdddc838ea92e3c160bc45117bc0018ae202edb6f875b7ff8b999
|
7
|
+
data.tar.gz: 6db5751507046998c8599835684eb0ca8521937079b2b4f5a91398e6841c46e273c49a1342209038d0d4ef6b6717fd0cef6ed2825101162e2117bb0c6b56d5cf
|
data/README.md
CHANGED
@@ -33,18 +33,20 @@ client = Octoparts::Client.new
|
|
33
33
|
|
34
34
|
# invoke aggregate request
|
35
35
|
response = client.invoke({
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
request_meta: {
|
37
|
+
id: "test",
|
38
|
+
timeout: 500
|
39
39
|
},
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
requests: [
|
41
|
+
{
|
42
|
+
part_id: "echo",
|
43
|
+
params: [
|
44
|
+
{
|
45
|
+
key: "fooValue",
|
46
|
+
value: "test"
|
47
|
+
}
|
48
|
+
]
|
49
|
+
}
|
48
50
|
]
|
49
51
|
})
|
50
52
|
|
data/lib/octoparts/client.rb
CHANGED
@@ -69,7 +69,11 @@ module Octoparts
|
|
69
69
|
@connection ||= Faraday.new(url: @endpoint) do |connection|
|
70
70
|
connection.adapter Faraday.default_adapter
|
71
71
|
end
|
72
|
-
@connection.send(method, path, params, @headers.merge(headers || {}))
|
72
|
+
response = @connection.send(method, path, params, @headers.merge(headers || {}))
|
73
|
+
if error = Octoparts::Error.from_response(response)
|
74
|
+
raise error
|
75
|
+
end
|
76
|
+
response
|
73
77
|
end
|
74
78
|
end
|
75
79
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Octoparts
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def self.from_response(response)
|
6
|
+
status = response.status.to_i
|
7
|
+
|
8
|
+
klass = case status
|
9
|
+
when 400..499 then Octoparts::ClientError
|
10
|
+
when 500..599 then Octoparts::ServerError
|
11
|
+
end
|
12
|
+
klass.new(response) unless klass.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(response)
|
16
|
+
@response = response
|
17
|
+
super(error_message)
|
18
|
+
end
|
19
|
+
|
20
|
+
def error_message
|
21
|
+
"status: #{@response.status}, body: #{@response.body}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class ClientError < Error; end
|
26
|
+
class ServerError < Error; end
|
27
|
+
end
|
data/lib/octoparts/version.rb
CHANGED
data/lib/octoparts.rb
CHANGED
data/octoparts.gemspec
CHANGED
@@ -26,4 +26,6 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
27
|
spec.add_development_dependency "pry"
|
28
28
|
spec.add_development_dependency "test-unit", "~> 3.0"
|
29
|
+
spec.add_development_dependency "webmock"
|
30
|
+
spec.add_development_dependency "vcr"
|
29
31
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://localhost:9000/octoparts/2
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"requestMeta":{"id":"test","timeout":500},"requests":[{"partId":"echo","params":[{"key":"fooValue","value":"test"}]}]}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Octoparts client ruby/0.0.2
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Content-Length:
|
26
|
+
- '309'
|
27
|
+
body:
|
28
|
+
encoding: UTF-8
|
29
|
+
string: '{"responseMeta":{"id":"test","processTime":1},"responses":[{"partId":"echo","id":"echo","cookies":[],"statusCode":200,"mimeType":"application/json","charset":"ISO-8859-1","cacheControl":{"noStore":false,"noCache":false},"contents":"{\"foo\":
|
30
|
+
\"test\"}\n","warnings":[],"errors":[],"retrievedFromCache":true}]}'
|
31
|
+
http_version:
|
32
|
+
recorded_at: Wed, 07 Jan 2015 22:27:38 GMT
|
33
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://localhost:9000/octoparts/2
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"requestMeta":{"id":"test","timeout":500},"requests":[{"partId":"echo","params":[{"key":"fooValue","value":"test"}]},{"partId":"echo","params":[{"key":"fooValue","value":"hoge"}]}]}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Octoparts client ruby/0.0.2
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Content-Length:
|
26
|
+
- '559'
|
27
|
+
body:
|
28
|
+
encoding: UTF-8
|
29
|
+
string: '{"responseMeta":{"id":"test","processTime":10},"responses":[{"partId":"echo","id":"echo","cookies":[],"statusCode":200,"mimeType":"application/json","charset":"ISO-8859-1","cacheControl":{"noStore":false,"noCache":false},"contents":"{\"foo\":
|
30
|
+
\"test\"}\n","warnings":[],"errors":[],"retrievedFromCache":true},{"partId":"echo","id":"echo","cookies":[],"statusCode":200,"mimeType":"application/json","charset":"ISO-8859-1","cacheControl":{"noStore":false,"noCache":false},"contents":"{\"foo\":
|
31
|
+
\"hoge\"}\n","warnings":[],"errors":[],"retrievedFromCache":true}]}'
|
32
|
+
http_version:
|
33
|
+
recorded_at: Wed, 07 Jan 2015 22:48:47 GMT
|
34
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://localhost:9000/octoparts/2
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"requestMeta":{"timeout":500}}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Octoparts client ruby/0.0.2
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 400
|
21
|
+
message: Bad Request
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- text/plain; charset=utf-8
|
25
|
+
Content-Length:
|
26
|
+
- '27'
|
27
|
+
body:
|
28
|
+
encoding: UTF-8
|
29
|
+
string: Unrecognized request object
|
30
|
+
http_version:
|
31
|
+
recorded_at: Thu, 08 Jan 2015 05:57:31 GMT
|
32
|
+
recorded_with: VCR 2.9.3
|
data/test/helper.rb
CHANGED
data/test/test_client.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestClient < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@client = Octoparts::Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
sub_test_case "#invoke" do
|
9
|
+
test "normal invoke" do
|
10
|
+
VCR.use_cassette 'invoke_example' do
|
11
|
+
response = @client.invoke({
|
12
|
+
"request_meta" => {
|
13
|
+
"id" => "test",
|
14
|
+
"timeout" => 500
|
15
|
+
},
|
16
|
+
"requests" => [
|
17
|
+
"part_id" => "echo",
|
18
|
+
"params" => [
|
19
|
+
{
|
20
|
+
"key" => "fooValue",
|
21
|
+
"value" => "test"
|
22
|
+
}
|
23
|
+
]
|
24
|
+
]
|
25
|
+
})
|
26
|
+
body = response.body
|
27
|
+
assert { body.class == Octoparts::Model::AggregateResponse }
|
28
|
+
assert { body.response_meta.class == Octoparts::Model::ResponseMeta }
|
29
|
+
assert { body.responses.first.class == Octoparts::Model::PartResponse }
|
30
|
+
assert { body.responses.first.cache_control.class == Octoparts::Model::CacheControl }
|
31
|
+
assert { body.responses.size == 1 }
|
32
|
+
assert { body.responses.first.contents =~ /"test"/ }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
test "normal invoke when 2 requests" do
|
37
|
+
VCR.use_cassette 'invoke_with_2_requests' do
|
38
|
+
response = @client.invoke({
|
39
|
+
request_meta: {
|
40
|
+
id: "test",
|
41
|
+
timeout: 500
|
42
|
+
},
|
43
|
+
requests: [
|
44
|
+
{
|
45
|
+
part_id: "echo",
|
46
|
+
params: [
|
47
|
+
{
|
48
|
+
key: "fooValue",
|
49
|
+
value: "test"
|
50
|
+
}
|
51
|
+
]
|
52
|
+
},
|
53
|
+
{
|
54
|
+
part_id: "echo",
|
55
|
+
params: [
|
56
|
+
{
|
57
|
+
key: "fooValue",
|
58
|
+
value: "hoge"
|
59
|
+
}
|
60
|
+
]
|
61
|
+
}
|
62
|
+
]
|
63
|
+
})
|
64
|
+
body = response.body
|
65
|
+
assert { body.class == Octoparts::Model::AggregateResponse }
|
66
|
+
assert { body.response_meta.class == Octoparts::Model::ResponseMeta }
|
67
|
+
assert { body.responses.first.class == Octoparts::Model::PartResponse }
|
68
|
+
assert { body.responses.first.cache_control.class == Octoparts::Model::CacheControl }
|
69
|
+
assert { body.responses.size == 2 }
|
70
|
+
assert { body.responses.first.contents =~ /"test"/ }
|
71
|
+
assert { body.responses.last.contents =~ /"hoge"/ }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
test "invalid parameters" do
|
76
|
+
VCR.use_cassette 'invoke_with_invalid_parameters' do
|
77
|
+
assert_raise Octoparts::ClientError do
|
78
|
+
response = @client.invoke({
|
79
|
+
"request_meta" => {
|
80
|
+
"timeout" => 500
|
81
|
+
}
|
82
|
+
})
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octoparts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takayuki Matsubara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: representable
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: vcr
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
description: " Ruby client library for the Octoparts API "
|
112
140
|
email:
|
113
141
|
- takayuki.1229@gmail.com
|
@@ -123,6 +151,7 @@ files:
|
|
123
151
|
- lib/octoparts.rb
|
124
152
|
- lib/octoparts/client.rb
|
125
153
|
- lib/octoparts/configuration.rb
|
154
|
+
- lib/octoparts/error.rb
|
126
155
|
- lib/octoparts/model.rb
|
127
156
|
- lib/octoparts/model/aggregate_request.rb
|
128
157
|
- lib/octoparts/model/aggregate_response.rb
|
@@ -139,8 +168,12 @@ files:
|
|
139
168
|
- lib/octoparts/response.rb
|
140
169
|
- lib/octoparts/version.rb
|
141
170
|
- octoparts.gemspec
|
171
|
+
- test/fixtures/vcr/invoke_example.yml
|
172
|
+
- test/fixtures/vcr/invoke_with_2_requests.yml
|
173
|
+
- test/fixtures/vcr/invoke_with_invalid_parameters.yml
|
142
174
|
- test/helper.rb
|
143
175
|
- test/representer/test_aggregate_request_representer.rb
|
176
|
+
- test/test_client.rb
|
144
177
|
- test/test_octoparts.rb
|
145
178
|
homepage: https://github.com/ma2gedev/octoparts-rb
|
146
179
|
licenses:
|
@@ -167,6 +200,10 @@ signing_key:
|
|
167
200
|
specification_version: 4
|
168
201
|
summary: Ruby client for the Octoparts API
|
169
202
|
test_files:
|
203
|
+
- test/fixtures/vcr/invoke_example.yml
|
204
|
+
- test/fixtures/vcr/invoke_with_2_requests.yml
|
205
|
+
- test/fixtures/vcr/invoke_with_invalid_parameters.yml
|
170
206
|
- test/helper.rb
|
171
207
|
- test/representer/test_aggregate_request_representer.rb
|
208
|
+
- test/test_client.rb
|
172
209
|
- test/test_octoparts.rb
|