module Libis::Services::RestClient
Attributes
client[R]
Public Instance Methods
configure(url, options = {})
click to toggle source
# 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)
click to toggle source
# 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.message, 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.message, response: parse_result(e.response, &block)} rescue Exception => e return {error_type: e.class.name, error_name: e.message, response: nil} end
post_data(path, payload, headers = {}, &block)
click to toggle source
# 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.message, 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.message, response: parse_result(e.response, &block)} rescue Exception => e return {error_type: e.class.name, error_name: e.message, response: nil} end
post_url(path, params = {}, headers = {}, &block)
click to toggle source
# 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.message, 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.message, response: parse_result(e.response, &block)} rescue Exception => e return {error_type: e.class.name, error_name: e.message, response: nil} end
put_data(path, payload, headers = {}, &block)
click to toggle source
# 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.message, 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.message, response: parse_result(e.response, &block)} rescue Exception => e return {error_type: e.class.name, error_name: e.message, response: nil} end
put_url(path, params = {}, headers = {}, &block)
click to toggle source
# 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.message, 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.message, response: parse_result(e.response, &block)} rescue Exception => e return {error_type: e.class.name, error_name: e.message, response: nil} end
Protected Instance Methods
parse_result(response) { |response| ... }
click to toggle source
# File lib/libis/services/rest_client.rb, line 85 def parse_result(response) block_given? ? yield(response) : result_parser(response) end
result_parser(response)
click to toggle source
# File lib/libis/services/rest_client.rb, line 89 def result_parser(response) response end