Class: CalendarExtractors::GCalExtractor

Inherits:
CalExtractor show all
Defined in:
lib/extensions/calendar-timekeeping/gcal_extractor.rb

Overview

Extracts data from a Google Calender source.

Setup

It is required that you have a Google App setup with your account to allow for API access to your data. Then add the following keys to your settings file.

gmail_username

The username for your google application.

gmail_password

The password associated with this username.

gmail_app_name

The name of the application you created.

Instance Attribute Summary

Attributes inherited from CalExtractor

#data

Attributes inherited from LEWT::Extension

#command_name, #customers, #enterprise, #lewt_settings, #lewt_stash, #options

Instance Method Summary collapse

Methods inherited from CalExtractor

#isTargetCustomer?, #isTargetDate?

Methods inherited from LEWT::Extension

#get_matched_customers, #lewt_extensions

Constructor Details

#initialize(dStart, dEnd, targetCustomers, lewt_settings, suppressTargets) ⇒ GCalExtractor

Sets up this extension



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/extensions/calendar-timekeeping/gcal_extractor.rb', line 23

def initialize ( dStart, dEnd, targetCustomers, lewt_settings, suppressTargets )
  uname = lewt_settings["gmail_username"]
  pass = lewt_settings["gmail_password"]
  app = lewt_settings["google_app_name"]
  @googleCalender = Google::Calendar.new(
                                         :username => uname,
                                         :password => pass,
                                         :app_name => app
                                         )
  super( dStart, dEnd, targetCustomers )
end

Instance Method Details

#extractCalendarDataObject

This method does the actual google calender extract, comparing events to the requested paramters. It manipulates the @data property of this object which is used by LEWT to gather the extracted data.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/extensions/calendar-timekeeping/gcal_extractor.rb', line 37

def extractCalendarData
  gConf = { :max_results => 2500, :order_by => 'starttime', :single_events => true }
  @googleCalender.find_events_in_range(@dateStart, @dateEnd + 1, gConf).each do |e|
    eStart = Time.parse( e.start_time )
    eEnd = Time.parse( e.end_time )
    timeDiff = (eEnd - eStart)/60/60
    target = self.isTargetCustomer?(e.title)
    if  self.isTargetDate?( eStart ) == true && target != false
      row = LEWT::LEWTLedger.new({
                                   :date_start => eStart, 
                                   :date_end => eEnd, 
                                   :category => @category, 
                                   :entity => target["name"], 
                                   :description => e.content, 
                                   :quantity => timeDiff, 
                                   :unit_cost => target["rate"]
                                 })
      @data.push(row)
    end
  end
end