garoon-cat 0.1.0
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/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +161 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/garoon-cat +3 -0
- data/garoon-cat.gemspec +40 -0
- data/lib/garoon-cat.rb +50 -0
- data/lib/garoon-cat/action.rb +90 -0
- data/lib/garoon-cat/actions/cbpapi/base/get_organization_versions.rb +9 -0
- data/lib/garoon-cat/actions/util_api/util/login.rb +17 -0
- data/lib/garoon-cat/client.rb +22 -0
- data/lib/garoon-cat/request.rb +102 -0
- data/lib/garoon-cat/response.rb +20 -0
- data/lib/garoon-cat/service.rb +36 -0
- data/lib/garoon-cat/version.rb +3 -0
- metadata +289 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2107a2da18d258d280b764c658b1a3e05f6c16cc
|
4
|
+
data.tar.gz: 26c13124c552e9868c18184470a0e802b7c756e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bebe9d97523b032a8628a4ba8b82021baea717f85d3bbc44336967fa2d30451841b027455ed5bd790e23069386d6de4c03111684978f7cdb0b78bdd388c237a8
|
7
|
+
data.tar.gz: 9a192a7626fffa710902532307fb8746801014aa48afa485872d13d6ddef2f1274dcd8f3c84749a3c794d1c6ade49c058a41cd140dcc00da79841fd0fecd27ce
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Masayuki Higashino
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
# Garoon Cat: A ruby interface to the Garoon API
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'garoon-cat', git:'https://github.com/mh61503891/garoon-cat.git'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
bundle install
|
15
|
+
```
|
16
|
+
|
17
|
+
Example Code 1: WS-Security Authentication
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'garoon-cat'
|
21
|
+
|
22
|
+
garoon = GaroonCat.setup({
|
23
|
+
uri: ENV['URI'],
|
24
|
+
username: ENV['USERNAME'],
|
25
|
+
password: ENV['PASSWORD']
|
26
|
+
})
|
27
|
+
|
28
|
+
garoon.service(:base).get_user_versions()
|
29
|
+
```
|
30
|
+
|
31
|
+
Example Code 2: Cookie Authentication
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'garoon-cat'
|
35
|
+
|
36
|
+
garoon = GaroonCat.setup(uri:ENV['URI'])
|
37
|
+
|
38
|
+
garoon.service(:util).login({
|
39
|
+
login_name: ENV['USERNAME'],
|
40
|
+
password: ENV['PASSWORD']
|
41
|
+
})
|
42
|
+
garoon.service(:base).get_user_versions()
|
43
|
+
garoon.service(:util).logout
|
44
|
+
```
|
45
|
+
|
46
|
+
Example code 3: Dump information of organizations and users
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'garoon-cat'
|
50
|
+
require 'json'
|
51
|
+
|
52
|
+
@garoon = GaroonCat.setup({
|
53
|
+
uri: ENV['URI'],
|
54
|
+
username: ENV['USERNAME'],
|
55
|
+
password: ENV['PASSWORD']
|
56
|
+
})
|
57
|
+
@base = @garoon.service(:base)
|
58
|
+
|
59
|
+
def write_json(filename, object)
|
60
|
+
File.open(filename, 'wb') do |io|
|
61
|
+
io.write(JSON.pretty_generate(object))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def read_json(filename)
|
66
|
+
File.open(filename) do |io|
|
67
|
+
JSON.parse(io.read)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# dump org_versions.json
|
72
|
+
write_json('org_versions.json', @base.get_organization_versions())
|
73
|
+
|
74
|
+
# dump orgs.json
|
75
|
+
org_ids = read_json('org_versions.json')['organization_item'].map{ |e| e['id'] }
|
76
|
+
write_json('orgs.json', @base.get_organizations_by_id(organization_id:org_ids))
|
77
|
+
|
78
|
+
# dump user_versions.json
|
79
|
+
write_json('user_versions.json', @base.get_user_versions())
|
80
|
+
|
81
|
+
# dump users.json
|
82
|
+
user_ids = read_json('user_versions.json')['user_item'].map{ |e| e['id'] }
|
83
|
+
write_json('users.json', @base.get_users_by_id(user_id:user_ids))
|
84
|
+
```
|
85
|
+
|
86
|
+
Execution:
|
87
|
+
|
88
|
+
```bash
|
89
|
+
$ ls -1
|
90
|
+
Gemfile
|
91
|
+
dump.rb
|
92
|
+
|
93
|
+
$ cat Gemfile
|
94
|
+
gem 'garoon-cat', git:'https://github.com/mh61503891/garoon-cat.git'
|
95
|
+
|
96
|
+
$ bundle install
|
97
|
+
Using concurrent-ruby 1.0.4
|
98
|
+
Using i18n 0.7.0
|
99
|
+
Using minitest 5.10.1
|
100
|
+
Using thread_safe 0.3.5
|
101
|
+
Using unf_ext 0.0.7.2
|
102
|
+
Using httpclient 2.8.3
|
103
|
+
Using xml-simple 1.1.5
|
104
|
+
Using bundler 1.13.7
|
105
|
+
Using tzinfo 1.2.2
|
106
|
+
Using unf 0.1.4
|
107
|
+
Using activesupport 5.0.1
|
108
|
+
Using domain_name 0.5.20161129
|
109
|
+
Using http-cookie 1.0.3
|
110
|
+
Using garoon-cat 0.1.0 from https://github.com/mh61503891/garoon-cat.git (at master@5140f80)
|
111
|
+
Bundle complete! 1 Gemfile dependency, 14 gems now installed.
|
112
|
+
Use `bundle show [gemname]` to see where a bundled gem is installed.
|
113
|
+
|
114
|
+
URI=https://example.net/cgi-bin/cbgrn/grn.cgi USERNAME=username PASSWORD=password bundle exec ruby dump.rb
|
115
|
+
```
|
116
|
+
|
117
|
+
Result:
|
118
|
+
|
119
|
+
```bash
|
120
|
+
$ cat orgs.json | head
|
121
|
+
{
|
122
|
+
"organization": [
|
123
|
+
{
|
124
|
+
"key": "1",
|
125
|
+
"name": "Tottori Daraz Company",
|
126
|
+
"order": "1",
|
127
|
+
"version": "0000000000",
|
128
|
+
"organization": [
|
129
|
+
{
|
130
|
+
"key": "2",
|
131
|
+
```
|
132
|
+
|
133
|
+
## Development
|
134
|
+
|
135
|
+
### Test
|
136
|
+
|
137
|
+
```bash
|
138
|
+
export URI=https://example.net/cgi-bin/cbgrn/grn.cgi
|
139
|
+
export USERNAME=username
|
140
|
+
export PASSWORD=password
|
141
|
+
```
|
142
|
+
|
143
|
+
```bash
|
144
|
+
bundle exec rake test
|
145
|
+
```
|
146
|
+
|
147
|
+
```bash
|
148
|
+
$ bundle exec ruby -Itest test/garoon-cat_test.rb
|
149
|
+
```
|
150
|
+
|
151
|
+
```bash
|
152
|
+
$ bundle exec ruby -Itest test/garoon-cat_test.rb --name test_users
|
153
|
+
```
|
154
|
+
|
155
|
+
```bash
|
156
|
+
$ bundle exec guard
|
157
|
+
```
|
158
|
+
|
159
|
+
## License
|
160
|
+
|
161
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'garoon-cat'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/garoon-cat
ADDED
data/garoon-cat.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'garoon-cat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'garoon-cat'
|
8
|
+
spec.version = GaroonCat::VERSION
|
9
|
+
spec.authors = ['Masayuki Higashino']
|
10
|
+
spec.email = ['mh.on.web@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Garoon Cat: A Ruby interface to the Garoon API.}
|
13
|
+
spec.description = %q{Garoon Cat: A Ruby interface to the Garoon API.}
|
14
|
+
spec.homepage = 'https://github.com/mh61503891/garoon-cat'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'httpclient'
|
25
|
+
spec.add_dependency 'http-cookie'
|
26
|
+
spec.add_dependency 'activesupport'
|
27
|
+
spec.add_dependency 'xml-simple'
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
31
|
+
spec.add_development_dependency 'minitest-assert_errors'
|
32
|
+
spec.add_development_dependency 'minitest-nyan-cat'
|
33
|
+
spec.add_development_dependency 'webmock'
|
34
|
+
spec.add_development_dependency 'faker'
|
35
|
+
spec.add_development_dependency 'pry'
|
36
|
+
spec.add_development_dependency 'guard'
|
37
|
+
spec.add_development_dependency 'guard-minitest'
|
38
|
+
spec.add_development_dependency 'guard-yard'
|
39
|
+
spec.add_development_dependency 'awesome_print'
|
40
|
+
end
|
data/lib/garoon-cat.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'garoon-cat/version'
|
2
|
+
require 'garoon-cat/client'
|
3
|
+
require 'garoon-cat/service'
|
4
|
+
require 'rexml/document'
|
5
|
+
require 'active_support/core_ext/string/inflections'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
class GaroonCat
|
9
|
+
|
10
|
+
# @return [URI]
|
11
|
+
attr_reader :uri
|
12
|
+
|
13
|
+
# @return [Hash<Symbol => GaroonCat::Service>]
|
14
|
+
attr_reader :services
|
15
|
+
|
16
|
+
# @param uri [URI, String] URI to WSDL
|
17
|
+
# @param username [String] a username for WS-Security
|
18
|
+
# @param password [String] a password for WS-Security
|
19
|
+
# @return [GaroonCat]
|
20
|
+
def self.setup(uri:, username:nil, password:nil)
|
21
|
+
client = GaroonCat::Client.new(username:username, password:password)
|
22
|
+
uri = uri.kind_of?(URI) ? uri : URI.parse(uri.to_s)
|
23
|
+
services = {}
|
24
|
+
doc = REXML::Document.new(client.get(uri))
|
25
|
+
REXML::XPath.match(doc, '/definitions/service').each do |service|
|
26
|
+
name = service.attribute('name').value
|
27
|
+
key = name.camelize.sub(/Service$/, '').underscore.to_sym
|
28
|
+
location = URI.parse(service.elements['port/soap12:address'].attribute('location').value)
|
29
|
+
services[key] = GaroonCat::Service.new(client:client, name:name, uri:location)
|
30
|
+
end
|
31
|
+
new(client:client, uri:uri, services:services)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param client [GaroonCat::Client]
|
35
|
+
# @param uri [URI]
|
36
|
+
# @param services [Hash<Symbol => GaroonCat::Service>]
|
37
|
+
def initialize(client:, uri:, services:)
|
38
|
+
@client = client
|
39
|
+
@uri = uri
|
40
|
+
@services = services
|
41
|
+
end
|
42
|
+
private_class_method :new
|
43
|
+
|
44
|
+
# @param key [Symbol, String]
|
45
|
+
# @return [GaroonCat::Service]
|
46
|
+
def service(key)
|
47
|
+
@services[key]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
require 'garoon-cat/request'
|
3
|
+
require 'garoon-cat/response'
|
4
|
+
|
5
|
+
class GaroonCat::Action
|
6
|
+
|
7
|
+
# @param service [GaroonCat::Service]
|
8
|
+
# @param key [Symbol]
|
9
|
+
# @return [GaroonCat::Action]
|
10
|
+
def self.create(service:, key:)
|
11
|
+
segments = {
|
12
|
+
prefix:service.uri.path.split('/')[-3],
|
13
|
+
service:service.uri.path.split('/')[-2],
|
14
|
+
action:key.to_s,
|
15
|
+
}
|
16
|
+
require(class_path(segments))
|
17
|
+
class_name(segments).constantize.new(service:service, key:key)
|
18
|
+
rescue LoadError => e
|
19
|
+
$stderr.puts e if $DEBUG
|
20
|
+
$stderr.puts 'default fallback file -- garoon-cat/action' if $DEBUG
|
21
|
+
self.new(service:service, key:key)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param segments [Hash<Symbol => String>]
|
25
|
+
# @return [String] the path for require
|
26
|
+
def self.class_path(segments)
|
27
|
+
path = %w(garoon-cat actions)
|
28
|
+
path << segments[:prefix]
|
29
|
+
path << segments[:service]
|
30
|
+
path << segments[:action]
|
31
|
+
path.join('/')
|
32
|
+
end
|
33
|
+
private_class_method :class_path
|
34
|
+
|
35
|
+
# @param segments [Hash<Symbol => String>]
|
36
|
+
# @return [String] the class name
|
37
|
+
def self.class_name(segments)
|
38
|
+
name = %w(GaroonCat Actions)
|
39
|
+
name << segments[:prefix].upcase
|
40
|
+
name << segments[:service].upcase
|
41
|
+
name << segments[:action].camelcase
|
42
|
+
name.join('::')
|
43
|
+
end
|
44
|
+
private_class_method :class_name
|
45
|
+
|
46
|
+
# @param service [GaroonCat::Service]
|
47
|
+
# @param key [Symbol]
|
48
|
+
def initialize(service:, key:)
|
49
|
+
@service = service
|
50
|
+
@key = key
|
51
|
+
end
|
52
|
+
|
53
|
+
# @param *args [Object] arguments of this action
|
54
|
+
# @return [Object] return values of this action
|
55
|
+
def execute(*args)
|
56
|
+
request = GaroonCat::Request.new(default_params.merge({
|
57
|
+
body:{
|
58
|
+
parameters: args[0][0]
|
59
|
+
}
|
60
|
+
}))
|
61
|
+
request_body = request.to_s
|
62
|
+
response_body = @service.client.post(@service.uri, request_body)
|
63
|
+
response = GaroonCat::Response.new(response_body)
|
64
|
+
return response.to_params
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Hash] the default parameters of this service and its actions
|
68
|
+
def default_params
|
69
|
+
{
|
70
|
+
header: {
|
71
|
+
action: @service.name.sub(/Service$/, @key.to_s.camelize),
|
72
|
+
security: {
|
73
|
+
username_token: {
|
74
|
+
username: @service.client.username,
|
75
|
+
password: @service.client.password
|
76
|
+
}
|
77
|
+
},
|
78
|
+
timestamp: {
|
79
|
+
created: Time.now,
|
80
|
+
expires: Time.now,
|
81
|
+
},
|
82
|
+
locale: 'jp'
|
83
|
+
},
|
84
|
+
body: {
|
85
|
+
parameters: nil
|
86
|
+
}
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'garoon-cat/action'
|
2
|
+
|
3
|
+
class GaroonCat; class Actions; class UTIL_API; class UTIL
|
4
|
+
class Login < GaroonCat::Action
|
5
|
+
def execute(*args)
|
6
|
+
request = GaroonCat::Request.new(default_params.merge({
|
7
|
+
body:{
|
8
|
+
parameters: args[0][0]
|
9
|
+
}
|
10
|
+
}))
|
11
|
+
request_body = request.to_s
|
12
|
+
response_body = @service.client.post(@service.uri, request_body)
|
13
|
+
response = GaroonCat::Response.new(response_body)
|
14
|
+
return response.to_params
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end; end; end; end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'httpclient'
|
2
|
+
|
3
|
+
class GaroonCat::Client
|
4
|
+
|
5
|
+
attr_reader :username
|
6
|
+
attr_reader :password
|
7
|
+
|
8
|
+
def initialize(username:nil, password:nil)
|
9
|
+
@client = HTTPClient.new
|
10
|
+
@username = username
|
11
|
+
@password = password
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(uri)
|
15
|
+
@client.get_content(uri)
|
16
|
+
end
|
17
|
+
|
18
|
+
def post(uri, data)
|
19
|
+
@client.post_content(uri, data)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
class GaroonCat::Request
|
5
|
+
|
6
|
+
def initialize(params)
|
7
|
+
@params = params
|
8
|
+
end
|
9
|
+
|
10
|
+
def header_action
|
11
|
+
action = REXML::Element.new('Action')
|
12
|
+
action.add_text(@params.dig(:header, :action).to_s)
|
13
|
+
action
|
14
|
+
end
|
15
|
+
|
16
|
+
def header_security
|
17
|
+
security = REXML::Element.new('Security')
|
18
|
+
username = @params.dig(:header, :security, :username_token, :username)
|
19
|
+
password = @params.dig(:header, :security, :username_token, :password)
|
20
|
+
if username && password
|
21
|
+
username_token = REXML::Element.new('UsernameToken')
|
22
|
+
username_token.add_element('Username').add_text(username)
|
23
|
+
username_token.add_element('Password').add_text(password)
|
24
|
+
security.add_element(username_token)
|
25
|
+
end
|
26
|
+
security
|
27
|
+
end
|
28
|
+
|
29
|
+
def header_timestamp
|
30
|
+
timestamp = REXML::Element.new('Timestamp')
|
31
|
+
timestamp.add_element('Created').add_text(@params.dig(:header, :timestamp, :created).iso8601)
|
32
|
+
timestamp.add_element('Expires').add_text(@params.dig(:header, :timestamp, :expires).iso8601)
|
33
|
+
timestamp
|
34
|
+
end
|
35
|
+
|
36
|
+
def header_locale
|
37
|
+
locale = REXML::Element.new('locale')
|
38
|
+
locale.add_text(@params.dig(:header, :locale))
|
39
|
+
locale
|
40
|
+
end
|
41
|
+
|
42
|
+
def header
|
43
|
+
header = REXML::Element.new('soap:Header')
|
44
|
+
header.add_element(header_action)
|
45
|
+
header.add_element(header_security)
|
46
|
+
header.add_element(header_timestamp)
|
47
|
+
header.add_element(header_locale)
|
48
|
+
header
|
49
|
+
end
|
50
|
+
|
51
|
+
# @todo fix: handling parameters' type
|
52
|
+
def body_action_parameters
|
53
|
+
parameters = REXML::Element.new('parameters')
|
54
|
+
target = @params.dig(:body, :parameters)
|
55
|
+
case target
|
56
|
+
when Hash
|
57
|
+
target.each do |key, v1|
|
58
|
+
case v1
|
59
|
+
when String
|
60
|
+
parameters.add_element(key.to_s).add_text(v1.to_s)
|
61
|
+
when Array
|
62
|
+
v1.each do |v2|
|
63
|
+
parameters.add_element(key.to_s).add_text(v2.to_s)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
parameters
|
69
|
+
end
|
70
|
+
|
71
|
+
def body_action
|
72
|
+
action = REXML::Element.new(@params.dig(:header, :action).to_s)
|
73
|
+
action.add_element(body_action_parameters)
|
74
|
+
action
|
75
|
+
end
|
76
|
+
|
77
|
+
def body
|
78
|
+
body = REXML::Element.new('soap:Body')
|
79
|
+
body.add_element(body_action)
|
80
|
+
body
|
81
|
+
end
|
82
|
+
|
83
|
+
def envelope
|
84
|
+
envelope = REXML::Element.new('soap:Envelope')
|
85
|
+
envelope.add_namespace('soap', 'http://www.w3.org/2003/05/soap-envelope')
|
86
|
+
envelope.add_element(header)
|
87
|
+
envelope.add_element(body)
|
88
|
+
envelope
|
89
|
+
end
|
90
|
+
|
91
|
+
def doc
|
92
|
+
doc = REXML::Document.new
|
93
|
+
doc << REXML::XMLDecl.new('1.0', 'UTF-8')
|
94
|
+
doc.add_element(envelope)
|
95
|
+
doc
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_s
|
99
|
+
doc.to_s
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'xmlsimple'
|
3
|
+
|
4
|
+
class GaroonCat::Response
|
5
|
+
|
6
|
+
def initialize(source)
|
7
|
+
@source = source
|
8
|
+
@doc = REXML::Document.new(source)
|
9
|
+
if @doc.elements['//returns']
|
10
|
+
@params = XmlSimple.xml_in(@doc.elements['//returns'].to_s)
|
11
|
+
else
|
12
|
+
raise @doc.elements['/soap:Envelope/soap:Body/soap:Fault/soap:Detail/cause'].text.strip
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_params
|
17
|
+
@params
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'garoon-cat/action'
|
2
|
+
|
3
|
+
class GaroonCat::Service
|
4
|
+
|
5
|
+
# @return [GaroonCat::Client]
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
# @return [String]
|
9
|
+
attr_reader :name
|
10
|
+
|
11
|
+
# @return [URI]
|
12
|
+
attr_reader :uri
|
13
|
+
|
14
|
+
# @param client [GaroonCat::Client]
|
15
|
+
# @param name [String]
|
16
|
+
# @param uri [URI]
|
17
|
+
def initialize(client:, name:, uri:)
|
18
|
+
@client = client
|
19
|
+
@name = name
|
20
|
+
@uri = uri
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# @param key [Symbol] the key of an action.
|
26
|
+
# @return [GaroonCat::Action #execute]
|
27
|
+
def action(key)
|
28
|
+
@actions ||= {}
|
29
|
+
@actions[key] ||= GaroonCat::Action.create(service:self, key:key)
|
30
|
+
end
|
31
|
+
|
32
|
+
def method_missing(key, *args)
|
33
|
+
action(key).execute(args)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,289 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: garoon-cat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masayuki Higashino
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httpclient
|
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: http-cookie
|
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: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: xml-simple
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.13'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.13'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '5.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '5.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest-assert_errors
|
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: minitest-nyan-cat
|
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'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: webmock
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: faker
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: pry
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: guard
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: guard-minitest
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: guard-yard
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: awesome_print
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
description: 'Garoon Cat: A Ruby interface to the Garoon API.'
|
238
|
+
email:
|
239
|
+
- mh.on.web@gmail.com
|
240
|
+
executables:
|
241
|
+
- garoon-cat
|
242
|
+
extensions: []
|
243
|
+
extra_rdoc_files: []
|
244
|
+
files:
|
245
|
+
- ".gitignore"
|
246
|
+
- ".travis.yml"
|
247
|
+
- Gemfile
|
248
|
+
- Guardfile
|
249
|
+
- LICENSE.txt
|
250
|
+
- README.md
|
251
|
+
- Rakefile
|
252
|
+
- bin/console
|
253
|
+
- bin/setup
|
254
|
+
- exe/garoon-cat
|
255
|
+
- garoon-cat.gemspec
|
256
|
+
- lib/garoon-cat.rb
|
257
|
+
- lib/garoon-cat/action.rb
|
258
|
+
- lib/garoon-cat/actions/cbpapi/base/get_organization_versions.rb
|
259
|
+
- lib/garoon-cat/actions/util_api/util/login.rb
|
260
|
+
- lib/garoon-cat/client.rb
|
261
|
+
- lib/garoon-cat/request.rb
|
262
|
+
- lib/garoon-cat/response.rb
|
263
|
+
- lib/garoon-cat/service.rb
|
264
|
+
- lib/garoon-cat/version.rb
|
265
|
+
homepage: https://github.com/mh61503891/garoon-cat
|
266
|
+
licenses:
|
267
|
+
- MIT
|
268
|
+
metadata: {}
|
269
|
+
post_install_message:
|
270
|
+
rdoc_options: []
|
271
|
+
require_paths:
|
272
|
+
- lib
|
273
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
274
|
+
requirements:
|
275
|
+
- - ">="
|
276
|
+
- !ruby/object:Gem::Version
|
277
|
+
version: '0'
|
278
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
279
|
+
requirements:
|
280
|
+
- - ">="
|
281
|
+
- !ruby/object:Gem::Version
|
282
|
+
version: '0'
|
283
|
+
requirements: []
|
284
|
+
rubyforge_project:
|
285
|
+
rubygems_version: 2.5.2
|
286
|
+
signing_key:
|
287
|
+
specification_version: 4
|
288
|
+
summary: 'Garoon Cat: A Ruby interface to the Garoon API.'
|
289
|
+
test_files: []
|