octoparts 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +32 -2
- data/Rakefile +8 -0
- data/lib/octoparts.rb +0 -1
- data/lib/octoparts/client.rb +4 -1
- data/lib/octoparts/representer/aggregate_request_representer.rb +20 -7
- data/lib/octoparts/version.rb +1 -1
- data/octoparts.gemspec +2 -0
- data/test/helper.rb +5 -0
- data/test/representer/test_aggregate_request_representer.rb +64 -0
- data/test/test_octoparts.rb +11 -0
- metadata +37 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13fef2aab30cd287c94672a9bdc9ce0ab4b1edd4
|
4
|
+
data.tar.gz: 6c41cb1d2aa6883b9d66dbb48afc3b6440fcd7ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a55dcf838978766b8a5b048979369fa68671ce94968aaa35403c9bafe2caf586cd811f4a3edd085c68ea67e78713d1e243b1d34c272a9fba420b9baad72c353
|
7
|
+
data.tar.gz: 589fcf6a4364f88b6e7d53093d6aef59d59ef95cd32d5e063de00cb8fb5edde1c3edb7b34d517d5c4203a6b2aac1c8e956c151bf6fb15a3d5a0857ffebfac0ca
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Octoparts
|
2
2
|
|
3
|
-
|
3
|
+
Octoparts Client for Ruby
|
4
|
+
|
5
|
+
Octoparts is the backend services aggregator. See more details [here](http://m3dev.github.io/octoparts/).
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -20,7 +22,35 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Usage
|
22
24
|
|
23
|
-
|
25
|
+
```ruby
|
26
|
+
# configuration
|
27
|
+
Octoparts.configure do |config|
|
28
|
+
config.endpoint = 'http://localhost:9000'
|
29
|
+
end
|
30
|
+
|
31
|
+
# create client
|
32
|
+
client = Octoparts::Client.new
|
33
|
+
|
34
|
+
# invoke aggregate request
|
35
|
+
response = client.invoke({
|
36
|
+
"request_meta" => {
|
37
|
+
"id" => "test",
|
38
|
+
"timeout" => 500
|
39
|
+
},
|
40
|
+
"requests" => [
|
41
|
+
"part_id" => "echo",
|
42
|
+
"params" => [
|
43
|
+
{
|
44
|
+
"key" => "fooValue",
|
45
|
+
"value" => "test"
|
46
|
+
}
|
47
|
+
]
|
48
|
+
]
|
49
|
+
})
|
50
|
+
|
51
|
+
response.status
|
52
|
+
response.body.responses.first.contents
|
53
|
+
```
|
24
54
|
|
25
55
|
## Contributing
|
26
56
|
|
data/Rakefile
CHANGED
data/lib/octoparts.rb
CHANGED
data/lib/octoparts/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support/core_ext/hash/keys'
|
1
2
|
require 'uri'
|
2
3
|
|
3
4
|
module Octoparts
|
@@ -20,7 +21,9 @@ module Octoparts
|
|
20
21
|
|
21
22
|
# TODO: doc
|
22
23
|
def invoke(params)
|
23
|
-
|
24
|
+
stringify_params = params.deep_stringify_keys
|
25
|
+
aggregate_request = Model::AggregateRequest.new.extend(Representer::AggregateRequestRepresenter).from_hash(stringify_params)
|
26
|
+
body = aggregate_request.to_json(camelize: true)
|
24
27
|
headers = { content_type: 'application/json' }
|
25
28
|
resp = post(OCTOPARTS_API_ENDPOINT_PATH, body, headers)
|
26
29
|
Response.new(
|
@@ -1,20 +1,33 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
|
1
3
|
module Octoparts
|
2
4
|
module Representer
|
5
|
+
class Camelizer
|
6
|
+
include Uber::Callable
|
7
|
+
def initialize(camelcase)
|
8
|
+
@camelcase = camelcase
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(_represented, args)
|
12
|
+
args[:camelize] ? @camelcase : @camelcase.underscore
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
3
16
|
module AggregateRequestRepresenter
|
4
17
|
include Representable::JSON
|
5
18
|
|
6
|
-
property :request_meta, as:
|
19
|
+
property :request_meta, as: Camelizer.new('requestMeta'), class: Model::RequestMeta do
|
7
20
|
property :id
|
8
|
-
property :service_id, as:
|
9
|
-
property :user_id, as:
|
10
|
-
property :session_id, as:
|
11
|
-
property :request_url, as:
|
12
|
-
property :user_agent, as:
|
21
|
+
property :service_id, as: Camelizer.new('serviceId')
|
22
|
+
property :user_id, as: Camelizer.new('userId')
|
23
|
+
property :session_id, as: Camelizer.new('sessionId')
|
24
|
+
property :request_url, as: Camelizer.new('requestUrl')
|
25
|
+
property :user_agent, as: Camelizer.new('userAgent')
|
13
26
|
property :timeout
|
14
27
|
end
|
15
28
|
|
16
29
|
collection :requests, class: Model::PartRequest do
|
17
|
-
property :part_id, as:
|
30
|
+
property :part_id, as: Camelizer.new('partId')
|
18
31
|
property :id
|
19
32
|
collection :params, class: Model::PartRequestParam do
|
20
33
|
property :key
|
data/lib/octoparts/version.rb
CHANGED
data/octoparts.gemspec
CHANGED
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "representable"
|
22
|
+
spec.add_dependency "activesupport", "> 4.0.0"
|
22
23
|
spec.add_dependency "faraday"
|
23
24
|
|
24
25
|
spec.add_development_dependency "bundler", "~> 1.7"
|
25
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
27
|
spec.add_development_dependency "pry"
|
28
|
+
spec.add_development_dependency "test-unit", "~> 3.0"
|
27
29
|
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'json'
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
|
+
|
5
|
+
class TestAggregateRequestRepresenter < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@json = <<-"JSON"
|
8
|
+
{
|
9
|
+
"request_meta": {
|
10
|
+
"id": "id",
|
11
|
+
"service_id": "serviceId",
|
12
|
+
"user_id": "userId",
|
13
|
+
"session_id": "sessionId",
|
14
|
+
"request_url": "requestUrl",
|
15
|
+
"user_agent": "userAgent",
|
16
|
+
"timeout": 500
|
17
|
+
},
|
18
|
+
"requests": [
|
19
|
+
{
|
20
|
+
"part_id": "partId",
|
21
|
+
"id": "id",
|
22
|
+
"params": [
|
23
|
+
{
|
24
|
+
"key": "fooValue",
|
25
|
+
"value": "test"
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"key": "nya-",
|
29
|
+
"value": "nya-"
|
30
|
+
}
|
31
|
+
]
|
32
|
+
}
|
33
|
+
]
|
34
|
+
}
|
35
|
+
JSON
|
36
|
+
end
|
37
|
+
|
38
|
+
def convert_hash_keys(value)
|
39
|
+
case value
|
40
|
+
when Array
|
41
|
+
value.map { |v| convert_hash_keys(v) }
|
42
|
+
when Hash
|
43
|
+
Hash[value.map { |k, v| [k.camelcase(:lower), convert_hash_keys(v)] }]
|
44
|
+
else
|
45
|
+
value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
test "underscored keys can change to underscored keys json" do
|
50
|
+
aggregate_request = Octoparts::Model::AggregateRequest.new
|
51
|
+
.extend(Octoparts::Representer::AggregateRequestRepresenter).from_hash(JSON.parse(@json))
|
52
|
+
assert do
|
53
|
+
JSON.parse(aggregate_request.to_json) == JSON.parse(@json)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
test "underscored keys can change to camelcase keys json" do
|
58
|
+
aggregate_request = Octoparts::Model::AggregateRequest.new
|
59
|
+
.extend(Octoparts::Representer::AggregateRequestRepresenter).from_hash(JSON.parse(@json))
|
60
|
+
assert do
|
61
|
+
JSON.parse(aggregate_request.to_json(camelize: true)) == convert_hash_keys(JSON.parse(@json))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
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.2
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: representable
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: faraday
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: test-unit
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
83
111
|
description: " Ruby client library for the Octoparts API "
|
84
112
|
email:
|
85
113
|
- takayuki.1229@gmail.com
|
@@ -111,6 +139,9 @@ files:
|
|
111
139
|
- lib/octoparts/response.rb
|
112
140
|
- lib/octoparts/version.rb
|
113
141
|
- octoparts.gemspec
|
142
|
+
- test/helper.rb
|
143
|
+
- test/representer/test_aggregate_request_representer.rb
|
144
|
+
- test/test_octoparts.rb
|
114
145
|
homepage: https://github.com/ma2gedev/octoparts-rb
|
115
146
|
licenses:
|
116
147
|
- MIT
|
@@ -135,4 +166,7 @@ rubygems_version: 2.2.2
|
|
135
166
|
signing_key:
|
136
167
|
specification_version: 4
|
137
168
|
summary: Ruby client for the Octoparts API
|
138
|
-
test_files:
|
169
|
+
test_files:
|
170
|
+
- test/helper.rb
|
171
|
+
- test/representer/test_aggregate_request_representer.rb
|
172
|
+
- test/test_octoparts.rb
|