class Harvest::Create::TimeEntry
Public Instance Methods
create(factory, client, active_user, state, kwargs)
click to toggle source
# File lib/harvest/creates.rb, line 13 def create(factory, client, active_user, state, kwargs) @state = state @active_user = active_user begin factory.time_entry( client.api_call( client.api_caller( 'time_entries', http_method: 'post', payload: time_entry_payload(kwargs).to_json, headers: { content_type: 'application/json' } ) ) ) rescue RestClient::UnprocessableEntity => e puts "Harvest Error from Create Time Entry: #{JSON.parse(e.response.body)['message']}" raise end end
Private Instance Methods
time_entry_payload(kwargs)
click to toggle source
@api private
# File lib/harvest/creates.rb, line 36 def time_entry_payload(kwargs) possible_keys = %i[spent_date notes external_reference user_id project_id task_id] payload = kwargs.each { |k, v| [k, v] if possible_keys.include?(k) }.to_h payload[:user_id] ||= @active_user.id payload[:task_id] = @state[:project_tasks][0].task.id payload[:project_id] = true_project(@state[:projects][0]).id payload end