class Harvest::Connection
Represents the link between Harvest
and Hammerhead
and the Harvest
V1 API.
Backed by ‘harvested’ gem.
Attributes
Public Class Methods
Use .instance to grab an initialied harvest connection:
connection = Harvest::Connection.instance
Because this attempts to establish a connection to the API, ensure a correctly defined 'hammerhead.yml' file exists.
Returns Harvest.hardy_client
# File lib/harvest/connection.rb, line 26 def initialize new_connection! end
Public Instance Methods
This is the hammerhead user, as defined in by the harvest credentials. It is for this user the client list will be provided, and the status report will be generated.
# File lib/harvest/connection.rb, line 35 def authenticated_user harvest.account.who_am_i end
For the specified client_id
return its Harvest
definition.
If client_id
contains alpha-characters NotImplementedError is raised.
# File lib/harvest/connection.rb, line 44 def client client_id raise NotImplementedError, 'Client by name is not implemented yet.' unless digits? client_id harvest.clients.find client_id end
Return a list of clients. Currently only options[:all]
is supported. The default behavior is to only return 'active' clients.
If the configuration file defines a list of ids to exclude, they're removed before 'active' or all clients are returned.
# File lib/harvest/connection.rb, line 56 def clients options = {} clients = harvest.clients.all.reject { |client| clients_to_exclude.include? client.id } clients = clients.select { |client| client.active == true } unless options['all'] clients end
Return a list of timesheet entries between start_date
and end_date
, inclusive.
This is for the authenticated_user
.
# File lib/harvest/connection.rb, line 67 def my_time_sheet_entries start_date, end_date harvest.reports.time_by_user authenticated_user, start_date, end_date end
Returns 'active' projects for the specified client
.
If the client
is not active, an empty list is returned.
# File lib/harvest/connection.rb, line 76 def projects_for_client client return [] unless client.active? harvest.reports.projects_by_client(client).select(&:active?) end
Return begining of work week as defined in Harvest
# File lib/harvest/connection.rb, line 85 def week_start_day authenticated_user.company.week_start_day end
Private Instance Methods
# File lib/harvest/connection.rb, line 113 def clients_to_exclude Hammerhead.configuration.clients_to_exclude end
# File lib/harvest/connection.rb, line 93 def new_connection! Hammerhead.configuration.validate! self.harvest = Harvest.hardy_client subdomain: subdomain, username: username, password: password if harvest.nil? harvest rescue StandardError => e Hammerhead.logger.fatal 'Fatal:', e end
# File lib/harvest/connection.rb, line 109 def password Hammerhead.configuration.password end
# File lib/harvest/connection.rb, line 101 def subdomain Hammerhead.configuration.subdomain end
# File lib/harvest/connection.rb, line 105 def username Hammerhead.configuration.username end