Class: Freckle
- Inherits:
-
Object
- Object
- Freckle
- Defined in:
- lib/freckle.rb
Defined Under Namespace
Classes: Base, Entry, Project, User
Class Method Summary collapse
Instance Method Summary collapse
-
#entries(options = {}) ⇒ Object
people: comma separated user ids projects: comma separated project ids tags: comma separated tag ids from: entries from this date to: entries to this date billable: true only shows billable entries; false only shows unbillable entries.
-
#initialize(options = {}) ⇒ Freckle
constructor
A new instance of Freckle.
- #projects(options = {}) ⇒ Object
- #user_by_email(email) ⇒ Object
-
#users(options = {}) ⇒ Object
Query Methods.
Constructor Details
#initialize(options = {}) ⇒ Freckle
Returns a new instance of Freckle.
9 10 11 12 13 14 15 16 |
# File 'lib/freckle.rb', line 9 def initialize( = {}) @account = .delete(:account) @token = .delete(:token) @logger = .delete(:logger) || Logger.new(STDOUT) RestClient.log = @logger @connection = RestClient::Resource.new( "http://#{@account}.letsfreckle.com/api", :headers => {"X-FreckleToken" => @token} ) end |
Class Method Details
.connection ⇒ Object
21 22 23 24 |
# File 'lib/freckle.rb', line 21 def self.connection return @connection if @connection raise RuntimeError, "Freckle.establish_connection with :account and :token first" end |
.establish_connection(options) ⇒ Object
18 19 20 |
# File 'lib/freckle.rb', line 18 def self.establish_connection() @connection = new() end |
Instance Method Details
#entries(options = {}) ⇒ Object
people: comma separated user ids projects: comma separated project ids tags: comma separated tag ids from: entries from this date to: entries to this date billable: true only shows billable entries; false only shows unbillable entries
49 50 51 52 53 54 |
# File 'lib/freckle.rb', line 49 def entries( = {}) .keys.each { |k| ["search[#{k}]"] = Array(.delete(k)).flatten.join(',') } Array(JSON.parse(@connection['/entries.json'].get(:params => ))).flatten.map do |entry| Entry.new(entry['entry'], self) end end |
#projects(options = {}) ⇒ Object
37 38 39 40 41 |
# File 'lib/freckle.rb', line 37 def projects( = {}) Array(JSON.parse(@connection['/projects.json'].get)).flatten.map do |project| Project.new(project['project'], self) end end |
#user_by_email(email) ⇒ Object
33 34 35 |
# File 'lib/freckle.rb', line 33 def user_by_email(email) self.users.detect{ |u| u.email == email } end |