Module: MangoApi::UriProvider

Overview

Provides full contextual URL details for API calls.

Instance Method Summary collapse

Instance Method Details

#provide_uri(api_method_symbol, *_params) ⇒ URI

Returns the URI for a given API endpoint. Calls ‘eval` on the declared API method string if the URL contains parameter placeholders, replacing them with data as passed into the method with the two ’param’ params.

as specified in ApiMethods

Parameters:

  • +api_method_symbol+ (Symbol)

    API endpoint symbol key,

  • +_params+ (Varargs)

Returns:

  • (URI)

    URI for the API endpoint specified by Symbol



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mangopay/api/uri_provider.rb', line 18

def provide_uri(api_method_symbol,
                *_params)
  _, unparsed = ApiMethods[api_method_symbol]
  raise("No method declared for key :#{api_method_symbol}") unless unparsed

  parsed_path = unparsed.include?('%') ? eval(unparsed) : unparsed
  config = MangoPay.configuration
  full_url = [config.root_url,
              config.api_version,
              config.client_id,
              parsed_path]
                 .join('/')
  URI(full_url)
end