lib/termii_ruby/client.rb in termii_ruby-0.1.0 vs lib/termii_ruby/client.rb in termii_ruby-0.1.1
- old
+ new
@@ -4,10 +4,14 @@
require "faraday"
require "faraday/retry"
require_relative "abstract_client"
module TermiiRuby
+ #
+ # @author Collins Ugwu
+ # Client class to make request to Termii endpoints
+ #
class Client < TermiiRuby::AbstractClient
def initialize(api_key)
@api_key = api_key
@connection = faraday_connection
end
@@ -22,30 +26,31 @@
req.params[key.to_s] = value.to_s
end
end
end
- {
- status: response.status,
- data: response.body
- }
+ request_response(response)
end
def make_post_request(endpoint, args = {})
url = request_url(endpoint)
args[:api_key] = @api_key
response = @connection.post(url) do |req|
req.headers["Content-Type"] = "application/json"
req.body = args.to_json
end
+ request_response(response)
+ end
+
+ private
+
+ def request_response(response)
{
status: response.status,
data: response.body
}
end
-
- private
def request_url(endpoint)
"#{base_url}/#{endpoint}"
end