octoparts 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/octoparts.rb +20 -0
- data/lib/octoparts/client.rb +72 -0
- data/lib/octoparts/configuration.rb +15 -0
- data/lib/octoparts/model.rb +9 -0
- data/lib/octoparts/model/aggregate_request.rb +7 -0
- data/lib/octoparts/model/aggregate_response.rb +7 -0
- data/lib/octoparts/model/cache_control.rb +8 -0
- data/lib/octoparts/model/cookie.rb +9 -0
- data/lib/octoparts/model/part_request.rb +7 -0
- data/lib/octoparts/model/part_request_param.rb +7 -0
- data/lib/octoparts/model/part_response.rb +10 -0
- data/lib/octoparts/model/request_meta.rb +8 -0
- data/lib/octoparts/model/response_meta.rb +7 -0
- data/lib/octoparts/representer.rb +4 -0
- data/lib/octoparts/representer/aggregate_request_representer.rb +26 -0
- data/lib/octoparts/representer/aggregate_response_representer.rb +41 -0
- data/lib/octoparts/response.rb +11 -0
- data/lib/octoparts/version.rb +3 -0
- data/octoparts.gemspec +27 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d42d09094ee6564fcccf5f5035132b374768b03
|
4
|
+
data.tar.gz: 099db10215310c2448487353074225512cb5a2d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c7083fd105ff37da361a5faf7d954328d198314b28e6ea5fe373c280fa9a731834590073dd235cc92c70504ae3d8972606c6d569737135137fa521bc09868d5
|
7
|
+
data.tar.gz: 4104053700d658bd4cd1bd238e746a49cb33a6da9dcbe6b2e168852031c32a0972de5e77bad9b62771a09005b143cc4ffc149c13cc9266c642aa3b12d500c0e1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Takayuki Matsubara
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Octoparts
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'octoparts'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install octoparts
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/octoparts/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/octoparts.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "json"
|
2
|
+
require "faraday"
|
3
|
+
require "octoparts/version"
|
4
|
+
require "octoparts/configuration"
|
5
|
+
require "octoparts/client"
|
6
|
+
require "octoparts/model"
|
7
|
+
require "octoparts/representer"
|
8
|
+
require "octoparts/response"
|
9
|
+
|
10
|
+
module Octoparts
|
11
|
+
class << self
|
12
|
+
def configuration
|
13
|
+
@configuration ||= Octoparts::Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure(&block)
|
17
|
+
configuration.instance_eval(&block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Octoparts
|
4
|
+
class Client
|
5
|
+
OCTOPARTS_API_ENDPOINT_PATH = '/octoparts/2'
|
6
|
+
CACHE_API_ENDPOINT_PATH = "#{OCTOPARTS_API_ENDPOINT_PATH}/cache"
|
7
|
+
|
8
|
+
def initialize(endpoint: nil, headers: {})
|
9
|
+
@endpoint = endpoint || Octoparts.configuration.endpoint
|
10
|
+
@headers = Octoparts.configuration.headers.merge(headers)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(path, params = nil, headers = {})
|
14
|
+
process(:get, path, params, headers)
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(path, params = nil, headers = {})
|
18
|
+
process(:post, path, params, headers)
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: doc
|
22
|
+
def invoke(params)
|
23
|
+
body = params.to_json # TODO
|
24
|
+
headers = { content_type: 'application/json' }
|
25
|
+
resp = post(OCTOPARTS_API_ENDPOINT_PATH, body, headers)
|
26
|
+
Response.new(
|
27
|
+
Model::AggregateResponse.new.extend(Representer::AggregateResponseRepresenter).from_json(resp.body),
|
28
|
+
resp.headers,
|
29
|
+
resp.status
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
# TODO: doc
|
34
|
+
def invalidate_cache(part_id, param_name: nil, param_value: nil)
|
35
|
+
cache_path = if param_name
|
36
|
+
"/invalidate/part/#{part_id}/#{param_name}/#{param_value}"
|
37
|
+
else
|
38
|
+
"/invalidate/part/#{part_id}"
|
39
|
+
end
|
40
|
+
post_cache_api(cache_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
# TODO: doc
|
44
|
+
def invalidate_cache_group(cache_group_name, param_value: nil)
|
45
|
+
cache_path = if param_value
|
46
|
+
"/invalidate/cache-group/#{cache_group_name}/params/#{param_value}"
|
47
|
+
else
|
48
|
+
"/invalidate/cache-group/#{cache_group_name}/parts"
|
49
|
+
end
|
50
|
+
post_cache_api(cache_path)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def post_cache_api(path)
|
56
|
+
escaped_path = URI.escape("#{CACHE_API_ENDPOINT_PATH}#{path}")
|
57
|
+
resp = post(escaped_path)
|
58
|
+
Response.new(
|
59
|
+
resp.body,
|
60
|
+
resp.headers,
|
61
|
+
resp.status
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
def process(method, path, params, headers)
|
66
|
+
@connection ||= Faraday.new(url: @endpoint) do |connection|
|
67
|
+
connection.adapter Faraday.default_adapter
|
68
|
+
end
|
69
|
+
@connection.send(method, path, params, @headers.merge(headers || {}))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Octoparts
|
2
|
+
class Configuration
|
3
|
+
USER_AGENT = "Octoparts client ruby/#{Octoparts::VERSION}"
|
4
|
+
|
5
|
+
attr_accessor :endpoint, :headers
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
# set default values
|
9
|
+
@endpoint = 'http://localhost:9000'
|
10
|
+
@headers = {
|
11
|
+
'User-Agent' => USER_AGENT
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "octoparts/model/request_meta"
|
2
|
+
require "octoparts/model/part_request_param"
|
3
|
+
require "octoparts/model/part_request"
|
4
|
+
require "octoparts/model/aggregate_request"
|
5
|
+
require "octoparts/model/cookie"
|
6
|
+
require "octoparts/model/cache_control"
|
7
|
+
require "octoparts/model/part_response"
|
8
|
+
require "octoparts/model/response_meta"
|
9
|
+
require "octoparts/model/aggregate_response"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Octoparts
|
2
|
+
module Representer
|
3
|
+
module AggregateRequestRepresenter
|
4
|
+
include Representable::JSON
|
5
|
+
|
6
|
+
property :request_meta, as: :requestMeta, class: Model::RequestMeta do
|
7
|
+
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
|
13
|
+
property :timeout
|
14
|
+
end
|
15
|
+
|
16
|
+
collection :requests, class: Model::PartRequest do
|
17
|
+
property :part_id, as: :partId
|
18
|
+
property :id
|
19
|
+
collection :params, class: Model::PartRequestParam do
|
20
|
+
property :key
|
21
|
+
property :value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Octoparts
|
2
|
+
module Representer
|
3
|
+
module AggregateResponseRepresenter
|
4
|
+
include Representable::JSON
|
5
|
+
|
6
|
+
property :response_meta, as: :responseMeta, class: Model::ResponseMeta do
|
7
|
+
property :id
|
8
|
+
property :process_time, as: :processTime
|
9
|
+
end
|
10
|
+
|
11
|
+
collection :responses, class: Model::PartResponse do
|
12
|
+
property :part_id, as: :partId
|
13
|
+
property :id
|
14
|
+
collection :cookies, class: Model::Cookie do
|
15
|
+
property :name
|
16
|
+
property :value
|
17
|
+
property :http_only, as: :httpOnly
|
18
|
+
property :secure
|
19
|
+
property :discard
|
20
|
+
property :max_age, as: :maxAge
|
21
|
+
property :path
|
22
|
+
property :domain
|
23
|
+
end
|
24
|
+
property :status_code, as: :statusCode
|
25
|
+
property :mime_type, as: :mimeType
|
26
|
+
property :charset
|
27
|
+
property :cache_control, as: :cacheControl, class: Model::CacheControl do
|
28
|
+
property :no_store, as: :noStore
|
29
|
+
property :no_cache, as: :noCache
|
30
|
+
property :expires_at, as: :expiresAt
|
31
|
+
property :etag
|
32
|
+
property :last_modified, as: :lastModified
|
33
|
+
end
|
34
|
+
property :contents
|
35
|
+
property :warnings
|
36
|
+
property :errors
|
37
|
+
property :retrieved_from_cache, as: :retrievedFromCache
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/octoparts.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'octoparts/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "octoparts"
|
8
|
+
spec.version = Octoparts::VERSION
|
9
|
+
spec.authors = ["Takayuki Matsubara"]
|
10
|
+
spec.email = ["takayuki.1229@gmail.com"]
|
11
|
+
spec.summary = %q{ Ruby client for the Octoparts API }
|
12
|
+
spec.description = %q{ Ruby client library for the Octoparts API }
|
13
|
+
spec.homepage = "https://github.com/ma2gedev/octoparts-rb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "representable"
|
22
|
+
spec.add_dependency "faraday"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: octoparts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takayuki Matsubara
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: representable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: " Ruby client library for the Octoparts API "
|
84
|
+
email:
|
85
|
+
- takayuki.1229@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/octoparts.rb
|
96
|
+
- lib/octoparts/client.rb
|
97
|
+
- lib/octoparts/configuration.rb
|
98
|
+
- lib/octoparts/model.rb
|
99
|
+
- lib/octoparts/model/aggregate_request.rb
|
100
|
+
- lib/octoparts/model/aggregate_response.rb
|
101
|
+
- lib/octoparts/model/cache_control.rb
|
102
|
+
- lib/octoparts/model/cookie.rb
|
103
|
+
- lib/octoparts/model/part_request.rb
|
104
|
+
- lib/octoparts/model/part_request_param.rb
|
105
|
+
- lib/octoparts/model/part_response.rb
|
106
|
+
- lib/octoparts/model/request_meta.rb
|
107
|
+
- lib/octoparts/model/response_meta.rb
|
108
|
+
- lib/octoparts/representer.rb
|
109
|
+
- lib/octoparts/representer/aggregate_request_representer.rb
|
110
|
+
- lib/octoparts/representer/aggregate_response_representer.rb
|
111
|
+
- lib/octoparts/response.rb
|
112
|
+
- lib/octoparts/version.rb
|
113
|
+
- octoparts.gemspec
|
114
|
+
homepage: https://github.com/ma2gedev/octoparts-rb
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.2.2
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Ruby client for the Octoparts API
|
138
|
+
test_files: []
|