Class: AlephApi::RestfulApiClient
- Inherits:
-
Object
- Object
- AlephApi::RestfulApiClient
- Defined in:
- lib/aleph_api/restful_api_client.rb
Defined Under Namespace
Constant Summary collapse
- RESTFUL_API_DEFAULT_PORT =
1891
- RESTFUL_API_DEFAULT_ROOT_PATH =
"/rest-dlf"
- RESTFUL_API_DEFAULT_SCHEME =
"http"
- @@faraday_adapter =
don’s use a constant here, because faraday treats them diffrently
defined?(::Patron) ? :patron : ::Faraday.default_adapter
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#http(method, path, options = {}) ⇒ Object
inter-client api.
-
#initialize(options = {}) ⇒ RestfulApiClient
constructor
A new instance of RestfulApiClient.
- #patron(patron_id) ⇒ Object
- #record(record_id) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ RestfulApiClient
Returns a new instance of RestfulApiClient.
26 27 28 29 30 31 |
# File 'lib/aleph_api/restful_api_client.rb', line 26 def initialize( = {}) .symbolize_keys.try do || @host = ([:host] || ENV["ALEPH_RESTFUL_API_HOST"] || ENV["ALEPH_API_HOST"]).try(:strip) @url = ([:url] || ENV["ALEPH_RESTFUL_API_URL"]).try(:strip) end end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
19 20 21 |
# File 'lib/aleph_api/restful_api_client.rb', line 19 def host @host end |
#url ⇒ Object
Returns the value of attribute url.
20 21 22 |
# File 'lib/aleph_api/restful_api_client.rb', line 20 def url @url end |
Instance Method Details
#http(method, path, options = {}) ⇒ Object
inter-client api
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/aleph_api/restful_api_client.rb', line 42 def http(method, path, = {}) # http://www.intridea.com/blog/2012/3/12/faraday-one-http-client-to-rule-them-all connection = ::Faraday.new do |_builder| _builder.request :url_encoded _builder.use AlephApi::Faraday::Response::EnforceUtf8EncodedBody _builder.adapter @@faraday_adapter end connection.send(method, "#{self.url}#{path}", ) do |_request| # some http libraries (e.g. patron) have tight connection timeouts which # may lead to (unnecessary) errors when used with aleph, so we raise 'em _request..open_timeout = 20 # seconds end end |