dit3-api 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dit3/api/client.rb +18 -1
- data/lib/dit3/api/model/account.rb +9 -0
- data/lib/dit3/api/model/tenant.rb +8 -0
- data/lib/dit3/api/wrappers/accounts.rb +25 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f884943f360236bbc87a1b8ad49b77e85163424e
|
4
|
+
data.tar.gz: 87014abcaac09a2e66b57103efc5f6dfe83186b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3db96e53f4b676b8af0fef9759e3007405d5f58941fabe2a6b197b85a5b73720b860377d8e1daff501f97e71ca50ecac5e88e6fae8801f583ed1075baf8f07b0
|
7
|
+
data.tar.gz: ff5d3692f2c8a27e35e43a0b934f3be1a867059022a9f48cc3b95f902eb00b2c4cd0b5cc29a1bdc7cea90ce6ef71115573df552351083df9218903191c4d64eb
|
data/lib/dit3/api/client.rb
CHANGED
@@ -4,6 +4,7 @@ require 'uri'
|
|
4
4
|
|
5
5
|
require_relative 'api_error'
|
6
6
|
require_relative 'oauth_client'
|
7
|
+
require_relative 'wrappers/accounts'
|
7
8
|
require_relative 'wrappers/tenants'
|
8
9
|
|
9
10
|
module DIT3::Api
|
@@ -15,7 +16,8 @@ module DIT3::Api
|
|
15
16
|
@request_factory = {
|
16
17
|
"GET" => method(:get_request),
|
17
18
|
"POST" => method(:post_request),
|
18
|
-
"DELETE" => method(:delete_request)
|
19
|
+
"DELETE" => method(:delete_request),
|
20
|
+
"PUT" => method(:put_request)
|
19
21
|
}
|
20
22
|
end
|
21
23
|
|
@@ -23,6 +25,10 @@ module DIT3::Api
|
|
23
25
|
Wrappers::Tenants.new(self)
|
24
26
|
end
|
25
27
|
|
28
|
+
def accounts
|
29
|
+
Wrappers::Accounts.new(self)
|
30
|
+
end
|
31
|
+
|
26
32
|
def exec_request method, endpoint
|
27
33
|
uri = URI(@api + endpoint)
|
28
34
|
request = @request_factory[method].call(uri)
|
@@ -52,6 +58,13 @@ module DIT3::Api
|
|
52
58
|
end
|
53
59
|
end
|
54
60
|
|
61
|
+
def put endpoint, data
|
62
|
+
exec_request("PUT", endpoint) do |request|
|
63
|
+
request['Content-Type'] = 'application/json'
|
64
|
+
request.body = data.to_json
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
55
68
|
def delete endpoint
|
56
69
|
exec_request("DELETE", endpoint)
|
57
70
|
end
|
@@ -80,6 +93,10 @@ module DIT3::Api
|
|
80
93
|
Net::HTTP::Delete.new(endpoint_uri.request_uri, 'Authorization' => "Bearer #{@token}")
|
81
94
|
end
|
82
95
|
|
96
|
+
def put_request endpoint_uri
|
97
|
+
Net::HTTP::Put.new(endpoint_uri.request_uri, 'Authorization' => "Bearer #{@token}")
|
98
|
+
end
|
99
|
+
|
83
100
|
def get_http endpoint_uri
|
84
101
|
http = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
|
85
102
|
if (endpoint_uri.scheme == 'https')
|
@@ -1,9 +1,17 @@
|
|
1
1
|
module DIT3::Api::Model
|
2
2
|
class Tenant
|
3
3
|
attr_reader :name
|
4
|
+
attr_reader :id
|
4
5
|
|
5
6
|
def initialize hash
|
6
7
|
@name = hash['name']
|
8
|
+
@id = hash['id']
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_hash
|
12
|
+
hash = {}
|
13
|
+
instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
|
14
|
+
hash
|
7
15
|
end
|
8
16
|
end
|
9
17
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative '../model/account.rb'
|
2
|
+
|
3
|
+
module DIT3::Api::Wrappers
|
4
|
+
class Accounts
|
5
|
+
def initialize client
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def get name
|
10
|
+
begin
|
11
|
+
DIT3::Api::Model::Account.new(@client.get("/accounts/#{name}"))
|
12
|
+
rescue DIT3::Api::ApiError
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_tenant name, tenant
|
18
|
+
@client.put("/accounts/#{name}/tenant", tenant.to_hash())
|
19
|
+
end
|
20
|
+
|
21
|
+
def exists? name
|
22
|
+
!get(name).nil?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dit3-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Maraev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2-client
|
@@ -33,8 +33,10 @@ files:
|
|
33
33
|
- lib/dit3/api.rb
|
34
34
|
- lib/dit3/api/api_error.rb
|
35
35
|
- lib/dit3/api/client.rb
|
36
|
+
- lib/dit3/api/model/account.rb
|
36
37
|
- lib/dit3/api/model/tenant.rb
|
37
38
|
- lib/dit3/api/oauth_client.rb
|
39
|
+
- lib/dit3/api/wrappers/accounts.rb
|
38
40
|
- lib/dit3/api/wrappers/tenants.rb
|
39
41
|
homepage: http://rubygems.org/gems/dit3-api
|
40
42
|
licenses:
|