niftycloud 0.0.1
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 +22 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/README.md +15 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/niftycloud.rb +36 -0
- data/lib/niftycloud/api.rb +15 -0
- data/lib/niftycloud/client.rb +28 -0
- data/lib/niftycloud/client/hoge.rb +7 -0
- data/lib/niftycloud/client/issues.rb +49 -0
- data/lib/niftycloud/configuration.rb +32 -0
- data/lib/niftycloud/error.rb +86 -0
- data/lib/niftycloud/objectified_hash.rb +29 -0
- data/lib/niftycloud/page_links.rb +30 -0
- data/lib/niftycloud/paginated_response.rb +96 -0
- data/lib/niftycloud/request.rb +134 -0
- data/lib/niftycloud/signature.rb +11 -0
- data/lib/niftycloud/version.rb +3 -0
- data/niftycloud.gemspec +33 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e71cd33c0db11a8080d0fabe9a8b12d7292568a
|
4
|
+
data.tar.gz: 3b85c4ba89965836ff96a3f75dbf78cc9eb1938b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e60b1f9edb8fc579623345dfde73c3300ef50c00c200b5e43eeb10e045e0b499573b7ec5d60c3c2bd92613812b1d88a097729d21f9961669ee1dd94a83a264d2
|
7
|
+
data.tar.gz: 721049e98c60c695f95dfa552e525db99838e170a487f7afcc3bc1ef67237f4ba26efb59e87e5d52d60bde549bf95ab886ac0c90b7fbb91c65e85baf1b1769c8
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
# rspec failure tracking
|
12
|
+
.rspec_status
|
13
|
+
|
14
|
+
.vscode/
|
15
|
+
.DS_Store
|
16
|
+
|
17
|
+
*.gem
|
18
|
+
*.rbc
|
19
|
+
*.swp
|
20
|
+
.bundle
|
21
|
+
.config
|
22
|
+
.yardoc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Unofficial NIFTY Cloud SDK for Ruby
|
2
|
+
|
3
|
+
## 概要
|
4
|
+
ニフティクラウド(IaaS)から提供されているAPIを利用し、サーバー作成等の操作を可能にするSDKです。
|
5
|
+
|
6
|
+
## インストール
|
7
|
+
```
|
8
|
+
gem install niftycloud
|
9
|
+
```
|
10
|
+
|
11
|
+
## 使い方
|
12
|
+
```
|
13
|
+
$ export NIFTYCLOUD_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXX
|
14
|
+
$ export NIFTYCLOUD_SECRET_ACCESS_KEY=YYYYYYYYYYYYYYYYYYY
|
15
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "niftycloud"
|
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
data/lib/niftycloud.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'niftycloud/version'
|
2
|
+
require 'niftycloud/page_links'
|
3
|
+
require 'niftycloud/objectified_hash'
|
4
|
+
require 'niftycloud/paginated_response'
|
5
|
+
require 'niftycloud/error'
|
6
|
+
require 'niftycloud/signature'
|
7
|
+
require 'niftycloud/configuration'
|
8
|
+
require 'niftycloud/request'
|
9
|
+
require 'niftycloud/api'
|
10
|
+
require 'niftycloud/client'
|
11
|
+
|
12
|
+
module Niftycloud
|
13
|
+
extend Configuration
|
14
|
+
|
15
|
+
def self.client(options={})
|
16
|
+
Niftycloud::Client.new(options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.method_missing(method, *args, &block)
|
20
|
+
return super unless client.respond_to?(method)
|
21
|
+
client.send(method, *args, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def respond_to_missing?(method_name, include_private = false)
|
25
|
+
client.respond_to?(method_name) || super
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.http_proxy(address=nil, port=nil, username=nil, password=nil)
|
29
|
+
Niftycloud::Request.http_proxy(address, port, username, password)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.actions
|
33
|
+
hidden = /endpoint|secret_access_key|auth_token|user_agent|sudo|get|post|put|\Adelete\z|validate|set_request_defaults|httparty/
|
34
|
+
(Niftycloud::Client.instance_methods - Object.methods).reject { |e| e[hidden] }
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Niftycloud
|
2
|
+
class API < Request
|
3
|
+
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
4
|
+
|
5
|
+
alias_method :auth_token=, :secret_access_key=
|
6
|
+
|
7
|
+
def initialize(options={})
|
8
|
+
options = Niftycloud.options.merge(options)
|
9
|
+
(Configuration::VALID_OPTIONS_KEYS + [:secret_access_key]).each do |key|
|
10
|
+
send("#{key}=", options[key]) if options[key]
|
11
|
+
end
|
12
|
+
set_request_defaults(@sudo)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Niftycloud
|
2
|
+
class Client < API
|
3
|
+
Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
|
4
|
+
|
5
|
+
include Instances
|
6
|
+
include Issues
|
7
|
+
|
8
|
+
def url_encode(s)
|
9
|
+
ERB::Util.url_encode(s)
|
10
|
+
end
|
11
|
+
|
12
|
+
def inspect
|
13
|
+
inspected = super
|
14
|
+
|
15
|
+
if @secret_access_key
|
16
|
+
inspected = inspected.sub! @secret_access_key, only_show_last_four_chars(@secret_access_key)
|
17
|
+
end
|
18
|
+
|
19
|
+
inspected
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def only_show_last_four_chars(key)
|
25
|
+
"#{'*'*(key.size - 4)}#{key[-4..-1]}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Niftycloud::Client
|
2
|
+
module Issues
|
3
|
+
|
4
|
+
def issues(project=nil, options={})
|
5
|
+
if project.to_s.empty? && project.to_i.zero?
|
6
|
+
get("/issues", query: options)
|
7
|
+
else
|
8
|
+
get("/projects/#{url_encode project}/issues", query: options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def issue(project, id)
|
13
|
+
get("/projects/#{url_encode project}/issues/#{id}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_issue(project, title, options={})
|
17
|
+
body = { title: title }.merge(options)
|
18
|
+
post("/projects/#{url_encode project}/issues", body: body)
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit_issue(project, id, options={})
|
22
|
+
put("/projects/#{url_encode project}/issues/#{id}", body: options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def close_issue(project, id)
|
26
|
+
put("/projects/#{url_encode project}/issues/#{id}", body: { state_event: 'close' })
|
27
|
+
end
|
28
|
+
|
29
|
+
def reopen_issue(project, id)
|
30
|
+
put("/projects/#{url_encode project}/issues/#{id}", body: { state_event: 'reopen' })
|
31
|
+
end
|
32
|
+
|
33
|
+
def subscribe_to_issue(project, id)
|
34
|
+
post("/projects/#{url_encode project}/issues/#{id}/subscribe")
|
35
|
+
end
|
36
|
+
|
37
|
+
def unsubscribe_from_issue(project, id)
|
38
|
+
post("/projects/#{url_encode project}/issues/#{id}/unsubscribe")
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_issue(project, id)
|
42
|
+
delete("/projects/#{url_encode project}/issues/#{id}")
|
43
|
+
end
|
44
|
+
|
45
|
+
def move_issue(project, id, options={})
|
46
|
+
post("/projects/#{url_encode project}/issues/#{id}/move", body: options)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Niftycloud
|
2
|
+
module Configuration
|
3
|
+
VALID_OPTIONS_KEYS = [:endpoint, :secret_access_key, :user_agent, :sudo, :httparty].freeze
|
4
|
+
DEFAULT_USER_AGENT = "Niftycloud Ruby Gem #{Niftycloud::VERSION}".freeze
|
5
|
+
# @private
|
6
|
+
attr_accessor(*VALID_OPTIONS_KEYS)
|
7
|
+
|
8
|
+
alias_method :auth_token=, :secret_access_key=
|
9
|
+
|
10
|
+
def self.extended(base)
|
11
|
+
base.reset
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure
|
15
|
+
yield self
|
16
|
+
end
|
17
|
+
|
18
|
+
def options
|
19
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
20
|
+
option.merge!(key => send(key))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def reset
|
25
|
+
self.endpoint = ENV['NIFTYCLOUD_API_ENDPOINT']
|
26
|
+
self.secret_access_key = ENV['NIFTYCLOUD_API_SECRET_ACCESS_KEY'] || ENV['NIFTYCLOUD_API_AUTH_TOKEN']
|
27
|
+
self.httparty = nil
|
28
|
+
self.sudo = nil
|
29
|
+
self.user_agent = DEFAULT_USER_AGENT
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Niftycloud
|
2
|
+
module Error
|
3
|
+
# Custom error class for rescuing from all errors.
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
# Raised when API endpoint credentials not configured.
|
7
|
+
class MissingCredentials < Error; end
|
8
|
+
|
9
|
+
# Raised when impossible to parse response body.
|
10
|
+
class Parsing < Error; end
|
11
|
+
|
12
|
+
# Custom error class for rescuing from HTTP response errors.
|
13
|
+
class ResponseError < Error
|
14
|
+
def initialize(response)
|
15
|
+
@response = response
|
16
|
+
super(build_error_message)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Status code returned in the http response.
|
20
|
+
#
|
21
|
+
# @return [Integer]
|
22
|
+
def response_status
|
23
|
+
@response.code
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Human friendly message.
|
29
|
+
#
|
30
|
+
# @return [String]
|
31
|
+
def build_error_message
|
32
|
+
parsed_response = @response.parsed_response
|
33
|
+
message = parsed_response.message || parsed_response.error if parsed_response != false
|
34
|
+
message = "false" if parsed_response == false
|
35
|
+
|
36
|
+
"Server responded with code #{@response.code}, message: " \
|
37
|
+
"#{handle_message(message)}. " \
|
38
|
+
"Request URI: #{@response.request.base_uri}#{@response.request.path}"
|
39
|
+
end
|
40
|
+
|
41
|
+
# Handle error response message in case of nested hashes
|
42
|
+
def handle_message(message)
|
43
|
+
case message
|
44
|
+
#when Niftycloud::ObjectifiedHash
|
45
|
+
# message.to_h.sort.map do |key, val|
|
46
|
+
# "'#{key}' #{(val.is_a?(Hash) ? val.sort.map { |k, v| "(#{k}: #{v.join(' ')})" } : val).join(' ')}"
|
47
|
+
# end.join(', ')
|
48
|
+
when Array
|
49
|
+
message.join(' ')
|
50
|
+
else
|
51
|
+
message
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Raised when API endpoint returns the HTTP status code 400.
|
57
|
+
class BadRequest < ResponseError; end
|
58
|
+
|
59
|
+
# Raised when API endpoint returns the HTTP status code 401.
|
60
|
+
class Unauthorized < ResponseError; end
|
61
|
+
|
62
|
+
# Raised when API endpoint returns the HTTP status code 403.
|
63
|
+
class Forbidden < ResponseError; end
|
64
|
+
|
65
|
+
# Raised when API endpoint returns the HTTP status code 404.
|
66
|
+
class NotFound < ResponseError; end
|
67
|
+
|
68
|
+
# Raised when API endpoint returns the HTTP status code 405.
|
69
|
+
class MethodNotAllowed < ResponseError; end
|
70
|
+
|
71
|
+
# Raised when API endpoint returns the HTTP status code 409.
|
72
|
+
class Conflict < ResponseError; end
|
73
|
+
|
74
|
+
# Raised when API endpoint returns the HTTP status code 422.
|
75
|
+
class Unprocessable < ResponseError; end
|
76
|
+
|
77
|
+
# Raised when API endpoint returns the HTTP status code 500.
|
78
|
+
class InternalServerError < ResponseError; end
|
79
|
+
|
80
|
+
# Raised when API endpoint returns the HTTP status code 502.
|
81
|
+
class BadGateway < ResponseError; end
|
82
|
+
|
83
|
+
# Raised when API endpoint returns the HTTP status code 503.
|
84
|
+
class ServiceUnavailable < ResponseError; end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Niftycloud
|
2
|
+
class ObjectifiedHash
|
3
|
+
def initialize(hash)
|
4
|
+
@hash = hash
|
5
|
+
@data = hash.inject({}) do |data, (key, value)|
|
6
|
+
value = ObjectifiedHash.new(value) if value.is_a? Hash
|
7
|
+
data[key.to_s] = value
|
8
|
+
data
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_hash
|
13
|
+
@hash
|
14
|
+
end
|
15
|
+
alias_method :to_h, :to_hash
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
"#<#{self.class}:#{object_id} {hash: #{@hash.inspect}}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(key)
|
22
|
+
@data.key?(key.to_s) ? @data[key.to_s] : nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def respond_to_missing?(method_name, include_private = false)
|
26
|
+
@hash.keys.map(&:to_sym).include?(method_name.to_sym) || super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Niftycloud
|
2
|
+
class PageLinks
|
3
|
+
HEADER_LINK = 'Link'.freeze
|
4
|
+
DELIM_LINKS = ','.freeze
|
5
|
+
LINK_REGEX = /<([^>]+)>; rel=\"([^\"]+)\"/
|
6
|
+
METAS = %w(last next first prev)
|
7
|
+
|
8
|
+
attr_accessor(*METAS)
|
9
|
+
|
10
|
+
def initialize(headers)
|
11
|
+
link_header = headers[HEADER_LINK]
|
12
|
+
|
13
|
+
if link_header && link_header =~ /(next|first|last|prev)/
|
14
|
+
extract_links(link_header)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def extract_links(header)
|
21
|
+
header.split(DELIM_LINKS).each do |link|
|
22
|
+
LINK_REGEX.match(link.strip) do |match|
|
23
|
+
url, meta = match[1], match[2]
|
24
|
+
next if !url || !meta || METAS.index(meta).nil?
|
25
|
+
self.send("#{meta}=", url)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Niftycloud
|
2
|
+
class PaginatedResponse
|
3
|
+
attr_accessor :client
|
4
|
+
|
5
|
+
def initialize(array)
|
6
|
+
@array = array
|
7
|
+
end
|
8
|
+
|
9
|
+
def ==(other)
|
10
|
+
@array == other
|
11
|
+
end
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
@array.inspect
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(name, *args, &block)
|
18
|
+
if @array.respond_to?(name)
|
19
|
+
@array.send(name, *args, &block)
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def respond_to_missing?(method_name, include_private = false)
|
26
|
+
super || @array.respond_to?(method_name, include_private)
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_headers!(headers)
|
30
|
+
@links = PageLinks.new headers
|
31
|
+
end
|
32
|
+
|
33
|
+
def each_page
|
34
|
+
current = self
|
35
|
+
yield current
|
36
|
+
while current.has_next_page?
|
37
|
+
current = current.next_page
|
38
|
+
yield current
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def auto_paginate
|
43
|
+
response = block_given? ? nil : []
|
44
|
+
each_page do |page|
|
45
|
+
if block_given?
|
46
|
+
page.each do |item|
|
47
|
+
yield item
|
48
|
+
end
|
49
|
+
else
|
50
|
+
response += page
|
51
|
+
end
|
52
|
+
end
|
53
|
+
response
|
54
|
+
end
|
55
|
+
|
56
|
+
def has_last_page?
|
57
|
+
!(@links.nil? || @links.last.nil?)
|
58
|
+
end
|
59
|
+
|
60
|
+
def last_page
|
61
|
+
return nil if @client.nil? || !has_last_page?
|
62
|
+
path = @links.last.sub(/#{@client.endpoint}/, '')
|
63
|
+
@client.get(path)
|
64
|
+
end
|
65
|
+
|
66
|
+
def has_first_page?
|
67
|
+
!(@links.nil? || @links.first.nil?)
|
68
|
+
end
|
69
|
+
|
70
|
+
def first_page
|
71
|
+
return nil if @client.nil? || !has_first_page?
|
72
|
+
path = @links.first.sub(/#{@client.endpoint}/, '')
|
73
|
+
@client.get(path)
|
74
|
+
end
|
75
|
+
|
76
|
+
def has_next_page?
|
77
|
+
!(@links.nil? || @links.next.nil?)
|
78
|
+
end
|
79
|
+
|
80
|
+
def next_page
|
81
|
+
return nil if @client.nil? || !has_next_page?
|
82
|
+
path = @links.next.sub(/#{@client.endpoint}/, '')
|
83
|
+
@client.get(path)
|
84
|
+
end
|
85
|
+
|
86
|
+
def has_prev_page?
|
87
|
+
!(@links.nil? || @links.prev.nil?)
|
88
|
+
end
|
89
|
+
|
90
|
+
def prev_page
|
91
|
+
return nil if @client.nil? || !has_prev_page?
|
92
|
+
path = @links.prev.sub(/#{@client.endpoint}/, '')
|
93
|
+
@client.get(path)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'rexml/document'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Niftycloud
|
6
|
+
class Request
|
7
|
+
include HTTParty
|
8
|
+
format :json
|
9
|
+
headers 'Accept' => 'application/json'
|
10
|
+
parser proc { |body, _| parse(body) }
|
11
|
+
|
12
|
+
attr_accessor :secret_access_key, :endpoint
|
13
|
+
|
14
|
+
def self.parse(body)
|
15
|
+
body = REXML::Document.new(body).root.to_h["reservationSet"]
|
16
|
+
|
17
|
+
if body.is_a? Hash
|
18
|
+
ObjectifiedHash.new body
|
19
|
+
elsif body.is_a? Array
|
20
|
+
PaginatedResponse.new(body.collect! { |e| ObjectifiedHash.new(e) })
|
21
|
+
elsif body
|
22
|
+
body
|
23
|
+
elsif !body
|
24
|
+
false
|
25
|
+
elsif body.nil?
|
26
|
+
false
|
27
|
+
else
|
28
|
+
raise Error::Parsing.new "Couldn't parse a response body"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.decode(response)
|
33
|
+
p response
|
34
|
+
JSON.load response
|
35
|
+
rescue JSON::ParserError
|
36
|
+
raise Error::Parsing.new "The response is not a valid JSON"
|
37
|
+
end
|
38
|
+
|
39
|
+
def get(path, options={})
|
40
|
+
set_httparty_config(options)
|
41
|
+
set_authorization_header(options)
|
42
|
+
validate self.class.get(@endpoint + path, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def post(path, options={})
|
46
|
+
set_httparty_config(options)
|
47
|
+
set_authorization_header(options)
|
48
|
+
validate self.class.post(@endpoint + path, options)
|
49
|
+
end
|
50
|
+
|
51
|
+
def put(path, options={})
|
52
|
+
set_httparty_config(options)
|
53
|
+
set_authorization_header(options)
|
54
|
+
validate self.class.put(@endpoint + path, options)
|
55
|
+
end
|
56
|
+
|
57
|
+
def delete(path, options={})
|
58
|
+
set_httparty_config(options)
|
59
|
+
set_authorization_header(options)
|
60
|
+
validate self.class.delete(@endpoint + path, options)
|
61
|
+
end
|
62
|
+
|
63
|
+
def validate(response)
|
64
|
+
error_klass = case response.code
|
65
|
+
when 400 then Error::BadRequest
|
66
|
+
when 401 then Error::Unauthorized
|
67
|
+
when 403 then Error::Forbidden
|
68
|
+
when 404 then Error::NotFound
|
69
|
+
when 405 then Error::MethodNotAllowed
|
70
|
+
when 409 then Error::Conflict
|
71
|
+
when 422 then Error::Unprocessable
|
72
|
+
when 500 then Error::InternalServerError
|
73
|
+
when 502 then Error::BadGateway
|
74
|
+
when 503 then Error::ServiceUnavailable
|
75
|
+
end
|
76
|
+
|
77
|
+
fail error_klass.new(response) if error_klass
|
78
|
+
|
79
|
+
parsed = response.parsed_response
|
80
|
+
parsed.client = self if parsed.respond_to?(:client=)
|
81
|
+
parsed.parse_headers!(response.headers) if parsed.respond_to?(:parse_headers!)
|
82
|
+
parsed
|
83
|
+
end
|
84
|
+
|
85
|
+
def set_request_defaults(sudo=nil)
|
86
|
+
self.class.default_params sudo: sudo
|
87
|
+
raise Error::MissingCredentials.new("Please set an endpoint to API") unless @endpoint
|
88
|
+
self.class.default_params.delete(:sudo) if sudo.nil?
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def set_authorization_header(options)
|
94
|
+
unless options[:unauthenticated]
|
95
|
+
raise Error::MissingCredentials.new("Please provide a secret_access_key or auth_token for user") unless @secret_access_key
|
96
|
+
if @secret_access_key.length <= 20
|
97
|
+
options[:headers] = { 'SECRET_ACCESS_KEY' => @secret_access_key }
|
98
|
+
else
|
99
|
+
options[:headers] = { 'Authorization' => "Bearer #{@secret_access_key}" }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def set_httparty_config(options)
|
105
|
+
options.merge!(httparty) if httparty
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class REXML::Element
|
112
|
+
def to_h
|
113
|
+
hash = {}
|
114
|
+
if self.has_elements?
|
115
|
+
self.elements.each do |e|
|
116
|
+
if e.has_elements?
|
117
|
+
if hash[e.name].nil?
|
118
|
+
hash[e.name] = e.to_h
|
119
|
+
elsif hash[e.name].is_a?(Array)
|
120
|
+
hash[e.name].push( e.to_h )
|
121
|
+
else
|
122
|
+
hash[e.name] = [ hash[e.name] ]
|
123
|
+
hash[e.name].push( e.to_h )
|
124
|
+
end
|
125
|
+
elsif e.has_text?
|
126
|
+
hash[e.name] = e.text
|
127
|
+
end
|
128
|
+
end
|
129
|
+
else
|
130
|
+
hash[self.name] = self.text
|
131
|
+
end
|
132
|
+
hash
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Niftycloud
|
2
|
+
class Signature
|
3
|
+
def self.v0(key, data)
|
4
|
+
Base64.encode64(OpenSSL::HMAC.digest("sha1", key.encode("utf-8"), data.encode("utf-8"))).chomp
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.v2(key, data)
|
8
|
+
CGI.escape(Base64.encode64(OpenSSL::HMAC.digest("sha256", key.encode("utf-8"), data.encode("utf-8"))).chomp)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/niftycloud.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "niftycloud/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "niftycloud"
|
8
|
+
spec.version = Niftycloud::VERSION
|
9
|
+
spec.authors = ["Kazuki Iwata"]
|
10
|
+
spec.email = ["kazu.0516.k0n0f@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Unofficial NIFTY Cloud SDK for Ruby}
|
13
|
+
spec.description = %q{The Unofficial NIFTY Cloud SDK for Ruby}
|
14
|
+
spec.homepage = "https://github.com/kzmake/niftycloud"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'webmock'
|
27
|
+
|
28
|
+
if RUBY_VERSION < '2.0'
|
29
|
+
spec.add_runtime_dependency 'httparty', '~> 0.13.0'
|
30
|
+
else
|
31
|
+
spec.add_runtime_dependency 'httparty'
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: niftycloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kazuki Iwata
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
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: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: The Unofficial NIFTY Cloud SDK for Ruby
|
84
|
+
email:
|
85
|
+
- kazu.0516.k0n0f@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- lib/niftycloud.rb
|
99
|
+
- lib/niftycloud/api.rb
|
100
|
+
- lib/niftycloud/client.rb
|
101
|
+
- lib/niftycloud/client/hoge.rb
|
102
|
+
- lib/niftycloud/client/issues.rb
|
103
|
+
- lib/niftycloud/configuration.rb
|
104
|
+
- lib/niftycloud/error.rb
|
105
|
+
- lib/niftycloud/objectified_hash.rb
|
106
|
+
- lib/niftycloud/page_links.rb
|
107
|
+
- lib/niftycloud/paginated_response.rb
|
108
|
+
- lib/niftycloud/request.rb
|
109
|
+
- lib/niftycloud/signature.rb
|
110
|
+
- lib/niftycloud/version.rb
|
111
|
+
- niftycloud.gemspec
|
112
|
+
homepage: https://github.com/kzmake/niftycloud
|
113
|
+
licenses: []
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.6.13
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Unofficial NIFTY Cloud SDK for Ruby
|
135
|
+
test_files: []
|