gifnoc 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/.editorconfig +24 -0
- data/.gitignore +8 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG +2 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +60 -0
- data/LICENSE +201 -0
- data/README.md +97 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gifnoc.gemspec +35 -0
- data/lib/gifnoc.rb +11 -0
- data/lib/gifnoc/apis.rb +5 -0
- data/lib/gifnoc/apis/account_api_methods.rb +29 -0
- data/lib/gifnoc/apis/api.rb +47 -0
- data/lib/gifnoc/apis/namespace_api_methods.rb +39 -0
- data/lib/gifnoc/apis/record_api_methods.rb +39 -0
- data/lib/gifnoc/apis/token_api_methods.rb +39 -0
- data/lib/gifnoc/clients.rb +5 -0
- data/lib/gifnoc/clients/account_client_methods.rb +24 -0
- data/lib/gifnoc/clients/client.rb +14 -0
- data/lib/gifnoc/clients/namespace_client_methods.rb +27 -0
- data/lib/gifnoc/clients/record_client_methods.rb +27 -0
- data/lib/gifnoc/clients/token_client_methods.rb +27 -0
- data/lib/gifnoc/exceptions.rb +18 -0
- data/lib/gifnoc/models.rb +6 -0
- data/lib/gifnoc/models/account.rb +18 -0
- data/lib/gifnoc/models/model.rb +71 -0
- data/lib/gifnoc/models/namespace.rb +20 -0
- data/lib/gifnoc/models/record.rb +53 -0
- data/lib/gifnoc/models/token.rb +20 -0
- data/lib/gifnoc/models/typed_attr_accessor.rb +62 -0
- data/lib/gifnoc/version.rb +3 -0
- metadata +213 -0
data/bin/setup
ADDED
data/gifnoc.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require "gifnoc/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gifnoc"
|
8
|
+
spec.version = Gifnoc::VERSION
|
9
|
+
spec.authors = ["Cloud 66"]
|
10
|
+
spec.email = ["hello@cloud66.com"]
|
11
|
+
|
12
|
+
spec.summary = "A Ruby Gifnoc client implementation"
|
13
|
+
spec.homepage = "https://github.com/cloud66-oss/gifnoc-ruby"
|
14
|
+
spec.license = "Apache-2.0"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "bin"
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
spec.add_development_dependency "pry-byebug", "~> 3.6"
|
29
|
+
spec.add_development_dependency "webmock", "~> 3.4", ">= 3.4.2"
|
30
|
+
spec.add_development_dependency "vcr", "~> 4.0"
|
31
|
+
spec.add_development_dependency "simplecov", "~> 0.16.1"
|
32
|
+
|
33
|
+
spec.add_dependency "httparty", "~> 0.16.2"
|
34
|
+
spec.add_dependency "ice_nine", "~> 0.11.2"
|
35
|
+
end
|
data/lib/gifnoc.rb
ADDED
data/lib/gifnoc/apis.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Gifnoc
|
2
|
+
module AccountAPIMethods
|
3
|
+
|
4
|
+
def list_accounts
|
5
|
+
return with_response_handling do
|
6
|
+
self.class.get("/accounts", @options)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_account(account_uuid)
|
11
|
+
return with_response_handling do
|
12
|
+
self.class.get("/accounts/#{account_uuid}", @options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_account
|
17
|
+
return with_response_handling do
|
18
|
+
self.class.post("/accounts", @options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_account(account_uuid)
|
23
|
+
return with_response_handling do
|
24
|
+
self.class.delete("/accounts/#{account_uuid}", @options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module Gifnoc
|
4
|
+
class API
|
5
|
+
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
include AccountAPIMethods
|
9
|
+
include NamespaceAPIMethods
|
10
|
+
include RecordAPIMethods
|
11
|
+
include TokenAPIMethods
|
12
|
+
|
13
|
+
default_timeout 30
|
14
|
+
|
15
|
+
def initialize(token:, base_url:)
|
16
|
+
@token = token
|
17
|
+
@options = {
|
18
|
+
base_uri: base_url,
|
19
|
+
headers: headers,
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def headers
|
26
|
+
return {
|
27
|
+
"X-Token" => @token,
|
28
|
+
'Content-Type' => 'application/json',
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def with_response_handling
|
33
|
+
response = begin
|
34
|
+
yield
|
35
|
+
rescue ::Timeout::Error # includes ::Net::OpenTimeout and ::Net::ReadTimeout
|
36
|
+
raise Gifnoc::Timeout
|
37
|
+
end
|
38
|
+
handle_error(response) unless response.success?
|
39
|
+
return response.parsed_response
|
40
|
+
end
|
41
|
+
|
42
|
+
def handle_error(response)
|
43
|
+
raise Gifnoc::HTTPError.new(status_code: response.code, response: response.parsed_response)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Gifnoc
|
2
|
+
module NamespaceAPIMethods
|
3
|
+
|
4
|
+
def list_namespaces
|
5
|
+
return with_response_handling do
|
6
|
+
self.class.get("/namespaces", @options)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_namespace(namespace_uuid)
|
11
|
+
return with_response_handling do
|
12
|
+
self.class.get("/namespaces/#{namespace_uuid}", @options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_namespace(namespace_hash)
|
17
|
+
options = {body: namespace_hash.to_json}
|
18
|
+
options = options.merge(@options)
|
19
|
+
return with_response_handling do
|
20
|
+
self.class.post("/namespaces", options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_namespace(namespace_uuid, namespace_hash)
|
25
|
+
options = {body: namespace_hash.to_json}
|
26
|
+
options = options.merge(@options)
|
27
|
+
return with_response_handling do
|
28
|
+
self.class.put("/namespaces/#{namespace_uuid}", options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_namespace(namespace_uuid)
|
33
|
+
return with_response_handling do
|
34
|
+
self.class.delete("/namespaces/#{namespace_uuid}", @options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Gifnoc
|
2
|
+
module RecordAPIMethods
|
3
|
+
|
4
|
+
def list_records(namespace_uuid)
|
5
|
+
return with_response_handling do
|
6
|
+
self.class.get("/namespaces/#{namespace_uuid}/records", @options)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_record(namespace_uuid, record_key)
|
11
|
+
return with_response_handling do
|
12
|
+
self.class.get("/namespaces/#{namespace_uuid}/records/#{record_key}", @options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_record(namespace_uuid, record_hash)
|
17
|
+
options = {body: record_hash.to_json}
|
18
|
+
options = options.merge(@options)
|
19
|
+
return with_response_handling do
|
20
|
+
self.class.post("/namespaces/#{namespace_uuid}/records", options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_record(namespace_uuid, record_key, record_hash)
|
25
|
+
options = {body: record_hash.to_json}
|
26
|
+
options = options.merge(@options)
|
27
|
+
return with_response_handling do
|
28
|
+
self.class.put("/namespaces/#{namespace_uuid}/records/#{record_key}", options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_record(namespace_uuid, record_key)
|
33
|
+
return with_response_handling do
|
34
|
+
self.class.delete("/namespaces/#{namespace_uuid}/records/#{record_key}", @options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Gifnoc
|
2
|
+
module TokenAPIMethods
|
3
|
+
|
4
|
+
def list_tokens
|
5
|
+
return with_response_handling do
|
6
|
+
self.class.get("/tokens", @options)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_token(token_uuid)
|
11
|
+
return with_response_handling do
|
12
|
+
self.class.get("/tokens/#{token_uuid}", @options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_token(token_hash)
|
17
|
+
options = {body: token_hash.to_json}
|
18
|
+
options = options.merge(@options)
|
19
|
+
return with_response_handling do
|
20
|
+
self.class.post("/tokens", options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_token(token_uuid, token_hash)
|
25
|
+
options = {body: token_hash.to_json}
|
26
|
+
options = options.merge(@options)
|
27
|
+
return with_response_handling do
|
28
|
+
self.class.put("/tokens/#{token_uuid}", options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_token(token_uuid)
|
33
|
+
return with_response_handling do
|
34
|
+
self.class.delete("/tokens/#{token_uuid}", @options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Gifnoc
|
2
|
+
module AccountClientMethods
|
3
|
+
|
4
|
+
def list_accounts
|
5
|
+
return @api.list_accounts.map do |raw_account|
|
6
|
+
next(Gifnoc::Account.from_api_hash(raw_account))
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_account(account_uuid)
|
11
|
+
return Gifnoc::Account.from_api_hash(@api.get_account(account_uuid))
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_account
|
15
|
+
raw_result = @api.create_account
|
16
|
+
return Gifnoc::Account.from_api_hash(raw_result["account"]), Gifnoc::Token.from_api_hash(raw_result["token"])
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete_account(account_uuid)
|
20
|
+
return @api.delete_account(account_uuid)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Gifnoc
|
2
|
+
class Client
|
3
|
+
|
4
|
+
include AccountClientMethods
|
5
|
+
include NamespaceClientMethods
|
6
|
+
include RecordClientMethods
|
7
|
+
include TokenClientMethods
|
8
|
+
|
9
|
+
def initialize(token:, base_url:)
|
10
|
+
@api = Gifnoc::API.new(token: token, base_url: base_url)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Gifnoc
|
2
|
+
module NamespaceClientMethods
|
3
|
+
|
4
|
+
def list_namespaces
|
5
|
+
return @api.list_namespaces.map do |raw_namespace|
|
6
|
+
next(Gifnoc::Namespace.from_api_hash(raw_namespace))
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_namespace(namespace_uuid)
|
11
|
+
return Gifnoc::Namespace.from_api_hash(@api.get_namespace(namespace_uuid))
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_namespace(namespace)
|
15
|
+
return Gifnoc::Namespace.from_api_hash(@api.create_namespace(namespace.to_api_hash))
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_namespace(namespace_uuid, namespace)
|
19
|
+
return Gifnoc::Namespace.from_api_hash(@api.update_namespace(namespace_uuid, namespace.to_api_hash))
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_namespace(namespace_uuid)
|
23
|
+
return @api.delete_namespace(namespace_uuid)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Gifnoc
|
2
|
+
module RecordClientMethods
|
3
|
+
|
4
|
+
def list_records(namespace_uuid)
|
5
|
+
return @api.list_records(namespace_uuid).map do |raw_record|
|
6
|
+
next(Gifnoc::Record.from_api_hash(raw_record))
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_record(namespace_uuid, record_key)
|
11
|
+
return Gifnoc::Record.from_api_hash(@api.get_record(namespace_uuid, record_key))
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_record(namespace_uuid, record)
|
15
|
+
return Gifnoc::Record.from_api_hash(@api.create_record(namespace_uuid, record.to_api_hash))
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_record(namespace_uuid, record_key, record)
|
19
|
+
return Gifnoc::Record.from_api_hash(@api.update_record(namespace_uuid, record_key, record.to_api_hash))
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_record(namespace_uuid, record_key)
|
23
|
+
return @api.delete_record(namespace_uuid, record_key)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Gifnoc
|
2
|
+
module TokenClientMethods
|
3
|
+
|
4
|
+
def list_tokens
|
5
|
+
return @api.list_tokens.map do |raw_token|
|
6
|
+
next(Gifnoc::Token.from_api_hash(raw_token))
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_token(token_uuid)
|
11
|
+
return Gifnoc::Token.from_api_hash(@api.get_token(token_uuid))
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_token(token)
|
15
|
+
return Gifnoc::Token.from_api_hash(@api.create_token(token.to_api_hash))
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_token(token_uuid, token)
|
19
|
+
return Gifnoc::Token.from_api_hash(@api.update_token(token_uuid, token.to_api_hash))
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_token(token_uuid)
|
23
|
+
return @api.delete_token(token_uuid)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Gifnoc
|
2
|
+
class Error < StandardError; end
|
3
|
+
class Timeout < Error; end;
|
4
|
+
class HTTPError < Error
|
5
|
+
attr_reader :status_code, :response
|
6
|
+
|
7
|
+
def initialize(status_code:, response:, message: nil)
|
8
|
+
@status_code = status_code
|
9
|
+
@response = response
|
10
|
+
@message = message
|
11
|
+
@default_message = "Gifnoc API request failed with HTTP status code #{status_code}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
return @message || @default_message
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Gifnoc
|
2
|
+
class Account < Model
|
3
|
+
|
4
|
+
ATTRIBUTES = {
|
5
|
+
uuid: TypedAttrAccessor::TYPE_STRING,
|
6
|
+
namespace_count: TypedAttrAccessor::TYPE_INTEGER,
|
7
|
+
created_at: TypedAttrAccessor::TYPE_DATE_TIME,
|
8
|
+
updated_at: TypedAttrAccessor::TYPE_DATE_TIME,
|
9
|
+
}.deep_freeze
|
10
|
+
|
11
|
+
API_ATTRIBUTE_LIST = [:uuid, :namespace_count, :created_at, :updated_at].deep_freeze
|
12
|
+
|
13
|
+
attributes_hash.each do |name, type_alias|
|
14
|
+
typed_attr_accessor(name, type_alias)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|