xlogin-apiclient 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/xlogin/apiclient.rb +27 -61
- data/lib/xlogin/apiclient/version.rb +1 -1
- data/xlogin-apiclient.gemspec +2 -0
- metadata +17 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 18a35f6ba98b58373950e71f3c3a87683087981acc457099952fe85beb474957
|
4
|
+
data.tar.gz: 6501f3d09a773b2925e779d5c72a7905e9871a0e002bb99560bea537b8747cdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84722296fb0c543e96fe23629845694c76a96dbac5f6d7812b3daf3022374163f4e389110b772931517e43fa895fe3baac23e03dbd8908fadaf020986d72d41e
|
7
|
+
data.tar.gz: 0ac161f727446451c8981e66e80c4c69be3821eab9cf7ad6998b95738cfba11cde028f9fa75e8d51e08f2fff16b73e5ae9c2327c762918ec7e4f66427530a800
|
data/lib/xlogin/apiclient.rb
CHANGED
@@ -1,78 +1,44 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'net/http'
|
3
|
-
require '
|
3
|
+
require 'addressable/uri'
|
4
4
|
require "xlogin/apiclient/version"
|
5
5
|
|
6
6
|
module Xlogin
|
7
|
-
|
8
|
-
class
|
7
|
+
class APIClient
|
8
|
+
class Error < StandardError; end
|
9
9
|
|
10
|
-
class
|
11
|
-
|
12
|
-
|
13
|
-
@type = type
|
14
|
-
@args = args
|
15
|
-
end
|
16
|
-
|
17
|
-
def cmd(req = Request.new, &block)
|
18
|
-
if req.kind_of?(String)
|
19
|
-
req, _req = Request.new, req
|
20
|
-
req.command = _req
|
21
|
-
end
|
22
|
-
|
23
|
-
req.xlogin = @args
|
24
|
-
block.call(req) if block
|
25
|
-
|
26
|
-
uri = @uri.dup
|
27
|
-
uri.path += "/vendors/#{@type}/actions"
|
28
|
-
|
29
|
-
http(:post, uri, req.to_h)
|
30
|
-
rescue => e
|
31
|
-
raise APIError.new(e.message)
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
def http(method, uri, **args)
|
36
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
37
|
-
|
38
|
-
klass = Net::HTTP.const_get(method.to_s.capitalize)
|
39
|
-
req = klass.new(uri.path)
|
40
|
-
req["Accept"] = "application/json"
|
41
|
-
|
42
|
-
unless args.empty?
|
43
|
-
req["Content-Type"] = "application/json"
|
44
|
-
req.body = JSON.dump(args)
|
45
|
-
end
|
10
|
+
class << self
|
11
|
+
attr_accessor :base_url
|
12
|
+
end
|
46
13
|
|
47
|
-
|
48
|
-
|
14
|
+
def initialize(base_url: self.class.base_url, **args)
|
15
|
+
raise Error.new('base_url not defined') unless base_url
|
49
16
|
|
50
|
-
|
51
|
-
|
17
|
+
@uri = Addressable::URI.parse(base_url)
|
18
|
+
@type = args.delete(:type)
|
19
|
+
@args = args
|
52
20
|
end
|
53
21
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
def create(**args)
|
60
|
-
Client.new(@base_uri, args)
|
61
|
-
end
|
22
|
+
def cmd(args)
|
23
|
+
params = {driver: @type, target: @args, command: args}
|
24
|
+
resp = request(**params.transform_keys(&:to_sym))
|
25
|
+
resp['payload'].join
|
62
26
|
end
|
63
27
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
28
|
+
private
|
29
|
+
def request(**params)
|
30
|
+
uri = @uri.dup
|
31
|
+
uri.query = "q=#{URI.encode_www_form_component(JSON.generate(params))}"
|
69
32
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
33
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
34
|
+
req["Accept"] = "application/json"
|
35
|
+
|
36
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
37
|
+
body = http.request(req).body
|
38
|
+
resp = body ? JSON.parse(body) : {}
|
39
|
+
return resp if resp['success']
|
74
40
|
|
75
|
-
|
41
|
+
raise Error.new(resp['error'])
|
76
42
|
end
|
77
43
|
end
|
78
44
|
end
|
data/xlogin-apiclient.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlogin-apiclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- haccht
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: addressable
|
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'
|
41
55
|
description: API client for xlogin-api.
|
42
56
|
email:
|
43
57
|
- haccht@users.noreply.github.com
|
@@ -75,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
89
|
- !ruby/object:Gem::Version
|
76
90
|
version: '0'
|
77
91
|
requirements: []
|
78
|
-
|
79
|
-
rubygems_version: 2.6.14.1
|
92
|
+
rubygems_version: 3.0.3
|
80
93
|
signing_key:
|
81
94
|
specification_version: 4
|
82
95
|
summary: API client for xlogin-api.
|