Class: Harvest::Create::TimeEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/harvest/creates.rb

Instance Method Summary collapse

Instance Method Details

#create(factory, client, active_user, state, kwargs) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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