Class: Vtex::Client

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

Constant Summary collapse

VTEX_API_BASE =
"http://accountName.environment.com.br"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



28
29
30
31
32
33
34
35
# 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

Instance Attribute Details

#account_nameObject (readonly)

Returns the value of attribute account_name.



7
8
9
# File 'lib/vtex/client.rb', line 7

def 
  @account_name
end

#app_keyObject (readonly)

Returns the value of attribute app_key.



7
8
9
# File 'lib/vtex/client.rb', line 7

def app_key
  @app_key
end

#app_tokenObject (readonly)

Returns the value of attribute app_token.



7
8
9
# File 'lib/vtex/client.rb', line 7

def app_token
  @app_token
end

#environmentObject (readonly)

Returns the value of attribute environment.



7
8
9
# File 'lib/vtex/client.rb', line 7

def environment
  @environment
end

Class Method Details

.resourcesObject



22
23
24
25
26
# File 'lib/vtex/client.rb', line 22

def self.resources
  {
    products: ProductResource
  }
end

Instance Method Details

#connectionObject



16
17
18
19
20
# File 'lib/vtex/client.rb', line 16

def connection
  @faraday ||= Faraday.new connection_options do |request|
    request.adapter :net_http
  end
end

#resourcesObject



37
38
39
# File 'lib/vtex/client.rb', line 37

def resources
  @resources ||= {}
end