class Foederati::Provider::Request

Makes HTTP requests to provider APIs.

Used by `Foederati::Provider#search`.

Attributes

provider[R]

Public Class Methods

new(provider) click to toggle source

@param provider [Foederati::Provider] the provider to make an API request for

# File lib/foederati/provider/request.rb, line 15
def initialize(provider)
  @provider = provider
end

Public Instance Methods

api_url(**params) click to toggle source

Construct the URL for making an API request

@param params [Hash] query-specific URL parameters @return [String] the provider's API URL with all necessary params

# File lib/foederati/provider/request.rb, line 47
def api_url(**params)
  local_params = params.dup
  local_params.delete(:query) if local_params[:query].blank? && provider.default_params.query.present?
  format(urls.api, default_params.merge(local_params))
end
default_params() click to toggle source

Default parameters to add to query-specific ones when querying the provider's API.

For instance, API key and limit.

@return [Hash]

# File lib/foederati/provider/request.rb, line 36
def default_params
  { api_key: Foederati.api_keys.send(id) }.
    merge(Foederati.defaults.to_h).
    merge(provider.default_params.to_h)
end
execute(**params) click to toggle source

Executes a query against the provider's API

@param params [Hash] query-specific URL parameters @return [Foederati::Response] response from the API

# File lib/foederati/provider/request.rb, line 24
def execute(**params)
  faraday_response = connection.get(api_url(params))
  Response.new(provider, faraday_response)
end