Module: Mytime::Client

Extended by:
Client
Included in:
Mytime, Client
Defined in:
lib/mytime/client.rb

Instance Method Summary collapse

Instance Method Details

#project(project_id = nil) ⇒ Object

Get project data from client API

Option:

project_id: Optional project_id to restrict data returned


11
12
13
14
15
16
17
18
19
# File 'lib/mytime/client.rb', line 11

def project(project_id = nil)
   = Config.details    
  c = FreshBooks::Client.new(["account"], ["token"])
  if project_id.nil?
    c.project.list["projects"]
  else
    c.project.get :project_id => project_id
  end
end

#submit(hours, message = "") ⇒ Object

Submit new time entry to client API

Option:

hours: Required - number of hours spent for this time entry
message: Optional - message to send with time entry


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mytime/client.rb', line 37

def submit(hours, message = "")

   = Config.details
  c = FreshBooks::Client.new(["account"], ["token"])
  project = Config.details(Dir.pwd)
  entry = c.time_entry.create(
    :time_entry => {
      project_id: project["project_id"],
      task_id: project["task_id"],
      hours: hours.to_f,
      notes: message.gsub(/\n/,"\n\n").to_s,
      date: Date.today.to_s
    }
  )
  return validate(entry)
end

#tasks(project_id) ⇒ Object

Get task data from client API

project_id: Required project_id to restrict data returned



25
26
27
28
29
# File 'lib/mytime/client.rb', line 25

def tasks(project_id)
   = Config.details    
  c = FreshBooks::Client.new(["account"], ["token"])
  c.task.list :project_id => project_id
end

#validate(entry) ⇒ Object

Validate time entry to establish API success or failure

Option

entry: Required time entry parameter to validate


59
60
61
62
63
64
65
66
# File 'lib/mytime/client.rb', line 59

def validate(entry)
  return "Oops. Please try resubmitting your time or checking accout details!" unless entry.any?
  if entry["time_entry_id"]
    return "Timesheet Successfully Submitted"
  else
    return "Oops. An error was encountered: #{entry}"
  end
end