Class: Alma::Electronic::ElectronicAPI
- Inherits:
-
Object
- Object
- Alma::Electronic::ElectronicAPI
show all
- Extended by:
- Forwardable
- Includes:
- Enumerable, HTTParty
- Defined in:
- lib/alma/electronic.rb
Constant Summary
collapse
- REQUIRED_PARAMS =
[]
- RESOURCE =
"/almaws/v1/electronic"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(params = {}) ⇒ ElectronicAPI
Returns a new instance of ElectronicAPI.
76
77
78
79
80
81
82
|
# File 'lib/alma/electronic.rb', line 76
def initialize(params = {})
@params = params
= self.class::
log.info(url:, query: params)
response = self.class::get(url, headers:, query: params, timeout:)
@data = JSON.parse(response.body) rescue {}
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
72
73
74
|
# File 'lib/alma/electronic.rb', line 72
def data
@data
end
|
#params ⇒ Object
Returns the value of attribute params.
72
73
74
|
# File 'lib/alma/electronic.rb', line 72
def params
@params
end
|
Class Method Details
.can_process?(params = {}) ⇒ Boolean
109
110
111
112
113
|
# File 'lib/alma/electronic.rb', line 109
def self.can_process?(params = {})
type = self.to_s.split("::").last.parameterize
self::REQUIRED_PARAMS.all? { |param| params.include? param } &&
params[:type].blank? || params[:type] == type
end
|
Instance Method Details
#resource ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/alma/electronic.rb', line 96
def resource
@params.inject(self.class::RESOURCE) { |path, param|
key = param.first
value = param.last
if key && value
path.gsub(/:#{key}/, value.to_s)
else
path
end
}
end
|
#timeout ⇒ Object
88
89
90
|
# File 'lib/alma/electronic.rb', line 88
def timeout
Alma.configuration.timeout
end
|
#url ⇒ Object
84
85
86
|
# File 'lib/alma/electronic.rb', line 84
def url
"#{Alma.configuration.region}#{resource}"
end
|