Class: Eco::API::Session::Config::Api
- Inherits:
-
Hash
- Object
- Hash
- Eco::API::Session::Config::Api
show all
- Defined in:
- lib/eco/api/session/config/api.rb
Class Method Summary
collapse
Instance Method Summary
collapse
-
#api(version: nil, logger: nil) ⇒ Ecoportal::API::Internal, ...
Obtain an API
object of a specific version
.
-
#config ⇒ Eco::API::Session::Config
-
#email ⇒ Object
-
#external_key ⇒ Object
-
#get(version) ⇒ Object
-
#host ⇒ Object
-
#initialize(name, root:, key:, host:, version:, mode: :local, user_key: nil, external_key: nil, email: nil, pass: nil, org_id: nil) ⇒ Api
constructor
-
#internal_key ⇒ Object
-
#key ⇒ Object
-
#local? ⇒ Boolean
-
#logger ⇒ Object
if no low level connection messages: use IO::NULL
.
-
#mode ⇒ Symbol
If running on :remote
or :local
.
-
#mode=(mode) ⇒ Object
-
#name ⇒ Object
-
#one_off? ⇒ Boolean
-
#org_id ⇒ Object
-
#pass ⇒ Object
-
#remote? ⇒ Boolean
-
#set(version, api) ⇒ Object
-
#user_key ⇒ Object
-
#version(value = nil) ⇒ Object
-
#version_available?(version) ⇒ Boolean
Whether or not version
is available.
Methods inherited from Hash
#deep_merge, #deep_merge!
Constructor Details
#initialize(name, root:, key:, host:, version:, mode: :local, user_key: nil, external_key: nil, email: nil, pass: nil, org_id: nil) ⇒ Api
Returns a new instance of Api.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/eco/api/session/config/api.rb', line 35
def initialize(name, root:, key:, host:, version:,
mode: :local, user_key: nil, external_key: nil,
email: nil, pass: nil, org_id: nil)
super(nil)
@root = root
@apis = {}
self["name"] = name
self["key"] = key
self["host"] = host
self["version"] = version
self["mode"] = mode
self["user_key"] = user_key
self["external_key"] = external_key
self["email"] = email
self["pass"] = pass
self["org_id"] = org_id
end
|
Class Method Details
.api_class(version = :v0) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/eco/api/session/config/api.rb', line 20
def api_class(version = :v0)
case to_version(version)
when :v0
Ecoportal::API::Internal
when :v1
Ecoportal::API::V1
when :v2
Ecoportal::API::V2
when :graphql
Ecoportal::API::GraphQL
else
end
end
|
.to_version(str) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/eco/api/session/config/api.rb', line 7
def to_version(str)
case str.to_sym
when :external, :v1
:v1
when :v2, :oozes
:v2
when :graphql
:graphql
else :v0
end
end
|
Instance Method Details
#api(version: nil, logger: nil) ⇒ Ecoportal::API::Internal, ...
Obtain an API
object of a specific version
.
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/eco/api/session/config/api.rb', line 62
def api(version: nil, logger: nil)
version = version ? version : self.version
switch_logger = (logger != @logger)
@logger = logger if logger
if (current = get(version)) && !switch_logger
return current
end
unless api_params?(version)
raise "The api configuration for '#{name}' is missing data for the api version '#{self.version(version)}'"
end
new_api(version).tap do |pi|
set(version, pi)
end
end
|
54
55
56
|
# File 'lib/eco/api/session/config/api.rb', line 54
def config
@root.config
end
|
#email ⇒ Object
116
117
118
|
# File 'lib/eco/api/session/config/api.rb', line 116
def email
self["email"] || @root.default_email
end
|
#external_key ⇒ Object
104
105
106
|
# File 'lib/eco/api/session/config/api.rb', line 104
def external_key
self["external_key"] || ([:v1, :v2].include?(version) && key)
end
|
#get(version) ⇒ Object
84
85
86
|
# File 'lib/eco/api/session/config/api.rb', line 84
def get(version)
@apis[self.version(version)]
end
|
#host ⇒ Object
124
125
126
|
# File 'lib/eco/api/session/config/api.rb', line 124
def host
self["host"]
end
|
#internal_key ⇒ Object
108
109
110
|
# File 'lib/eco/api/session/config/api.rb', line 108
def internal_key
(version == :v0) && self["key"]
end
|
#key ⇒ Object
96
97
98
|
# File 'lib/eco/api/session/config/api.rb', line 96
def key
self["key"]
end
|
#local? ⇒ Boolean
138
139
140
|
# File 'lib/eco/api/session/config/api.rb', line 138
def local?
mode == :local
end
|
#logger ⇒ Object
if no low level connection messages: use IO::NULL
156
157
158
159
|
# File 'lib/eco/api/session/config/api.rb', line 156
def logger
@logger ||= ::Logger.new(IO::NULL)
log_connection? ? @logger : ::Logger.new(IO::NULL)
end
|
#mode ⇒ Symbol
Returns if running on :remote
or :local
.
134
135
136
|
# File 'lib/eco/api/session/config/api.rb', line 134
def mode
self["mode"]
end
|
#mode=(mode) ⇒ Object
129
130
131
|
# File 'lib/eco/api/session/config/api.rb', line 129
def mode=(mode)
self["mode"] = (mode == :remote)? :remote : :local
end
|
#name ⇒ Object
88
89
90
|
# File 'lib/eco/api/session/config/api.rb', line 88
def name
self["name"]
end
|
#one_off? ⇒ Boolean
92
93
94
|
# File 'lib/eco/api/session/config/api.rb', line 92
def one_off?
name.is_a?(Symbol)
end
|
#org_id ⇒ Object
112
113
114
|
# File 'lib/eco/api/session/config/api.rb', line 112
def org_id
self["org_id"]
end
|
#pass ⇒ Object
120
121
122
|
# File 'lib/eco/api/session/config/api.rb', line 120
def pass
self["pass"] || @root.default_pass
end
|
#remote? ⇒ Boolean
142
143
144
|
# File 'lib/eco/api/session/config/api.rb', line 142
def remote?
!local?
end
|
#set(version, api) ⇒ Object
80
81
82
|
# File 'lib/eco/api/session/config/api.rb', line 80
def set(version, api)
@apis[self.version(version)] = api
end
|
#user_key ⇒ Object
100
101
102
|
# File 'lib/eco/api/session/config/api.rb', line 100
def user_key
self["user_key"] || @root.default_user_key
end
|
#version(value = nil) ⇒ Object
151
152
153
|
# File 'lib/eco/api/session/config/api.rb', line 151
def version(value = nil)
self.class.to_version(value || self["version"])
end
|
#version_available?(version) ⇒ Boolean
Returns whether or not version
is available.
147
148
149
|
# File 'lib/eco/api/session/config/api.rb', line 147
def version_available?(version)
api_params?(version)
end
|