Class: Alma::Electronic::ElectronicAPI

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, HTTParty
Defined in:
lib/alma/electronic.rb

Direct Known Subclasses

Collection, Collections, Portfolio, Service, Services

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
  headers = self.class::headers
  log.info(url:, query: params)
  response = self.class::get(url, headers:, query: params, timeout:)
  @data = JSON.parse(response.body) rescue {}
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



72
73
74
# File 'lib/alma/electronic.rb', line 72

def data
  @data
end

#paramsObject (readonly)

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

Returns:

  • (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

#logObject



92
93
94
# File 'lib/alma/electronic.rb', line 92

def log
  Alma::Electronic.log
end

#resourceObject



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

#timeoutObject



88
89
90
# File 'lib/alma/electronic.rb', line 88

def timeout
  Alma.configuration.timeout
end

#urlObject



84
85
86
# File 'lib/alma/electronic.rb', line 84

def url
  "#{Alma.configuration.region}#{resource}"
end