Class: LetsFreckle::Entry

Inherits:
Hashie::Mash
  • Object
show all
Extended by:
ClientResource
Defined in:
lib/letsfreckle/entry.rb

Class Method Summary collapse

Methods included from ClientResource

base_api_url, get, post, relative_path_for

Class Method Details

.allObject



5
6
7
# File 'lib/letsfreckle/entry.rb', line 5

def self.all
  get('entries')
end

.create(options = {}) ⇒ Object

Creates a new entry. Supported options are:

:minutes => '4h' (required)
:project_id => 3221
:description => 'new task'
:date => '2011-08-01'

Raises:

  • (ArgumentError)


25
26
27
28
29
# File 'lib/letsfreckle/entry.rb', line 25

def self.create(options = {})
  raise ArgumentError, ':username config missing' unless LetsFreckle.config.username
  raise ArgumentError, ':minutes missing' unless options.has_key?(:minutes)
  post('entries', options.merge(:root => :entry, :user => LetsFreckle.config.username))
end

.find(options = {}) ⇒ Object

Fetches all entries. Supported options are:

:people => ['ryan', 'frank']
:projects => ['project1', 'project2']
:tags => ['tag1', 'tag2']
:from => '2011-01-01'
:to => '2012-01-01'
:billable => true/false


16
17
18
# File 'lib/letsfreckle/entry.rb', line 16

def self.find(options = {})
  get('entries', searchable_options_from(options))
end

.searchable_options_from(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/letsfreckle/entry.rb', line 31

def self.searchable_options_from(options = {})
  options.each_with_object({}) do |(key, value), result|
    case value
    when Array then
      result["search[#{key}]"] = value.join(',')
    else
      result["search[#{key}]"] = value.to_s
    end
  end
end