Module: Sfctl::Harvest::Client
- Defined in:
- lib/sfctl/harvest/client.rb
Constant Summary collapse
- API_V2_PATH =
'api/v2/'.freeze
Class Method Summary collapse
- .conn(account_id, token) ⇒ Object
- .parsed_response(response, key) ⇒ Object
- .projects(account_id, token) ⇒ Object
- .tasks(account_id, token) ⇒ Object
- .time_entries(account_id, token, params) ⇒ Object
Class Method Details
.conn(account_id, token) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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) ⇒ Object
24 25 26 |
# 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) ⇒ Object
28 29 30 31 |
# 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) ⇒ Object
33 34 35 36 |
# 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) ⇒ Object
38 39 40 41 |
# 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 |