class Dovico::TimeEntry

Constants

URL_PATH

Public Class Methods

batch_create!(assignments) click to toggle source
# File lib/dovico/model/time_entry.rb, line 55
def self.batch_create!(assignments)
  api_assignements = assignments.map(&:to_api)
  if api_assignements.count > 0
    ApiClient.post(URL_PATH, body: api_assignements.to_json)
  else
    []
  end
end
get(id) click to toggle source
# File lib/dovico/model/time_entry.rb, line 37
def self.get(id)
  entry = ApiClient.get("#{URL_PATH}/#{id}")["TimeEntries"].first
  TimeEntry.parse(entry)
end
parse(hash) click to toggle source
# File lib/dovico/model/time_entry.rb, line 21
def self.parse(hash)
  TimeEntry.new(
    id:         parse_id(hash['ID']),
    start_time: hash['StartTime'],
    stop_time:  hash['StopTime'],
    project_id: hash['Project']['ID'],
    task_id:    hash['Task']['ID'],
    employee_id:hash['Employee']['ID'],
    sheet_id:   hash['Sheet']['ID'],
    sheet_status: hash['Sheet']['Status'],
    date:       hash['Date'],
    total_hours:hash['TotalHours'],
    description:hash['Description']
  )
end
submit!(employee_id, start_date, end_date) click to toggle source
# File lib/dovico/model/time_entry.rb, line 64
def self.submit!(employee_id, start_date, end_date)
  ApiClient.post(
    "#{URL_PATH}/Employee/#{employee_id}/Submit",
    params: {
      daterange: "#{start_date} #{end_date}"
    },
    body: {}.to_json,
  )
end

Private Class Methods

parse_id(long_id) click to toggle source
# File lib/dovico/model/time_entry.rb, line 115
def self.parse_id(long_id)
  # T: ID is a GUID, non-approved
  # M: ID is a long, approved
  long_id.sub(/^(T|M)/, "")
end

Public Instance Methods

create!() click to toggle source
# File lib/dovico/model/time_entry.rb, line 74
def create!
  ApiClient.post(URL_PATH, body: [to_api].to_json)
end
delete!() click to toggle source
# File lib/dovico/model/time_entry.rb, line 82
def delete!
  ApiClient.delete("#{URL_PATH}/#{id}")
end
formal_sheet_status() click to toggle source
# File lib/dovico/model/time_entry.rb, line 100
def formal_sheet_status
  case sheet_status
  when "N"
    :not_submitted
  when "A"
    :approved
  when "U"
    :under_review
  when "R"
    :rejected
  end
end
to_api() click to toggle source
# File lib/dovico/model/time_entry.rb, line 86
def to_api
  {
    "ID":         id,
    "StartTime":  start_time,
    "StopTime":   stop_time,
    "ProjectID":  project_id.to_s,
    "TaskID":     task_id.to_s,
    "EmployeeID": employee_id.to_s,
    "Date":       date,
    "TotalHours": total_hours.to_s,
    "Description": description,
  }.compact.stringify_keys
end
update!() click to toggle source
# File lib/dovico/model/time_entry.rb, line 78
def update!
  ApiClient.put(URL_PATH, body: [to_api].to_json)
end