Class: FreeAgent::Company

Inherits:
Object
  • Object
show all
Defined in:
lib/free_agent.rb

Instance Method Summary collapse

Constructor Details

#initialize(domain, username, password) ⇒ Company

Returns a new instance of Company.



17
18
19
20
21
22
# File 'lib/free_agent.rb', line 17

def initialize(domain, username, password)
  @resource = RestClient::Resource.new(
    "https://#{domain}.freeagentcentral.com",
    :user => username, :password => password
  )
end

Instance Method Details

#contactsObject



28
29
30
# File 'lib/free_agent.rb', line 28

def contacts
  @contacts ||= Collection.new(@resource['/contacts'], :entity => :contact)
end

#expenses(user_id, options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/free_agent.rb', line 45

def expenses(user_id, options={})
  options.assert_valid_keys(:view, :from, :to)
  options.reverse_merge!(:view => 'recent')

  if options[:from] && options[:to]
    options[:view] = "#{options[:from].strftime('%Y-%m-%d')}_#{options[:to].strftime('%Y-%m-%d')}"
  end

  Collection.new(@resource["/users/#{user_id}/expenses?view=#{options[:view]}"], :entity => :expense)
end

#invoicesObject



24
25
26
# File 'lib/free_agent.rb', line 24

def invoices
  @invoices ||= Collection.new(@resource['/invoices'], :entity => :invoice)
end

#projectsObject



32
33
34
# File 'lib/free_agent.rb', line 32

def projects
  @projects ||= Collection.new(@resource['/projects'], :entity => :project)
end

#timeslipsObject

Note, this is only for PUT/POSTing to



41
42
43
# File 'lib/free_agent.rb', line 41

def timeslips
  @timeslips ||= Collection.new(@resource['/timeslips'], :entity => :timeslip)
end

#usersObject



36
37
38
# File 'lib/free_agent.rb', line 36

def users
  @users ||= Collection.new(@resource['/company/users'], :entity => :user)
end