akamai-core-client 0.0.2
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/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +82 -0
- data/Rakefile +6 -0
- data/akamai-core-client-ruby.gemspec +37 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/akamai/core/client.rb +23 -0
- data/lib/akamai/core/client/authority.rb +87 -0
- data/lib/akamai/core/client/client.rb +90 -0
- data/lib/akamai/core/client/error.rb +35 -0
- data/lib/akamai/core/client/response.rb +54 -0
- data/lib/akamai/core/client/version.rb +7 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 90661e56d46fe43694b6e0bad32137e5872e4cdd
|
4
|
+
data.tar.gz: 43b612ab2bce461c6ccbaa9789a655037915c3c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b280e973e2e11e7b3c7b5e0a7e8df510d058f76b2c5981078bd4e0351d1a8de565702e2fbd4cad6f9417aaa70c1f31982d26d8ad8b267825efaa875a285c591
|
7
|
+
data.tar.gz: '0978cfd26b119f330aa064d587494fdbd3f84659bcf614692951f73bc0830f793c49c8ef597a4959e40eb98d3e0692a1467652748700ae890207608eb31f3758'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at satsudai200411078@yahoo.co.jp. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Akito Ueno
|
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,82 @@
|
|
1
|
+
# Akamai::Core::Client::Ruby
|
2
|
+
This library provides fundamental functions to call Akamai API.
|
3
|
+
Using this library, you can easily request HTTP methods with akamai signature.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'akamai-core-client-ruby'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install akamai-core-client-ruby
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
You can initialize this cient following code.
|
23
|
+
```ruby
|
24
|
+
require "akamai/core/client"
|
25
|
+
client = Akamai::Core::Client.new(
|
26
|
+
client_secret: "xxxxxxx_secret",
|
27
|
+
host: "akab-host.luna.akamaiapis.net",
|
28
|
+
access_token: "akab-xxxxxxxxx",
|
29
|
+
client_token: "akab-xxxxxxxxx"
|
30
|
+
)
|
31
|
+
```
|
32
|
+
|
33
|
+
### HTTP GET
|
34
|
+
```ruby
|
35
|
+
response = client.get(
|
36
|
+
"/papi/v0/contracts/"
|
37
|
+
)
|
38
|
+
response.code # 200
|
39
|
+
response.headers # {"server"=>"Apache-Coyote/1.1", "content-language"=>"en-US", "etag"=>"\"xxxxxxxxxe440d81b1a171ca579b2597587\"", "vary"=>"Accept-Encoding", "content-type"=>"text/plain", "date"=>"Sat, 11 Nov 2017 13:39:20 GMT", "connection"=>"keep-alive"}
|
40
|
+
response.body["contracts"]["items"].each do |contract|
|
41
|
+
contract # {"contractId"=>"ctr_M-XXXXXX", "contractTypeName"=>"DIRECT_CUSTOMER"}
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
### HTTP POST
|
46
|
+
```ruby
|
47
|
+
body = {
|
48
|
+
"cpcodeName" => "SME WAA",
|
49
|
+
"productId" => "prd_Web_App_Accel"
|
50
|
+
}
|
51
|
+
client.post("/papi/v1/cpcodes?contractId=ctr_1–1TJZFW&groupId=grp_15166", body.to_json)
|
52
|
+
```
|
53
|
+
|
54
|
+
### HTTP PUT
|
55
|
+
```ruby
|
56
|
+
body = {
|
57
|
+
"ruleFormat" => "v2015-08-08",
|
58
|
+
"usePrefixes" => "true"
|
59
|
+
}
|
60
|
+
client.put("/papi/v1/client-settings", body.to_json)
|
61
|
+
```
|
62
|
+
|
63
|
+
### HTTP HEAD
|
64
|
+
```ruby
|
65
|
+
client.head("/papi/v1/properties/prp_175780/versions/3/rules?contractId=ctr_1–1TJZFW&groupId=grp_15166&validateRules=true&validateMode=fast&dryRun=true")
|
66
|
+
```
|
67
|
+
|
68
|
+
## Development
|
69
|
+
|
70
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
71
|
+
|
72
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/akamai-core-client-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
77
|
+
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
82
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "akamai/core/client/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "akamai-core-client"
|
8
|
+
spec.version = Akamai::Core::Client::VERSION
|
9
|
+
spec.authors = ["Akito Ueno"]
|
10
|
+
spec.email = ["satsudai200411078@yahoo.co.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{Akamai client}
|
13
|
+
spec.description = %q{Akamai client. This library provides fundamental function for calling akamai api.}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host"
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
spec.add_dependency "activesupport"
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "akamai/core/client/ruby"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext"
|
3
|
+
|
4
|
+
module Akamai
|
5
|
+
module Core
|
6
|
+
module Client
|
7
|
+
autoload :VERSION, "akamai/core/client/version"
|
8
|
+
autoload :Authority, "akamai/core/client/authority"
|
9
|
+
autoload :Client, "akamai/core/client/client"
|
10
|
+
autoload :Error, "akamai/core/client/error"
|
11
|
+
autoload :Response, "akamai/core/client/response"
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def new(host:, client_token:, access_token:, client_secret:, ssl: true)
|
15
|
+
Client.new(
|
16
|
+
host: host, client_token: client_token, access_token: access_token,
|
17
|
+
client_secret: client_secret, ssl: ssl
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "openssl"
|
2
|
+
require "securerandom"
|
3
|
+
|
4
|
+
module Akamai
|
5
|
+
module Core
|
6
|
+
module Client
|
7
|
+
class Authority
|
8
|
+
attr_reader :params, :client
|
9
|
+
def initialize(params)
|
10
|
+
@params = params.with_indifferent_access
|
11
|
+
@client = @params[:client]
|
12
|
+
end
|
13
|
+
|
14
|
+
def publish_authorization
|
15
|
+
authorization_seed + "signature=#{signature}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def signature
|
19
|
+
@signature ||= Base64.strict_encode64(
|
20
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), encryption_key, encryption_seed)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def authorization_seed
|
25
|
+
"EG1-HMAC-SHA256 " +
|
26
|
+
[].tap do |arr|
|
27
|
+
%w(client_token access_token).each do |k|
|
28
|
+
arr << "#{k}=#{client.send(k)}"
|
29
|
+
end
|
30
|
+
%w(timestamp nonce).each do |k|
|
31
|
+
arr << "#{k}=#{send(k)}"
|
32
|
+
end
|
33
|
+
end.join(";") + ";"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def encryption_key
|
39
|
+
Base64.strict_encode64(
|
40
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), client.client_secret, timestamp)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def encryption_seed
|
45
|
+
[].tap do |arr|
|
46
|
+
%w(method protocol host path).each do |k|
|
47
|
+
arr << params[k]
|
48
|
+
end
|
49
|
+
# Although Akamai's document tell us to use header informations in creating signature, "
|
50
|
+
# Probably Akamai use header informations to authenticate api request #
|
51
|
+
# For now I set blank. #
|
52
|
+
arr << ""
|
53
|
+
arr << body_hash
|
54
|
+
arr << authorization_seed
|
55
|
+
end.join("\t")
|
56
|
+
end
|
57
|
+
|
58
|
+
def body_hash
|
59
|
+
return "" unless params[:body]
|
60
|
+
Base64.strict_encode64(
|
61
|
+
OpenSSL::Digest.new("sha256").digest(params[:body])
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
def nonce
|
66
|
+
@nonce ||=
|
67
|
+
(params[:nonce] || SecureRandom.uuid)
|
68
|
+
end
|
69
|
+
|
70
|
+
def timestamp
|
71
|
+
@timestamp ||=
|
72
|
+
(params[:timestamp] || Time.now.utc.strftime("%Y%m%dT%H:%M:%S%z"))
|
73
|
+
end
|
74
|
+
|
75
|
+
def canonicalized_headers
|
76
|
+
return "" unless params[:headers]
|
77
|
+
sorted_headers = Hash[params[:headers].sort]
|
78
|
+
[].tap do |arr|
|
79
|
+
sorted_headers.each do |k, v|
|
80
|
+
arr << (k.downcase + ":" + v.to_s.gsub(/\s{2,}/, " "))
|
81
|
+
end
|
82
|
+
end.join("\t")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
module Akamai
|
4
|
+
module Core
|
5
|
+
module Client
|
6
|
+
class Client
|
7
|
+
attr_reader :host, :client_token, :access_token, :client_secret, :ssl
|
8
|
+
def initialize(host:, client_token:, access_token:, client_secret:, ssl: true)
|
9
|
+
@host = host
|
10
|
+
@client_token = client_token
|
11
|
+
@access_token = access_token
|
12
|
+
@client_secret = client_secret
|
13
|
+
@ssl = ssl
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(path, headers = nil)
|
17
|
+
request("get", path, nil, headers)
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(path, body = nil, headers = nil)
|
21
|
+
request("post", path, body, headers)
|
22
|
+
end
|
23
|
+
|
24
|
+
def put(path, body = nil, headers = nil)
|
25
|
+
request("put", path, body, headers)
|
26
|
+
end
|
27
|
+
|
28
|
+
def patch(path, body = nil, headers = nil)
|
29
|
+
request("patch", path, body, headers)
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete(path, headers = nil)
|
33
|
+
request("delete", path, nil, headers)
|
34
|
+
end
|
35
|
+
|
36
|
+
def head(path, headers = nil)
|
37
|
+
request("head", path, nil, headers)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def request(method, path, body = nil, optional_headers = nil)
|
43
|
+
response = Response.new(
|
44
|
+
"".tap do |raw_response|
|
45
|
+
http_client.start do |session|
|
46
|
+
headers = {
|
47
|
+
"Authorization" => authorization(method, path, body,
|
48
|
+
optional_headers),
|
49
|
+
"Content-Type" => "application/json"
|
50
|
+
}.merge(optional_headers ? optional_headers : {})
|
51
|
+
raw_response = if /^get$|^delete$|^head$/ =~ method
|
52
|
+
session.send(method, path, headers)
|
53
|
+
else
|
54
|
+
session.send(method, path, body, headers)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
break raw_response
|
58
|
+
end
|
59
|
+
)
|
60
|
+
|
61
|
+
Error.new(response.body).tap do |error|
|
62
|
+
error.raise_error if error.exist?
|
63
|
+
end
|
64
|
+
response
|
65
|
+
end
|
66
|
+
|
67
|
+
def http_client
|
68
|
+
@http_client ||= Net::HTTP.new(uri.host, uri.port).tap do |http|
|
69
|
+
http.use_ssl = !!ssl
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def protocol
|
74
|
+
ssl ? "https" : "http"
|
75
|
+
end
|
76
|
+
|
77
|
+
def authorization(method, path, body = nil, headers = nil)
|
78
|
+
Authority.new(
|
79
|
+
client: self, method: method.upcase, protocol: protocol,
|
80
|
+
host: host, path: path, body: body, headers: headers
|
81
|
+
).publish_authorization
|
82
|
+
end
|
83
|
+
|
84
|
+
def uri
|
85
|
+
@uri ||= URI("#{protocol}://#{host}")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Akamai
|
2
|
+
module Core
|
3
|
+
module Client
|
4
|
+
class Error
|
5
|
+
AkamaiError = Class.new(StandardError)
|
6
|
+
attr_reader :body
|
7
|
+
def initialize(body)
|
8
|
+
@body = /Array/ =~ body.class.name ? body[0] : body
|
9
|
+
end
|
10
|
+
|
11
|
+
def exist?
|
12
|
+
!!message
|
13
|
+
end
|
14
|
+
|
15
|
+
def raise_error
|
16
|
+
raise(AkamaiError, message) if exist?
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def message
|
22
|
+
@message ||=
|
23
|
+
case body.class.name
|
24
|
+
when /Hash/
|
25
|
+
if body[:errorString]
|
26
|
+
body[:errorString]
|
27
|
+
elsif body[:status] && /^4\d{2}|^5\d{2}/ =~ body[:status].to_s
|
28
|
+
body[:detail]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Akamai
|
2
|
+
module Core
|
3
|
+
module Client
|
4
|
+
class Response
|
5
|
+
attr_reader :http_response
|
6
|
+
def initialize(http_response)
|
7
|
+
@http_response = http_response
|
8
|
+
end
|
9
|
+
|
10
|
+
def body
|
11
|
+
@body ||= if http_response.body
|
12
|
+
JSON.parse(http_response.body).tap do |parsed_body|
|
13
|
+
result =
|
14
|
+
if /^Array$/ =~ parsed_body.class.name
|
15
|
+
[].tap do |arr|
|
16
|
+
parsed_body.each do |data|
|
17
|
+
arr << transform_data(data)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
else
|
21
|
+
transform_data(parsed_body)
|
22
|
+
end
|
23
|
+
break result
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def code
|
29
|
+
http_response.code.to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def headers
|
33
|
+
@headers ||=
|
34
|
+
{}.tap do |hash|
|
35
|
+
http_response.header.each do |k, v|
|
36
|
+
hash[k] = v
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def body_object
|
44
|
+
JSON.parse(http_response.body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def transform_data(data)
|
48
|
+
return data.with_indifferent_access if /Hash/ =~ data.class.name
|
49
|
+
data
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: akamai-core-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Akito Ueno
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Akamai client. This library provides fundamental function for calling
|
70
|
+
akamai api.
|
71
|
+
email:
|
72
|
+
- satsudai200411078@yahoo.co.jp
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CODE_OF_CONDUCT.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- akamai-core-client-ruby.gemspec
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- lib/akamai/core/client.rb
|
89
|
+
- lib/akamai/core/client/authority.rb
|
90
|
+
- lib/akamai/core/client/client.rb
|
91
|
+
- lib/akamai/core/client/error.rb
|
92
|
+
- lib/akamai/core/client/response.rb
|
93
|
+
- lib/akamai/core/client/version.rb
|
94
|
+
homepage: ''
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata:
|
98
|
+
allowed_push_host: https://rubygems.org
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.6.13
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Akamai client
|
119
|
+
test_files: []
|