require 'bundler/setup' require 'httparty' class APIClient def initialize(http_client:HTTParty) @base_uri = ENV['API_URI'] @auth = {username:'snap', password:ENV['AUTH_TOKEN']} @http_client = http_client end def get(path:path) body = @http_client.get("#{@base_uri}#{encoded path}", {basic_auth:@auth}).body JSON.parse(body, quirks_mode:true) end def delete(path:path) @http_client.delete("#{@base_uri}#{encoded path}", {basic_auth:@auth}) end 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 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 def encoded path path.gsub ' ', '%20' end end