Class: Vtex::Client
- Inherits:
-
Object
- Object
- Vtex::Client
- Defined in:
- lib/vtex/client.rb
Constant Summary collapse
- VTEX_API_BASE =
"http://accountName.environment.com.br"
Instance Attribute Summary collapse
-
#account_name ⇒ Object
readonly
Returns the value of attribute account_name.
-
#app_key ⇒ Object
readonly
Returns the value of attribute app_key.
-
#app_token ⇒ Object
readonly
Returns the value of attribute app_token.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Class Method Summary collapse
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(name, *args, &block) ⇒ Object
- #resources ⇒ Object
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( = {}) @account_name = [:account_name] @environment = [:environment] @app_key = [:app_key] @app_token = [: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_name ⇒ Object (readonly)
Returns the value of attribute account_name.
7 8 9 |
# File 'lib/vtex/client.rb', line 7 def account_name @account_name end |
#app_key ⇒ Object (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_token ⇒ Object (readonly)
Returns the value of attribute app_token.
7 8 9 |
# File 'lib/vtex/client.rb', line 7 def app_token @app_token end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
7 8 9 |
# File 'lib/vtex/client.rb', line 7 def environment @environment end |
Class Method Details
.resources ⇒ Object
22 23 24 25 26 |
# File 'lib/vtex/client.rb', line 22 def self.resources { products: ProductResource } end |
Instance Method Details
#connection ⇒ Object
16 17 18 19 20 |
# File 'lib/vtex/client.rb', line 16 def connection @faraday ||= Faraday.new do |request| request.adapter :net_http end end |
#resources ⇒ Object
37 38 39 |
# File 'lib/vtex/client.rb', line 37 def resources @resources ||= {} end |