Class: Beggar::Basecamp
- Inherits:
-
Object
- Object
- Beggar::Basecamp
- Includes:
- HTTParty
- Defined in:
- lib/beggar/basecamp.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #current_month ⇒ Object
- #current_month_report ⇒ Object
- #current_user ⇒ Object
- #hours_ratio ⇒ Object
-
#initialize(config) ⇒ Basecamp
constructor
A new instance of Basecamp.
- #time_report(options = {}) ⇒ Object
- #workdays_progression ⇒ Object
- #worked_hours ⇒ Object
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
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/beggar/basecamp.rb', line 5 def config @config end |
Instance Method Details
#current_month ⇒ Object
43 44 45 |
# File 'lib/beggar/basecamp.rb', line 43 def current_month @current_month ||= CurrentMonth.new(:country => @config['country']) end |
#current_month_report ⇒ Object
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_user ⇒ Object
19 20 21 |
# File 'lib/beggar/basecamp.rb', line 19 def current_user @current_user ||= self.class.get('/me.xml')['person']['id'] end |
#hours_ratio ⇒ Object
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( = {}) .merge!(subject_id: current_user) self.class.get("/time_entries/report.xml", :query => ) end |
#workdays_progression ⇒ Object
39 40 41 |
# File 'lib/beggar/basecamp.rb', line 39 def workdays_progression current_month.workdays_progression end |
#worked_hours ⇒ Object
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 |