rxg_client 0.1.0 → 1.0.0

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.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/rxg_client.rb +52 -17
  3. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e7faddbac99675ec4042eb40ac013e70aa005c98
4
- data.tar.gz: 36edf972b42b8012e37b6dc04b828952bbe1e074
2
+ SHA256:
3
+ metadata.gz: aa8f8c7ab1ddb93d7980df022f69b4c27724b8a7bad078077f266dd8e8988da4
4
+ data.tar.gz: 20cb8f51c71a2e8064ef238272b42531111f89e6a385cca9da485aefde080375
5
5
  SHA512:
6
- metadata.gz: b1626b8e2375bb84512059f249caaf7bd3b386be98c18f69ca49378b43a2ebc7aeaae4cfd2d2f092e108a734e74554ac2d2cb9ad3dbdd29707b08efbb14ee8f7
7
- data.tar.gz: be0004f6d585196a0f6d61e99001f79cdb020114130b581ccd786f622bcc97396222e59bd5d944d6bfd3d047cbc22124dcf3cfdddce508c8ff59de14fe7edffc
6
+ metadata.gz: a73d0b3014384505a07678155f7a34d4649531957bf7ff22014dab0227e6b800715e21c5d54b96c5c4500fcd0a5141ffd4d2f37b53c77e2e8c4bb0a84659a49e
7
+ data.tar.gz: fe53a906dd991b1a5347e0bf7a2c5412e6728449dc1a99d7a0797b37bf538262340f05ec5aa3e8943cc8bb7aa553b1d2f1b3d9d20aac15d34f174c0789ab4830
@@ -1,35 +1,65 @@
1
1
  class RxgClient
2
- require 'delegate'
3
2
  require 'httparty'
4
3
 
5
4
  include HTTParty
6
5
 
7
- attr_accessor :api_key, :hostname, :request_format, :raise_exceptions
6
+ attr_accessor :api_key, :hostname, :request_format, :raise_exceptions, :auth
8
7
 
9
8
  def request_format= (requested_format)
10
9
  raise HTTParty::UnsupportedFormat unless [ :json, :xml ].include?(requested_format.to_sym)
11
10
  @request_format = requested_format
12
11
  end
13
12
 
14
- def initialize(hostname, api_key, request_format: :json, default_timeout: 5, raise_exceptions: false, verify_ssl: false)
13
+ # The following options can be configured when initializing the client:
14
+ # - default_timeout: the amount of time in seconds to wait for a response.
15
+ # default is 5
16
+ # - raise_exceptions: true or false.
17
+ # default is true
18
+ # - verify_ssl: true or false.
19
+ # default is true
20
+ # If using an IP, must be false.
21
+ # - fleet: pass true if authentication should use the 'fleetkey' header
22
+ # instead of apikey.
23
+ # default is false
24
+ # - auth_method: must be one of: :headers, :query
25
+ # default is :headers
26
+ # If fleet is true, headers will always be used
27
+ # - debug: pass a logger or $stdout to have debug_output logged, or nil to disable.
28
+ # default is nil
29
+ def initialize(hostname, api_key, request_format: :json, default_timeout: 5,
30
+ raise_exceptions: false, verify_ssl: false, fleet: false, debug: nil,
31
+ auth_method: :headers)
15
32
 
16
33
  self.api_key = api_key
17
-
34
+
18
35
  self.request_format = request_format.to_sym
19
36
  self.class.format self.request_format
20
37
 
21
38
  self.hostname = hostname
22
39
  self.class.base_uri "https://#{self.hostname}/admin/scaffolds"
23
-
40
+
24
41
  self.class.default_timeout default_timeout
25
42
 
26
43
  self.raise_exceptions = raise_exceptions
27
44
 
28
45
  self.class.default_options.update(verify: verify_ssl)
29
- end
30
46
 
31
- def auth
32
- {api_key: self.api_key}
47
+ self.class.debug_output debug
48
+
49
+ case auth_method
50
+ when :headers # compatible with rXg version 11.442 or later
51
+ if fleet
52
+ self.class.headers { 'fleetkey' => self.api_key }
53
+ else
54
+ self.class.headers { 'api_key' => self.api_key }
55
+ end
56
+ when :query
57
+ if fleet
58
+ self.class.headers { 'fleetkey' => self.api_key }
59
+ else
60
+ self.class.default_params { 'api_key' => self.api_key }
61
+ end
62
+ end
33
63
  end
