Class: Berbix::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/berbix.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/berbix.rb', line 61

def initialize(opts={})
  @client_id = opts[:client_id]
  @client_secret = opts[:client_secret]
  @api_host = api_host(opts)
  @http_client = opts[:http_client] || NetHTTPClient.new

  if @client_id.nil?
    raise ':client_id must be provided when instantiating Berbix client'
  end
  if @client_secret.nil?
    raise ':client_secret must be provided when instantiating Berbix client'
  end
end

Instance Method Details

#create_continuation(user_tokens) ⇒ Object



101
102
103
104
# File 'lib/berbix.rb', line 101

def create_continuation(user_tokens)
  result = token_auth_request(:post, user_tokens, '/v0/continuations')
  result['value']
end

#create_user(opts = {}) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/berbix.rb', line 75

def create_user(opts={})
  payload = {}
  payload[:email] = opts[:email] unless opts[:email].nil?
  payload[:phone] = opts[:phone] unless opts[:phone].nil?
  payload[:customer_uid] = opts[:customer_uid] unless opts[:customer_uid].nil?
  fetch_tokens('/v0/users', payload)
end

#exchange_code(code) ⇒ Object



90
91
92
93
94
95
# File 'lib/berbix.rb', line 90

def exchange_code(code)
  fetch_tokens('/v0/tokens', {
    'code' => code,
    'grant_type' => 'authorization_code',
  })
end

#fetch_user(user_tokens) ⇒ Object



97
98
99
# File 'lib/berbix.rb', line 97

def fetch_user(user_tokens)
  token_auth_request(:get, user_tokens, '/v0/users')
end

#refresh_tokens(user_tokens) ⇒ Object



83
84
85
86
87
88
# File 'lib/berbix.rb', line 83

def refresh_tokens(user_tokens)
  fetch_tokens('/v0/tokens', {
    'refresh_token' => user_tokens.refresh_token,
    'grant_type' => 'refresh_token',
  })
end