Class: Harvest::Connection
- Inherits:
-
Object
- Object
- Harvest::Connection
- Includes:
- Hammerhead::Utils, Singleton
- Defined in:
- lib/harvest/connection.rb
Overview
:markup: markdown Represents the link between Harvest and Hammerhead and the Harvest V1 API.
Backed by [‘harvested’](rubygems.org/gems/harvested) gem.
Instance Method Summary collapse
-
#authenticated_user ⇒ Object
This is the hammerhead user, as defined in by the harvest credentials.
-
#client(client_id) ⇒ Object
For the specified
client_id
return its Harvest definition. -
#clients(options = {}) ⇒ Object
Return a list of clients.
-
#initialize ⇒ Connection
constructor
Use .instance to grab an initialied harvest connection: connection = Harvest::Connection.instance.
-
#my_time_sheet_entries(start_date, end_date) ⇒ Object
Return a list of timesheet entries between
start_date
andend_date
, inclusive. -
#projects_for_client(client) ⇒ Object
Returns ‘active’ projects for the specified
client
. -
#week_start_day ⇒ Object
Return begining of work week as defined in Harvest.
Methods included from Hammerhead::Utils
Constructor Details
#initialize ⇒ Connection
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
26 27 28 |
# File 'lib/harvest/connection.rb', line 26 def initialize new_connection! end |
Instance Method Details
#authenticated_user ⇒ Object
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.
35 36 37 |
# File 'lib/harvest/connection.rb', line 35 def authenticated_user harvest.account.who_am_i end |
#client(client_id) ⇒ Object
For the specified client_id
return its Harvest definition.
If client_id
contains alpha-characters NotImplementedError is raised.
44 45 46 47 48 |
# 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 |
#clients(options = {}) ⇒ Object
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.
57 58 59 60 61 |
# File 'lib/harvest/connection.rb', line 57 def clients = {} clients = harvest.clients.all.reject { |client| clients_to_exclude.include? client.id } clients = clients.select { |client| client.active == true } unless ['all'] clients end |
#my_time_sheet_entries(start_date, end_date) ⇒ Object
Return a list of timesheet entries between start_date
and end_date
, inclusive.
This is for the authenticated_user
.
68 69 70 |
# File 'lib/harvest/connection.rb', line 68 def my_time_sheet_entries start_date, end_date harvest.reports.time_by_user authenticated_user, start_date, end_date end |
#projects_for_client(client) ⇒ Object
Returns ‘active’ projects for the specified client
.
If the client
is not active, an empty list is returned.
77 78 79 80 81 |
# File 'lib/harvest/connection.rb', line 77 def projects_for_client client return [] unless client.active? harvest.reports.projects_by_client(client).select(&:active?) end |
#week_start_day ⇒ Object
Return begining of work week as defined in Harvest
86 87 88 |
# File 'lib/harvest/connection.rb', line 86 def week_start_day authenticated_user.company.week_start_day end |