Class: Tick::Entry

Inherits:
Base
  • Object
show all
Defined in:
lib/tick/entry.rb

Constant Summary collapse

XML_PROPERTIES =
%w( id billable billed budget client_name created_at date hours notes
project_name sum_hours task_id task_name updated_at user_email user_id )

Instance Attribute Summary collapse

Attributes inherited from Base

#api_name, #api_path, #created_at, #id, #updated_at

Class Method Summary collapse

Methods inherited from Base

api_name, list, #set_properties_from_xml_node

Instance Attribute Details

#billableObject

Returns the value of attribute billable.



4
5
6
# File 'lib/tick/entry.rb', line 4

def billable
  @billable
end

#billedObject

Returns the value of attribute billed.



4
5
6
# File 'lib/tick/entry.rb', line 4

def billed
  @billed
end

#budgetObject

Returns the value of attribute budget.



4
5
6
# File 'lib/tick/entry.rb', line 4

def budget
  @budget
end

#client_nameObject

Returns the value of attribute client_name.



4
5
6
# File 'lib/tick/entry.rb', line 4

def client_name
  @client_name
end

#dateObject

Returns the value of attribute date.



4
5
6
# File 'lib/tick/entry.rb', line 4

def date
  @date
end

#hoursObject

Returns the value of attribute hours.



4
5
6
# File 'lib/tick/entry.rb', line 4

def hours
  @hours
end

#notesObject

Returns the value of attribute notes.



4
5
6
# File 'lib/tick/entry.rb', line 4

def notes
  @notes
end

#project_nameObject

Returns the value of attribute project_name.



4
5
6
# File 'lib/tick/entry.rb', line 4

def project_name
  @project_name
end

#sum_hoursObject

Returns the value of attribute sum_hours.



4
5
6
# File 'lib/tick/entry.rb', line 4

def sum_hours
  @sum_hours
end

#task_idObject

Returns the value of attribute task_id.



4
5
6
# File 'lib/tick/entry.rb', line 4

def task_id
  @task_id
end

#task_nameObject

Returns the value of attribute task_name.



4
5
6
# File 'lib/tick/entry.rb', line 4

def task_name
  @task_name
end

#user_emailObject

Returns the value of attribute user_email.



4
5
6
# File 'lib/tick/entry.rb', line 4

def user_email
  @user_email
end

#user_idObject

Returns the value of attribute user_id.



4
5
6
# File 'lib/tick/entry.rb', line 4

def user_id
  @user_id
end

Class Method Details

.api_pathObject



11
12
13
# File 'lib/tick/entry.rb', line 11

def self.api_path
  "/api/entries"
end

.create(options = {}, &block) ⇒ Object



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
# File 'lib/tick/entry.rb', line 15

def self.create(options={}, &block)
  url  = "https://#{current_session.company}.tickspot.com/api/create_entry"
  
  params = {
    email: current_session.email,
    password: current_session.password
  }.merge!(options)
  
  if params[:date].is_a?(NSDate)
    dateFormatter = NSDateFormatter.new
    dateFormatter.setDateFormat(DATE_FORMAT)
    params[:date] = dateFormatter.stringFromDate(params[:date])
  end
  
  request_manager.GET(url, parameters:params, success:lambda{|operation, result|
    error = Pointer.new(:object)
    xml = GDataXMLDocument.alloc.initWithXMLString(result.to_s, error:error)
    
    # Create the entry object from xml
    error = Pointer.new(:object)
    entry_node = xml.nodesForXPath("//entry", error:error).first
    entry = new
    entry.set_properties_from_xml_node(entry_node)
    block.call(entry) if block
  }, failure:lambda{|operation, error|
    block.call(error) if block
  })
  
  self
end