Class: SkullIsland::APIClientBase
Overview
The API Client Base class
Instance Attribute Summary collapse
Instance Method Summary
collapse
#about_service, #cache, #invalidate_cache_for, #json_escape, #lru_cache, #raw, #server_status, #version
#validate_creds, #validate_opts, #validate_server
Instance Attribute Details
#base_uri ⇒ Object
Returns the value of attribute base_uri.
6
7
8
|
# File 'lib/skull_island/api_client_base.rb', line 6
def base_uri
@base_uri
end
|
#password ⇒ Object
Returns the value of attribute password.
7
8
9
|
# File 'lib/skull_island/api_client_base.rb', line 7
def password
@password
end
|
#server ⇒ Object
Returns the value of attribute server.
6
7
8
|
# File 'lib/skull_island/api_client_base.rb', line 6
def server
@server
end
|
#username ⇒ Object
Returns the value of attribute username.
7
8
9
|
# File 'lib/skull_island/api_client_base.rb', line 7
def username
@username
end
|
Instance Method Details
#api_uri ⇒ Object
12
13
14
15
16
|
# File 'lib/skull_island/api_client_base.rb', line 12
def api_uri
@api_uri ||= URI.parse(server)
@api_uri.path = base_uri if base_uri
@api_uri
end
|
#authenticated? ⇒ Boolean
18
19
20
21
22
|
# File 'lib/skull_island/api_client_base.rb', line 18
def authenticated?
raise Exceptions::APIClientNotConfigured unless configured?
@username && @password ? true : false
end
|
24
25
26
|
# File 'lib/skull_island/api_client_base.rb', line 24
def configured?
@configured ? true : false
end
|
#delete(uri) ⇒ Object
83
84
85
86
87
|
# File 'lib/skull_island/api_client_base.rb', line 83
def delete(uri)
client_action do |client|
client[uri].delete()
end
end
|
#get(uri, data = nil) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/skull_island/api_client_base.rb', line 32
def get(uri, data = nil)
client_action do |client|
results = nil
params = {}
params.merge(data) if data
loop do
follow_up = JSON.parse client[uri].get(.merge(params: params))
if results
results['data'] += follow_up['data']
else
results = follow_up.dup
results.delete('offset')
results.delete('next')
end
params = params.merge('offset' => follow_up['offset']) if follow_up.key?('offset')
raise StopIteration unless follow_up.key?('offset')
end
results
end
end
|
28
29
30
|
# File 'lib/skull_island/api_client_base.rb', line 28
def
{ content_type: :json, accept: :json }
end
|
#patch(uri, data) ⇒ Object
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/skull_island/api_client_base.rb', line 66
def patch(uri, data)
client_action do |client|
response = client[uri].patch(json_escape(data.to_json), )
if response && !response.empty?
JSON.parse(response)
else
true
end
end
end
|
#post(uri, data = nil) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/skull_island/api_client_base.rb', line 56
def post(uri, data = nil)
client_action do |client|
if data
JSON.parse client[uri].post(json_escape(data.to_json), )
else
JSON.parse client[uri].post(nil, )
end
end
end
|
#put(uri, data) ⇒ Object
77
78
79
80
81
|
# File 'lib/skull_island/api_client_base.rb', line 77
def put(uri, data)
client_action do |client|
client[uri].put(json_escape(data.to_json), )
end
end
|