Class: Harvest::Base

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Requires a sub_domain, email, and password. Specifying headers is optional, but useful for setting a user agent.



38
39
40
41
42
43
44
45
46
# File 'lib/harvest/base.rb', line 38

def initialize(options={})
  options.assert_required_keys(:email, :password, :sub_domain)
  @email        = options[:email]
  @password     = options[:password]
  @sub_domain   = options[:sub_domain]
  @headers      = options[:headers]
  @ssl          = options[:ssl]
  configure_base_resource
end

Class Method Details

.debug_levelObject



5
6
7
# File 'lib/harvest/base.rb', line 5

def self.debug_level
  @debug_level
end

.debug_level=(debug_level) ⇒ Object

Raises:

  • (ArgumentError)


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
# File 'lib/harvest/base.rb', line 9

def self.debug_level=(debug_level)
  raise ArgumentError, "debug level must be an integer" unless debug_level == debug_level.to_i

  return @debug_level if @debug_level == debug_level

  @debug_level = debug_level.to_i

  ActiveSupport::Notifications.unsubscribe(@subscriber) if @subscriber

  case @debug_level
  when 0 then
  when 1 then
    @subscriber = ActiveSupport::Notifications.subscribe(/request.active_resource/) do |*args|
      event = ActiveSupport::Notifications::Event.new(*args)
      puts "-- HARVEST #{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}, #{event.payload[:result].andand.code}: #{event.payload[:result].andand.message}"
    end
  else
    @subscriber = ActiveSupport::Notifications.subscribe(/request.active_resource/) do |*args|
      event = ActiveSupport::Notifications::Event.new(*args)
      puts "-- HARVEST #{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}, #{event.payload[:result].andand.code}: #{event.payload[:result].andand.message}"
      puts event.payload[:result].body + "\n"
    end
  end
  
  @debug_level
end

Instance Method Details

#clientsObject

Clients



52
53
54
# File 'lib/harvest/base.rb', line 52

def clients
  Harvest::Resources::Client
end

#contactsObject

Contacts



57
58
59
# File 'lib/harvest/base.rb', line 57

def contacts
  Harvest::Resources::Contact
end

#expense_categoriesObject

Expense categories.



67
68
69
# File 'lib/harvest/base.rb', line 67

def expense_categories
  Harvest::Resources::ExpenseCategory
end

#expensesObject

Expenses.



62
63
64
# File 'lib/harvest/base.rb', line 62

def expenses
  Harvest::Resources::Expense
end

#invoice_messagesObject

Invoice Messages



95
96
97
# File 'lib/harvest/base.rb', line 95

def invoice_messages
  Harvest::Resources::InvoiceMessage
end

#invoicesObject

Invoices



90
91
92
# File 'lib/harvest/base.rb', line 90

def invoices
  Harvest::Resources::Invoice
end

#peopleObject

People. Also provides access to time entries.



73
74
75
# File 'lib/harvest/base.rb', line 73

def people
  Harvest::Resources::Person
end

#projectsObject

Projects. Provides access to the assigned users and tasks along with reports for entries on the project.



80
81
82
# File 'lib/harvest/base.rb', line 80

def projects
  Harvest::Resources::Project
end

#tasksObject

Tasks.



85
86
87
# File 'lib/harvest/base.rb', line 85

def tasks
  Harvest::Resources::Task
end