Class: BsellerRuby::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/bseller_ruby/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(params) ⇒ Base
Returns a new instance of Base.
13
14
15
16
17
18
|
# File 'lib/bseller_ruby/base.rb', line 13
def initialize(params)
params.each do |key, value|
instance_variable_set "@#{key}", value
define_singleton_method(key) { instance_variable_get "@#{key}" }
end
end
|
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
11
12
13
|
# File 'lib/bseller_ruby/base.rb', line 11
def response
@response
end
|
Class Method Details
.call(method, params) ⇒ Object
35
36
37
38
39
|
# File 'lib/bseller_ruby/base.rb', line 35
def call(method, params)
@method = method
params.merge!(authentication) if params.class.eql?(Hash)
Response.new method, api.call(method, message: params)
end
|
.collection_name ⇒ Object
31
32
33
|
# File 'lib/bseller_ruby/base.rb', line 31
def collection_name
@collection_name = "#{resource_name}s"
end
|
.create(method, params) ⇒ Object
41
42
43
|
# File 'lib/bseller_ruby/base.rb', line 41
def create(method, params)
new response: call(method, params)
end
|
.get(resource, params = {}) ⇒ Object
45
46
47
|
# File 'lib/bseller_ruby/base.rb', line 45
def get(resource, params = {})
json_parse(execute(:get, "#{resource}?#{to_params(params)}"))
end
|
.post(path, body, &block) ⇒ Object
49
50
51
|
# File 'lib/bseller_ruby/base.rb', line 49
def post(path, body, &block)
json_parse(execute(:post, path, body: body, &block))
end
|
.put(resource, path, payload) ⇒ Object
53
54
55
|
# File 'lib/bseller_ruby/base.rb', line 53
def put(resource, path, payload)
json_parse(execute(:put, "#{resource}/#{path}?a=1", body: payload))
end
|