class Ecommerce::Client

Attributes

secret[R]
token[R]

Public Class Methods

new(token, secret) click to toggle source
# File lib/ecommerce/client.rb, line 8
def initialize(token, secret)
  @token = token
  @secret = secret
end

Public Instance Methods

authenticated?(plan) click to toggle source
# File lib/ecommerce/client.rb, line 13
def authenticated?(plan)
  get("/api/orders/#{plan}/") { |response| response.code == 200 }
rescue RequestError => e
  raise e unless [401, 403].include?(e.code)
  false
end

Private Instance Methods

authorization_hash() click to toggle source
# File lib/ecommerce/client.rb, line 41
def authorization_hash
  ::Base64.strict_encode64("#{token}:#{secret}")
end
send_request(method, path, options, &block) click to toggle source
# File lib/ecommerce/client.rb, line 28
def send_request(method, path, options, &block)
  request  = Request.new(options.merge!({
    method: method,
    authorization_hash: authorization_hash,
    url: "#{Ecommerce.configuration.url}#{path}",
    user_agent: Ecommerce.configuration.user_agent
  }))

  response = Response.new(request.run)

  response.resolve!(&block)
end