class Vtex::Client

Constants

VTEX_API_BASE

Attributes

account_name[R]
app_key[R]
app_token[R]
environment[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/vtex/client.rb, line 9
def initialize(options = {})
  @account_name = options[:account_name]
  @environment  = options[:environment]
  @app_key      = options[:app_key]
  @app_token    = options[:app_token]
end
resources() click to toggle source
# File lib/vtex/client.rb, line 22
def self.resources
  {
    products: ProductResource
  }
end

Public Instance Methods

connection() click to toggle source
# File lib/vtex/client.rb, line 16
def connection
  @faraday ||= Faraday.new connection_options do |request|
    request.adapter :net_http
  end
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/vtex/client.rb, line 28
def method_missing(name, *args, &block)
  if self.class.resources.keys.include?(name)
    resources[name] ||= self.class.resources[name].new(connection: connection)
    resources[name]
  else
    super
  end
end
resources() click to toggle source
# File lib/vtex/client.rb, line 37
def resources
  @resources ||= {}
end

Private Instance Methods

connection_options() click to toggle source
# File lib/vtex/client.rb, line 49
def connection_options
  {
    url: vtex_api,
    headers: {
      content_type: 'application/json',
      "X-VTEX-API-AppKey" => app_key,
      "X-VTEX-API-AppToken" => app_token
    }
  }
end
vtex_api() click to toggle source
# File lib/vtex/client.rb, line 43
def vtex_api
  VTEX_API_BASE.gsub(/accountName|environment/,
                     'accountName' => account_name,
                     'environment' => environment)
end