class Alma::Electronic::ElectronicAPI
Constants
- REQUIRED_PARAMS
- RESOURCE
Attributes
data[R]
params[R]
Public Class Methods
can_process?(params = {})
click to toggle source
# 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
new(params = {})
click to toggle source
# File lib/alma/electronic.rb, line 76 def initialize(params = {}) @params = params headers = self.class::headers log.info(url: url, query: params) response = self.class::get(url, headers: headers, query: params, timeout: timeout) @data = JSON.parse(response.body) rescue {} end
Private Class Methods
apikey()
click to toggle source
# File lib/alma/electronic.rb, line 122 def self.apikey Alma.configuration.apikey end
headers()
click to toggle source
# File lib/alma/electronic.rb, line 116 def self.headers { "Authorization": "apikey #{apikey}", "Accept": "application/json", "Content-Type": "application/json" } end
Public Instance Methods
log()
click to toggle source
# File lib/alma/electronic.rb, line 92 def log Alma::Electronic.log end
resource()
click to toggle source
# 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()
click to toggle source
# File lib/alma/electronic.rb, line 88 def timeout Alma.configuration.timeout end
url()
click to toggle source
# File lib/alma/electronic.rb, line 84 def url "#{Alma.configuration.region}#{resource}" end