Method: WebPay#initialize

Defined in:
lib/webpay.rb

#initialize(auth_token, options = {}) ⇒ WebPay

Initialize client

Parameters:

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

    options



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/webpay.rb', line 23

def initialize(auth_token, options = {})
  options = options.each_with_object({}) { |kv, obj| k,v = kv; obj[k.to_s] = v }

  connection_options = options['faraday_options'] || {}
  connection_options['headers'] = {

    "Content-Type" => "application/json",

    "Accept" => "application/json",

    "User-Agent" => "Apipa-webpay/3.2.3 ruby",

    "Accept-Language" => "en",
  }
  connection_options['url'] = options['api_base'] || 'https://api.webpay.jp/v1'
  @conn = Faraday.new(connection_options) do |builder|
    builder.request :url_encoded
    builder.adapter Faraday.default_adapter
  end


  @conn.authorization(:Bearer, auth_token)

  @charge = WebPay::Charge.new(self)
  @customer = WebPay::Customer.new(self)
  @token = WebPay::Token.new(self)
  @event = WebPay::Event.new(self)
  @shop = WebPay::Shop.new(self)
  @recursion = WebPay::Recursion.new(self)
  @account = WebPay::Account.new(self)
end