class Harvest::HTTP::Api
Make
Public Class Methods
new(domain:, account_id:, personal_token:)
click to toggle source
# File lib/harvest/httpclient.rb, line 58 def initialize(domain:, account_id:, personal_token:) @domain = domain @account_id = account_id @personal_token = personal_token end
Public Instance Methods
api_call(struct)
click to toggle source
Make a api call to an endpoint. @api public @param struct [ApiCall]
# File lib/harvest/httpclient.rb, line 75 def api_call(struct) JSON.parse( send(struct.http_method.to_sym, struct).tap do # require 'pry'; binding.pry end ) end
api_caller(path, http_method: 'get', param: {}, payload: nil, headers: {})
click to toggle source
# File lib/harvest/httpclient.rb, line 112 def api_caller(path, http_method: 'get', param: {}, payload: nil, headers: {}) ApiCall.new( { path: path, http_method: http_method.to_sym, params: param, payload: payload, headers: headers } ) end
client()
click to toggle source
# File lib/harvest/httpclient.rb, line 64 def client Harvest::HTTP::Client .new .domain(@domain) .headers(@personal_token, @account_id) .client end
pagination(struct)
click to toggle source
Pagination through request @api public @param struct [Struct::Pagination]
# File lib/harvest/httpclient.rb, line 86 def pagination(struct) struct.param[:page] = struct.page_count page = api_call(struct.to_api_call).tap do # require 'pry'; binding.pry end struct.rows.concat(page[struct.data_key]) return struct.rows if struct.page_count >= page['total_pages'] struct.page_count += 1 pagination(struct) end
paginator(http_method: 'get', page_count: 1, param: {}, entries: [], headers: {})
click to toggle source
Create
Paginaation struct message to pass to pagination call
# File lib/harvest/httpclient.rb, line 100 def paginator(http_method: 'get', page_count: 1, param: {}, entries: [], headers: {}) Struct::Pagination.new( { http_method: http_method, param: param, rows: entries, page_count: page_count, headers: headers } ) end
Private Instance Methods
delete(struct)
click to toggle source
# File lib/harvest/httpclient.rb, line 130 def delete(struct) client[struct.path].delete(struct.headers) end
get(struct)
click to toggle source
# File lib/harvest/httpclient.rb, line 126 def get(struct) client[struct.path].get(struct.headers) end
patch(struct)
click to toggle source
# File lib/harvest/httpclient.rb, line 138 def patch(struct) client[struct.path].patch(struct.payload, struct.headers) end
post(struct)
click to toggle source
# File lib/harvest/httpclient.rb, line 134 def post(struct) client[struct.path].post(struct.payload, struct.headers) end