class APIClient
Public Class Methods
new(http_client:HTTParty)
click to toggle source
# File lib/allegro_api_client.rb, line 6 def initialize(http_client:HTTParty) @base_uri = ENV['API_URI'] @auth = {username:'snap', password:ENV['AUTH_TOKEN']} @http_client = http_client end
Public Instance Methods
delete(path:path)
click to toggle source
# File lib/allegro_api_client.rb, line 17 def delete(path:path) @http_client.delete("#{@base_uri}#{encoded path}", {basic_auth:@auth}) end
encoded(path)
click to toggle source
# File lib/allegro_api_client.rb, line 31 def encoded path URI.escape(path) end
get(path:path)
click to toggle source
# File lib/allegro_api_client.rb, line 12 def get(path:path) body = @http_client.get("#{@base_uri}#{encoded path}", {basic_auth:@auth}).body JSON.parse(body, quirks_mode:true) end
patch(path:path, body:body)
click to toggle source
# File lib/allegro_api_client.rb, line 21 def patch(path:path, body:body) @http_client.patch("#{@base_uri}#{encoded path}", :basic_auth =>@auth, :body => body.to_json, headers:{ 'Content-Type' => 'application/json' }).body end
post(path:path, body:body)
click to toggle source
# File lib/allegro_api_client.rb, line 26 def post(path:path, body:body) @http_client.post("#{@base_uri}#{encoded path}", :basic_auth =>@auth, :body => body.to_json, headers:{ 'Content-Type' => 'application/json' }).body end