public
Description: A gem that provides a ruby wrapper around the tickspot.com api
Homepage: http://tickspot.com/api/
Clone URL: git://github.com/bricooke/tickspot-ruby.git
Search Repo:
commit  902f5346e5483546f854e6709611fa12a3a310be
tree    e50f06f7053390c1916757a1c1d79b10b9431435
parent  2466c32e5d29875b2583cefb4dad53ac094aefec
tickspot-ruby / lib / tickspot.rb
100644 51 lines (43 sloc) 1.142 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'rubygems'
require 'net/http'
require 'xmlsimple'
require 'activesupport'
require File.dirname(__FILE__) + '/tickspot_entry'
 
class Tickspot
  VERSION = '0.1.0'
  
  def initialize(domain, email, password)
    @domain = domain
    @email = email
    @password = password
  end
 
  def users(params={})
    te = request("users", params)
    te.empty? ? [] : te.users
  end
 
  def projects
    te = request("projects")
    te.empty? ? [] : te.projects
  end
 
  def tasks(project_id)
    te = request("tasks", :project_id => project_id)
    te.empty? ? [] : te.tasks
  end
 
  def entries(start_date, end_date, params={})
    te = request("entries", params.merge({:start_date => start_date, :end_date => end_date}))
    te.empty? ? [] : te.entries
  end
 
private
  def request(path, params={})
    request = Net::HTTP::Post.new("/api/" + path)
    request.form_data = {
      'email' => @email,
      'password' => @password
    }.merge(params)
 
    ret = nil
    Net::HTTP.new(@domain).start {|http|
      response = http.request(request)
      ret = TickspotEntry.new(XmlSimple.xml_in(response.body))
    }
    ret
  end
end