Module: BerkeleyLibrary::TIND::API
- Extended by:
- Logging, Util
- Defined in:
- lib/berkeley_library/tind/api/api.rb,
lib/berkeley_library/tind/api/format.rb,
lib/berkeley_library/tind/api/search.rb,
lib/berkeley_library/tind/api/collection.rb,
lib/berkeley_library/tind/api/date_range.rb,
lib/berkeley_library/tind/api/api_exception.rb
Defined Under Namespace
Classes: APIException, APIKeyNotSet, BaseURINotSet, Collection, DateRange, Format, Search
Class Method Summary collapse
-
.api_base_uri ⇒ URI
Gets the API base URI.
-
.api_key ⇒ String?
Gets the TIND API key.
- .format_query(params) ⇒ Object
-
.format_request(uri, params = nil, method = 'GET') ⇒ Object
Returns a formatted string version of the request, suitable for logging or error messages.
-
.get(endpoint, **params, &block) ⇒ Object
Makes a GET request.
-
.uri_for(endpoint) ⇒ URI
Gets the URI for the specified API endpoint.
-
.user_agent ⇒ String
Gets the value to send in the User-Agent header.
Class Method Details
.api_base_uri ⇒ URI
Gets the API base URI.
30 31 32 33 34 |
# File 'lib/berkeley_library/tind/api/api.rb', line 30 def api_base_uri return if Config.blank?((base_uri = Config.base_uri)) URIs.append(base_uri, '/api/v1') end |
.api_key ⇒ String?
Gets the TIND API key.
18 19 20 |
# File 'lib/berkeley_library/tind/api/api.rb', line 18 def api_key BerkeleyLibrary::TIND::Config.api_key end |
.format_query(params) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/berkeley_library/tind/api/api.rb', line 98 def format_query(params) return unless params return URI.encode_www_form(params.to_hash) if params.respond_to?(:to_hash) raise ArgumentError, "Argument #{params.inspect} does not appear to be a set of query parameters" end |
.format_request(uri, params = nil, method = 'GET') ⇒ Object
Returns a formatted string version of the request, suitable for logging or error messages.
91 92 93 94 95 96 |
# File 'lib/berkeley_library/tind/api/api.rb', line 91 def format_request(uri, params = nil, method = 'GET') query_string = format_query(params) uri = URIs.append(uri, '?', query_string) if query_string "#{method} #{uri}" end |
.get(endpoint, **params) ⇒ String .get(endpoint, **params) {|body| ... } ⇒ Object
Makes a GET request.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/berkeley_library/tind/api/api.rb', line 73 def get(endpoint, **params, &block) endpoint_uri = uri_for(endpoint) raise BaseURINotSet.new(endpoint, params) if Config.blank?(endpoint_uri) logger.debug(format_request(endpoint_uri, params)) body = do_get(endpoint_uri, params) return body unless block_given? stream_response_body(body, &block) end |
.uri_for(endpoint) ⇒ URI
Gets the URI for the specified API endpoint.
40 41 42 43 44 |
# File 'lib/berkeley_library/tind/api/api.rb', line 40 def uri_for(endpoint) return if Config.blank?(api_base_uri) URIs.append(api_base_uri, endpoint) end |
.user_agent ⇒ String
Gets the value to send in the User-Agent header
24 25 26 |
# File 'lib/berkeley_library/tind/api/api.rb', line 24 def user_agent BerkeleyLibrary::TIND::Config.user_agent end |