octoparts 0.0.1 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d42d09094ee6564fcccf5f5035132b374768b03
4
- data.tar.gz: 099db10215310c2448487353074225512cb5a2d6
3
+ metadata.gz: 13fef2aab30cd287c94672a9bdc9ce0ab4b1edd4
4
+ data.tar.gz: 6c41cb1d2aa6883b9d66dbb48afc3b6440fcd7ab
5
5
  SHA512:
6
- metadata.gz: 3c7083fd105ff37da361a5faf7d954328d198314b28e6ea5fe373c280fa9a731834590073dd235cc92c70504ae3d8972606c6d569737135137fa521bc09868d5
7
- data.tar.gz: 4104053700d658bd4cd1bd238e746a49cb33a6da9dcbe6b2e168852031c32a0972de5e77bad9b62771a09005b143cc4ffc149c13cc9266c642aa3b12d500c0e1
6
+ metadata.gz: 4a55dcf838978766b8a5b048979369fa68671ce94968aaa35403c9bafe2caf586cd811f4a3edd085c68ea67e78713d1e243b1d34c272a9fba420b9baad72c353
7
+ data.tar.gz: 589fcf6a4364f88b6e7d53093d6aef59d59ef95cd32d5e063de00cb8fb5edde1c3edb7b34d517d5c4203a6b2aac1c8e956c151bf6fb15a3d5a0857ffebfac0ca
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Takayuki Matsubara
1
+ Copyright (c) 2014-2015 Takayuki Matsubara
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Octoparts
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
@@ -1,2 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.test_files = Dir["test/**/test_*.rb"]
7
+ end
8
+
9
+ task :default => :test
2
10
 
data/lib/octoparts.rb CHANGED
@@ -1,4 +1,3 @@
1
- require "json"
2
1
  require "faraday"
3
2
  require "octoparts/version"
4
3
  require "octoparts/configuration"
@@ -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
- body = params.to_json # TODO
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: :requestMeta, class: Model::RequestMeta do
19
+ property :request_meta, as: Camelizer.new('requestMeta'), class: Model::RequestMeta do
7
20
  property :id
8
- property :service_id, as: :serviceId
9
- property :user_id, as: :userId
10
- property :session_id, as: :sessionId
11
- property :request_url, as: :requestUrl
12
- property :user_agent, as: :userAgent
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: :partId
30
+ property :part_id, as: Camelizer.new('partId')
18
31
  property :id
19
32
  collection :params, class: Model::PartRequestParam do
20
33
  property :key
@@ -1,3 +1,3 @@
1
1
  module Octoparts
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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,5 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'octoparts'
3
+
4
+ require 'pry'
5
+ require 'test/unit'
@@ -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
@@ -0,0 +1,11 @@
1
+ require 'helper'
2
+
3
+ class TestOctoparts < Test::Unit::TestCase
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::Octoparts::VERSION
6
+ end
7
+
8
+ def test_it_does_something_useful
9
+ assert { ['exist'].empty? == false }
10
+ end
11
+ 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.1
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-04 00:00:00.000000000 Z
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