Module: Libis::Services::RestClient

Included in:
Alma::SruService, Alma::WebService, Primo::Limo, Primo::Search, Libis::Services::Rosetta::PdsHandler
Defined in:
lib/libis/services/rest_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



12
13
14
# File 'lib/libis/services/rest_client.rb', line 12

def client
  @client
end

Instance Method Details

#configure(url, options = {}) ⇒ Object



14
15
16
# File 'lib/libis/services/rest_client.rb', line 14

def configure(url, options = {})
  @client = ::RestClient::Resource.new(url, options)
end

#get(path, params = {}, headers = {}, &block) ⇒ Object



18
19
20
21
22
23
# File 'lib/libis/services/rest_client.rb', line 18

def get(path, params = {}, headers = {}, &block)
  response = client[path].get({params: params}.merge headers, &block)
  parse_result response, &block
rescue ::RestClient::Exception => e
  return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)}
end

#post_data(path, payload, headers = {}, &block) ⇒ Object



32
33
34
35
36
37
# File 'lib/libis/services/rest_client.rb', line 32

def post_data(path, payload, headers = {}, &block)
  response = client[path].post(payload, headers, &block)
  parse_result response, &block
rescue ::RestClient::Exception => e
  return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)}
end

#post_url(path, params = {}, headers = {}, &block) ⇒ Object



25
26
27
28
29
30
# File 'lib/libis/services/rest_client.rb', line 25

def post_url(path, params = {}, headers = {}, &block)
  response = client[path].post({params: params}.merge headers, &block)
  parse_result response, &block
rescue ::RestClient::Exception => e
  return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)}
end

#put_data(path, payload, headers = {}, &block) ⇒ Object



46
47
48
49
50
51
# File 'lib/libis/services/rest_client.rb', line 46

def put_data(path, payload, headers = {}, &block)
  response = client[path].put(payload, headers, &block)
  parse_result response, &block
rescue ::RestClient::Exception => e
  return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)}
end

#put_url(path, params = {}, headers = {}, &block) ⇒ Object



39
40
41
42
43
44
# File 'lib/libis/services/rest_client.rb', line 39

def put_url(path, params = {}, headers = {}, &block)
  response = client[path].put({params: params}.merge headers, &block)
  parse_result response, &block
rescue ::RestClient::Exception => e
  return {error_type: e.class.name, error_name: e.message, response: parse_result(e.response, &block)}
end