Class: Beggar::Basecamp

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/beggar/basecamp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Basecamp

Returns a new instance of Basecamp.



7
8
9
10
11
12
# File 'lib/beggar/basecamp.rb', line 7

def initialize(config)
  @config = config

  self.class.base_uri("https://#{config['company']}.basecamphq.com")
  self.class.basic_auth(config['token'], 'X')
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/beggar/basecamp.rb', line 5

def config
  @config
end

Instance Method Details

#current_monthObject



43
44
45
# File 'lib/beggar/basecamp.rb', line 43

def current_month
  @current_month ||= CurrentMonth.new(:country => @config['country'])
end

#current_month_reportObject



23
24
25
# File 'lib/beggar/basecamp.rb', line 23

def current_month_report
  @current_month_report ||= time_report(from: current_month.first_day, to: current_month.today)
end

#current_userObject



19
20
21
# File 'lib/beggar/basecamp.rb', line 19

def current_user
  @current_user ||= self.class.get('/me.xml')['person']['id']
end

#hours_ratioObject



35
36
37
# File 'lib/beggar/basecamp.rb', line 35

def hours_ratio
  current_month.workday_hours_until_today - worked_hours
end

#time_report(options = {}) ⇒ Object



14
15
16
17
# File 'lib/beggar/basecamp.rb', line 14

def time_report(options = {})
  options.merge!(subject_id: current_user)
  self.class.get("/time_entries/report.xml", :query => options)
end

#workdays_progressionObject



39
40
41
# File 'lib/beggar/basecamp.rb', line 39

def workdays_progression
  current_month.workdays_progression
end

#worked_hoursObject



27
28
29
30
31
32
33
# File 'lib/beggar/basecamp.rb', line 27

def worked_hours
  time_entries = current_month_report['time_entries']
  return 0 if time_entries.empty?
  time_entries.map do |entry|
    entry['hours']
  end.inject(:+)
end