Permalink
Browse files

Timesheets api

  • Loading branch information...
1 parent 8aca555 commit f847630b996c221503fa0ee80d8c9a707a247bd1 @samfoo committed Nov 15, 2011
Showing with 47 additions and 1 deletion.
  1. +2 −0 .gitignore
  2. +1 −1 gab.rb
  3. +44 −0 timesheets.rb
View
@@ -1 +1,3 @@
Gemfile.lock
+*.swp
+*.swo
View
2 gab.rb
@@ -1,4 +1,5 @@
require 'mechanize'
+require 'csv'
module ThoughtWorks
class Gab
@@ -21,7 +22,6 @@ def search(name)
private
def login(user, pass)
- result = @agent.get("http://gab.thoughtworks.com/")
form = @agent.get("http://gab.thoughtworks.com/").forms.first
form.password = pass
View
@@ -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.