Class: Gladly::Api::Client
- Inherits:
-
Object
- Object
- Gladly::Api::Client
show all
- Includes:
- ErrorHandling
- Defined in:
- app/services/gladly/api/client.rb
Instance Method Summary
collapse
#net_http_errors, #not_implemented_error, #parse_error
Constructor Details
#initialize(payload: {}) ⇒ Client
Returns a new instance of Client.
10
11
12
13
14
15
|
# File 'app/services/gladly/api/client.rb', line 10
def initialize(payload: {})
@api_username = SpreeGladly::Config.gladly_api_username
@api_key = SpreeGladly::Config.gladly_api_key
@base_url = SpreeGladly::Config.gladly_api_base_url
@payload = payload
end
|
Instance Method Details
#call ⇒ Object
17
18
19
20
21
|
# File 'app/services/gladly/api/client.rb', line 17
def call
return if base_url.blank?
perform_request
end
|
23
24
25
|
# File 'app/services/gladly/api/client.rb', line 23
def perform_request
post_request if request_method.eql?(:post)
end
|
#post_request ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/services/gladly/api/client.rb', line 27
def post_request
uri = URI(request_url)
http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = 20
http.use_ssl = true
request = Net::HTTP::Post.new(uri.path)
request.basic_auth(api_username, api_key)
request.body = payload.to_json
response = http.request(request)
formatted_response(response: response)
end
|
#request_method ⇒ Object
47
48
49
|
# File 'app/services/gladly/api/client.rb', line 47
def request_method
not_implemented_error
end
|
#request_url ⇒ Object
43
44
45
|
# File 'app/services/gladly/api/client.rb', line 43
def request_url
"#{base_url}#{resource_url}"
end
|
#resource_url ⇒ Object
51
52
53
|
# File 'app/services/gladly/api/client.rb', line 51
def resource_url
not_implemented_error
end
|