Skip to content

Commit

Permalink
Timesheets api
Browse files Browse the repository at this point in the history
  • Loading branch information
samfoo committed Nov 15, 2011
1 parent 8aca555 commit f847630
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -1 +1,3 @@
Gemfile.lock Gemfile.lock
*.swp
*.swo
2 changes: 1 addition & 1 deletion gab.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'mechanize' require 'mechanize'
require 'csv'


module ThoughtWorks module ThoughtWorks
class Gab class Gab
Expand All @@ -21,7 +22,6 @@ def search(name)
private private


def login(user, pass) def login(user, pass)
result = @agent.get("http://gab.thoughtworks.com/")
form = @agent.get("http://gab.thoughtworks.com/").forms.first form = @agent.get("http://gab.thoughtworks.com/").forms.first


form.password = pass form.password = pass
Expand Down
44 changes: 44 additions & 0 deletions timesheets.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'csv'
require 'mechanize'
require 'logger'

module ThoughtWorks
class Timesheets
def initialize(user, pass)
@agent = Mechanize.new
login(user, pass)
end

def lates(due_date)
form = @agent.get("http://psfs89.thoughtworks.com/psc/fsprd89_6/EMPLOYEE/ERP/q/?ICAction=ICQryNameURL=PUBLIC.TW_TIME_MISSING_LATE_ONTIME").forms.first
form.ICAction = "#ICOK"
form.InputKeys_TW_WEEK_END_DT = due_date

form = @agent.submit(form).forms.first
form.ICAction = "#ICQryDownloadRaw"
form.InputKeys_TW_WEEK_END_DT = due_date
csv = @agent.submit(form)
temp = Tempfile.new("jcvd-is-gonna-kick-your-face")
temp.write(csv.content)
temp.close

all = CSV.read(temp.path)[1..-1]
badguys = all.select { |e| e[0].downcase.start_with?("au") && e[4] == "Y" }
badguys.collect do |e|
last, first = e[2].split(",")
[first, last].join(" ")
end
end

private

def login(user, pass)
form = @agent.get("http://psfs89.thoughtworks.com/psp/fsprd89/?cmd=login").forms.first

form.userid = user
form.pwd = pass

@agent.submit(form, form.buttons.first)
end
end
end

0 comments on commit f847630

Please sign in to comment.