Class: WrAPI::API

Inherits:
Object
  • Object
show all
Includes:
Authentication, Connection, Request
Defined in:
lib/wrapi/api.rb

Overview

The API class is responsible for managing the configuration and connections for the WrAPI library. It includes modules for handling connections, requests, and authentication.

Examples:

Creating a new API instance

api = WrAPI::API.new(api_key: 'your_api_key')

Accessing the configuration

config = api.config
puts config[:api_key]

See Also:

Constant Summary

Constants included from Request

Request::CONTENT_TYPE_HDR

Instance Method Summary collapse

Methods included from Authentication

#api_auth, #api_refresh

Methods included from Request

#delete, #get, #get_paged, #is_json?, #post, #put

Constructor Details

#initialize(options = {}) ⇒ WrAPI::API

Initializes a new API object with the given options.

Parameters:

  • options (Hash) (defaults to: {})

    A hash of options to configure the API object. The options are merged with the default options from ‘WrAPI.options`.

Options Hash (options):

  • :api_key (String)

    The API key for authentication.

  • :api_secret (String)

    The API secret for authentication.

  • :endpoint (String)

    The API endpoint URL.

  • :user_agent (String)

    The User-Agent header for HTTP requests.

  • :timeout (Integer)

    The timeout for HTTP requests.

  • :open_timeout (Integer)

    The open timeout for HTTP requests.



41
42
43
44
45
46
# File 'lib/wrapi/api.rb', line 41

def initialize(options = {})
  options = WrAPI.options.merge(options)
  WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

Instance Method Details

#configHash

Returns a hash of configuration options and their values. Iterates over each valid configuration key defined in WrAPI::Configuration::VALID_OPTIONS_KEYS, and assigns the corresponding value by calling the method with the same name as the key.

Returns:

  • (Hash)

    A hash containing the configuration options and their values.



53
54
55
56
57
58
59
# File 'lib/wrapi/api.rb', line 53

def config
  conf = {}
  WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
    conf[key] = send key
  end
  conf
end