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
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #configure(url, options = {}) ⇒ Object
- #get(path, params = {}, headers = {}, &block) ⇒ Object
- #post_data(path, payload, headers = {}, &block) ⇒ Object
- #post_url(path, params = {}, headers = {}, &block) ⇒ Object
- #put_data(path, payload, headers = {}, &block) ⇒ Object
- #put_url(path, params = {}, headers = {}, &block) ⇒ Object
Instance Attribute Details
#client ⇒ Object (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, = {}) @client = ::RestClient::Resource.new(url, ) end |
#get(path, params = {}, headers = {}, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# 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::ServerBrokeConnection, IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE => e unless (tries ||= 0) > 3; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e., response: parse_result(e.response, &block)} rescue Net::ReadTimeout, Timeout::Error => e unless (tries ||= 0) > 1; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e., response: parse_result(e.response, &block)} rescue Exception => e return {error_type: e.class.name, error_name: e., response: nil} end |
#post_data(path, payload, headers = {}, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/libis/services/rest_client.rb', line 44 def post_data(path, payload, headers = {}, &block) response = client[path].post(payload, headers, &block) parse_result response, &block rescue ::RestClient::ServerBrokeConnection, IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE => e unless (tries ||= 0) > 3; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e., response: parse_result(e.response, &block)} rescue Net::ReadTimeout, Timeout::Error => e unless (tries ||= 0) > 1; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e., response: parse_result(e.response, &block)} rescue Exception => e return {error_type: e.class.name, error_name: e., response: nil} end |
#post_url(path, params = {}, headers = {}, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/libis/services/rest_client.rb', line 31 def post_url(path, params = {}, headers = {}, &block) response = client[path].post({params: params}.merge headers, &block) parse_result response, &block rescue ::RestClient::ServerBrokeConnection, IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE => e unless (tries ||= 0) > 3; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e., response: parse_result(e.response, &block)} rescue Net::ReadTimeout, Timeout::Error => e unless (tries ||= 0) > 1; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e., response: parse_result(e.response, &block)} rescue Exception => e return {error_type: e.class.name, error_name: e., response: nil} end |
#put_data(path, payload, headers = {}, &block) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/libis/services/rest_client.rb', line 70 def put_data(path, payload, headers = {}, &block) response = client[path].put(payload, headers, &block) parse_result response, &block rescue ::RestClient::ServerBrokeConnection, IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE => e unless (tries ||= 0) > 3; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e., response: parse_result(e.response, &block)} rescue Net::ReadTimeout, Timeout::Error => e unless (tries ||= 0) > 1; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e., response: parse_result(e.response, &block)} rescue Exception => e return {error_type: e.class.name, error_name: e., response: nil} end |
#put_url(path, params = {}, headers = {}, &block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/libis/services/rest_client.rb', line 57 def put_url(path, params = {}, headers = {}, &block) response = client[path].put({params: params}.merge headers, &block) parse_result response, &block rescue ::RestClient::ServerBrokeConnection, IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE => e unless (tries ||= 0) > 3; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e., response: parse_result(e.response, &block)} rescue Net::ReadTimeout, Timeout::Error => e unless (tries ||= 0) > 1; sleep(5 ** tries); tries += 1; retry; end return {error_type: e.class.name, error_name: e., response: parse_result(e.response, &block)} rescue Exception => e return {error_type: e.class.name, error_name: e., response: nil} end |