34
64
 
35
65
  def parse(body)
@@ -40,7 +70,7 @@ class RxgClient
40
70
  result = JSON.parse(body)
41
71
  when :xml
42
72
  result = Hash.from_xml(body)
43
- else
73
+ else
44
74
  raise "Request format should be one of: :json, :xml"
45
75
  end
46
76
 
@@ -62,31 +92,36 @@ class RxgClient
62
92
 
63
93
  # create a record in the given table with the attributes provided in new_record
64
94
  def create(table, new_record)
65
- response = self.class.post("/#{table}/create/index.#{self.request_format}", { body: {record: new_record}.merge(self.auth) })
95
+ response = self.class.post("/#{table}/create/index.#{self.request_format}", body: {record: new_record})
66
96
  response.success? ? self.parse(response.body) : raise(response.message)
67
97
  end
68
-
98
+
69
99
  # list all records from the given table
70
100
  def list(table)
71
- response = self.class.get("/#{table}/index.#{self.request_format}", {body: self.auth})
101
+ response = self.class.get("/#{table}/index.#{self.request_format}")
102
+ response.success? ? self.parse(response.body) : raise(response.message)
103
+ end
104
+
105
+ def search(table, search_params)
106
+ response = self.class.post("/#{table}/index.#{self.request_format}", body: search_params)
72
107
  response.success? ? self.parse(response.body) : raise(response.message)
73
108
  end
74
109
 
75
110
  # return the record from the given table having the given id
76
111
  def show(table, id)
77
- response = self.class.get("/#{table}/show/#{id}.#{self.request_format}", {body: self.auth})
112
+ response = self.class.get("/#{table}/show/#{id}.#{self.request_format}")
78
113
  response.success? ? self.parse(response.body) : raise(response.message)
79
114
  end
80
115
 
81
116
  # update a record from the given table, having the given id, with the updated attributes provided in updated_record_hash
82
117
  def update(table, id, updated_record_hash)
83
- response = self.class.post("/#{table}/update/#{id}.#{self.request_format}", {body: {record: updated_record_hash}.merge(self.auth)})
118
+ response = self.class.post("/#{table}/update/#{id}.#{self.request_format}", body: {record: updated_record_hash})
84
119
  response.success? ? self.parse(response.body) : raise(response.message)
85
120
  end
86
121
 
87
122
  # destroy a record from the given table having the given id
88
123
  def destroy(table, id)
89
- response = self.class.post("/#{table}/destroy/#{id}.#{self.request_format}", {body: self.auth})
124
+ response = self.class.post("/#{table}/destroy/#{id}.#{self.request_format}")
90
125
  response.success? ? self.parse(response.body) : raise(response.message)
91
126
  end
92
127
 
@@ -99,7 +134,7 @@ class RxgClient
99
134
  # method_args - A serialized Array or Hash of the argument(s) expected by the method.
100
135
  # example method call:
101
136
  # node.execute("shared_credential_groups", {record_id: 7, method_name: "make_login_session", method_args:["192.168.20.111", "00:00:00:00:00:05", "test", 1]})
102
- response = self.class.post("/#{table}/execute.#{self.request_format}", {query: self.auth, body: {request: request}})
137
+ response = self.class.post("/#{table}/execute.#{self.request_format}", body: {request: request})
103
138
  response.success? ? self.parse(response.body) : raise(response.message)
104
139
  end
105
140
 
@@ -123,7 +158,7 @@ class RxgClient
123
158
 
124
159
  # The listed methods will be rescued from all StandardError exceptions, and the code within
125
160
  # the block will be executed.
126
- rescue_from StandardError, :create, :list, :show, :update, :destroy, :execute do |exception, instance|
161
+ rescue_from StandardError, :create, :list, :show, :update, :destroy, :execute, :search do |exception, instance|
127
162
  puts exception.message
128
163
 
129
164
  raise exception if instance.raise_exceptions
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rxg_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lannar Dean
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-18 00:00:00.000000000 Z
11
+ date: 2020-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -51,8 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubyforge_project:
55
- rubygems_version: 2.6.11
54
+ rubygems_version: 3.0.6
56
55
  signing_key:
57
56
  specification_version: 4
58
57
  summary: RXG API Client