Method: Voog::Client#initialize

Defined in:
lib/voog_api/client.rb

#initialize(host = Voog.host, api_token = Voog.api_token, options = {}) ⇒ Client

Initialize Voog API client.

Examples:

Initialize client

client = Voog::Client.new('example.com', 'afcf30182aecfc8155d390d7d4552d14', protocol: :http, raise_on_error: false)

Parameters:

  • host (String) (defaults to: Voog.host)

    a Voog site host.

  • api_token (String) (defaults to: Voog.api_token)

    a Voog site API token.

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

    a customizable set of options

Options Hash (options):

  • :protocol (String)

    endpoint protocol (“http” or “https”). Defaults to “http”.

  • :auto_paginate (String)

    enable auto pagination for list requests. Defaults to “false”.

  • :per_page (String)

    set default “per_page” value for list requests. Defaults to “nil”.

  • :raise_on_error (Boolean)

    interrupts program with error (“Faraday::Error”) when request response code is between “400” and “600” (default is “false”).



71
72
73
74
75
76
77
78
79
# File 'lib/voog_api/client.rb', line 71

def initialize(host = Voog.host, api_token = Voog.api_token, options = {})
  @host = host
  @api_token = api_token
  @options = options
  @protocol = options[:protocol].to_s.downcase == 'https' ? 'https' : 'http'
  @auto_paginate = options.fetch(:auto_paginate, Voog.auto_paginate)
  @per_page = options.fetch(:per_page, Voog.per_page)
  @raise_on_error = options.fetch(:raise_on_error, true)
end