Class: Harvest::TimeLogger
- Inherits:
-
Object
- Object
- Harvest::TimeLogger
- Defined in:
- lib/harvest/time_logger.rb
Constant Summary collapse
- BASE_URL =
'https://api.harvestapp.com/v2'.freeze
- DEFAULT_USER_AGENT =
'Oozou Harvest CLI ([email protected])'.freeze
- WEB_DEVELOPMENT_TASK_ID =
10740736
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config) ⇒ TimeLogger
constructor
A new instance of TimeLogger.
- #log(task_title:, task_url: nil) ⇒ Object
- #projects ⇒ Object
Constructor Details
#initialize(config) ⇒ TimeLogger
Returns a new instance of TimeLogger.
12 13 14 15 |
# File 'lib/harvest/time_logger.rb', line 12 def initialize(config) @config = config config['task_id'] ||= WEB_DEVELOPMENT_TASK_ID end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/harvest/time_logger.rb', line 10 def config @config end |
Instance Method Details
#log(task_title:, task_url: nil) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/harvest/time_logger.rb', line 32 def log(task_title:, task_url: nil) RestClient.post( "#{BASE_URL}/time_entries", time_log_payload(task_title, task_url).to_json, headers ) end |
#projects ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/harvest/time_logger.rb', line 17 def projects response = RestClient::Request.execute( method: :get, url: "#{BASE_URL}/users/me/project_assignments", headers: headers ) JSON.parse(response.body)['project_assignments'].map do |project_assignment| { name: project_assignment['project']['name'], id: project_assignment['project']['id'] } end end |