module Sfctl::Harvest::Client
Constants
- API_V2_PATH
Public Class Methods
conn(account_id, token)
click to toggle source
# File lib/sfctl/harvest/client.rb, line 9 def self.conn(account_id, token) raise 'Please set Harvest provider before continue.' if account_id.nil? || token.nil? headers = { 'Content-Type' => 'application/json', 'Harvest-Account-ID' => account_id, 'Authorization' => "Bearer #{token}" } Faraday.new(url: "https://api.harvestapp.com/#{API_V2_PATH}", headers: headers) do |builder| builder.request :retry builder.adapter :net_http end end
parsed_response(response, key)
click to toggle source
# File lib/sfctl/harvest/client.rb, line 24 def self.parsed_response(response, key) [response.status == 200, JSON.parse(response.body)[key]] end
projects(account_id, token)
click to toggle source
# File lib/sfctl/harvest/client.rb, line 28 def self.projects(account_id, token) response = conn(account_id, token).get('projects') parsed_response(response, 'projects') end
tasks(account_id, token)
click to toggle source
# File lib/sfctl/harvest/client.rb, line 33 def self.tasks(account_id, token) response = conn(account_id, token).get('tasks') parsed_response(response, 'tasks') end
time_entries(account_id, token, params)
click to toggle source
# File lib/sfctl/harvest/client.rb, line 38 def self.time_entries(account_id, token, params) response = conn(account_id, token).get('time_entries', params) parsed_response(response, 'time_entries') end