Skip to content

Instantly share code, notes, and snippets.

@stephen-puiszis
Created December 2, 2014 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephen-puiszis/0477655f62a59225e2ae to your computer and use it in GitHub Desktop.
Save stephen-puiszis/0477655f62a59225e2ae to your computer and use it in GitHub Desktop.
Find Your Missing Harvest Descriptions
require 'date'
require 'harvested'
class MissingHarvestEntries
attr_accessor :subdomain, :username, :password, :timesheet, :missing_entries, :start_date, :end_date
def initialize(start_date, end_date)
@subdomain = 'MY SUBDOMAIN'
@username = 'MY USERNAME'
@password = 'MY PASSWORD'
@timesheet = []
@missing_entries = []
self.fetch_timesheet(start_date,end_date)
self.find_and_print_missing_entries
end
def fetch_timesheet(start_date, end_date)
harvest = Harvest.client(subdomain: subdomain, username: username, password: password)
@timesheet = (start_date..end_date).map {|date| harvest.time.all(date) }
end
def find_and_print_missing_entries
@missing_entries = @timesheet.flatten.select { |t| t.notes.nil? }
@missing_entries.each {|t| self.print_entry(t) }
end
def print_entry(harvest_entry)
string = <<-STRING
---------------------------------------------------
Date: #{Date.parse(harvest_entry.created_at).strftime("%b %d, %Y")}
Client: #{harvest_entry.client}
Task: #{harvest_entry.task}
Hours: #{harvest_entry.hours}
Desc: #{harvest_entry.notes}
STRING
puts string
end
end
dates = ARGF.argv
raise "End Date begins before start date, please try again." if (dates[0] > dates[1])
start_date = Date.parse(dates[0])
end_date = Date.parse(dates[1])
m = MissingHarvestEntries.new(start_date, end_date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment