Module: Sfctl::Harvest::Client

Defined in:
lib/sfctl/harvest/client.rb

Constant Summary collapse

API_V2_PATH =
'api/v2/'.freeze

Class Method Summary collapse

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(, token)
  raise 'Please set Harvest provider before continue.' if .nil? || token.nil?

  headers = {
    'Content-Type' => 'application/json',
    'Harvest-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(, token)
  response = conn(, 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(, token)
  response = conn(, 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(, token, params)
  response = conn(, token).get('time_entries', params)
  parsed_response(response, 'time_entries')
end