def request(method, path, token, query={}, payload={})
      path = "/#{path}" unless path.start_with?('/')
      header = {
        authorization: "Bearer #{token.access_token}",
        content_type: :json,
        accept: :json,
        params: query
      }
      opts = {
        method: method,
        url: "https://api.infusionsoft.com/crm/rest/v1" + path,
        headers: header
      }
      opts.merge!( { payload: payload.to_json }) unless payload.empty?
      resp = RestClient::Request.execute(opts)
    rescue RestClient::ExceptionWithResponse => err
      # log error?
    else
      return JSON.parse(resp.body)
    end
def request(method, path, token, query={}, payload={})
      path = "/#{path}" unless path.start_with?('/')
      header = {
        authorization: "Bearer #{token.access_token}",
        content_type: :json,
        accept: :json,
        params: query
      }
      opts = {
        method: method,
        url: "https://api.infusionsoft.com/crm/rest/v1" + path,
        headers: header
      }
      opts.merge!( { payload: payload.to_json }) unless payload.empty?
      resp = RestClient::Request.execute(opts)
    rescue RestClient::ExceptionWithResponse => err
      # log error?
    else
      return JSON.parse(resp.body)
    end
Perform request