Class: BigcommerceProductAgent::Client::AbstractClient
- Inherits:
-
Object
- Object
- BigcommerceProductAgent::Client::AbstractClient
show all
- Defined in:
- lib/abstract_client.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(store_hash, client_id, access_token, params = {
endpoint: 'https://api.bigcommerce.com',
api_version: 'v3',
}) ⇒ AbstractClient
Returns a new instance of AbstractClient.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/abstract_client.rb', line 8
def initialize(
store_hash,
client_id,
access_token,
params = {
endpoint: 'https://api.bigcommerce.com',
api_version: 'v3',
}
)
= {
'X-Auth-Client' => client_id,
'X-Auth-Token' => access_token,
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
@store_hash = store_hash
@endpoint = params[:endpoint]
@api_version = params[:api_version]
end
|
Class Method Details
.uri_base ⇒ Object
28
29
30
|
# File 'lib/abstract_client.rb', line 28
def self.uri_base
@uri_base
end
|
Instance Method Details
#client ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/abstract_client.rb', line 36
def client
if !@client
@client = Faraday.new({ url: @endpoint, headers: }) do |conn|
conn.use Faraday::Response::RaiseError
conn.response :logger, nil, { headers: true, bodies: true }
conn.response :json, :content_type => 'application/json'
conn.adapter Faraday.default_adapter
end
end
return @client
end
|
#create(payload) ⇒ Object
67
68
69
|
# File 'lib/abstract_client.rb', line 67
def create(payload)
raise "not implemented yet."
end
|
#delete(payload) ⇒ Object
75
76
77
|
# File 'lib/abstract_client.rb', line 75
def delete(payload)
raise "not implemented yet."
end
|
#get(url_params = {}, params = {}) ⇒ Object
83
84
85
86
|
# File 'lib/abstract_client.rb', line 83
def get(url_params = {}, params = {})
response = client.get(uri(url_params), params)
return response.body['data']
end
|
#index(params = {}) ⇒ Object
62
63
64
65
|
# File 'lib/abstract_client.rb', line 62
def index(params = {})
response = client.get(uri, params)
return response.body['data']
end
|
#update(payload) ⇒ Object
71
72
73
|
# File 'lib/abstract_client.rb', line 71
def update(payload)
raise "not implemented yet."
end
|
#upsert(payload) ⇒ Object
79
80
81
|
# File 'lib/abstract_client.rb', line 79
def upsert(payload)
raise "not implemented yet."
end
|
#uri(params = {}) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/abstract_client.rb', line 49
def uri(params = {})
u = "/stores/#{@store_hash}/#{@api_version}/#{uri_base}"
params.each do |key,val|
u = u.gsub(":#{key.to_s}", val.to_s)
end
u = u.gsub(/(\/\:[^\/]+)/, '')
return u
end
|
#uri_base ⇒ Object
32
33
34
|
# File 'lib/abstract_client.rb', line 32
def uri_base
self.class.uri_base
end
|