Module: MyGCalModule

Defined in:
lib/lib/mygcal.rb

Overview

Googleカレンダーへのアクセスを提供する

~/config.ymlに

gmail:
  address: [email protected]
  pass: xxxxxxxxxx
  feedurl: http://www.google.com/calendar/feeds/xxxxxxxx%40gmail.com/private/full

使い方など class ThisDo

include MyGCalModule

して o = ThisDo.new o.gcal_read とかでok

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gcal_queryObject

Returns the value of attribute gcal_query.



18
19
20
# File 'lib/lib/mygcal.rb', line 18

def gcal_query
  @gcal_query
end

#gcalfeedurlObject

Returns the value of attribute gcalfeedurl.



18
19
20
# File 'lib/lib/mygcal.rb', line 18

def gcalfeedurl
  @gcalfeedurl
end

#gmailObject

Returns the value of attribute gmail.



18
19
20
# File 'lib/lib/mygcal.rb', line 18

def gmail
  @gmail
end

#gmailpassObject

Returns the value of attribute gmailpass.



18
19
20
# File 'lib/lib/mygcal.rb', line 18

def gmailpass
  @gmailpass
end

Instance Method Details

#gcal_checkout(event) ⇒ Object

fetchしたデータの取り込み済みマークを立てる



61
62
63
64
65
# File 'lib/lib/mygcal.rb', line 61

def gcal_checkout(event)
  event.title = '[FETCHED]' + event.title
  event.save!
  return self
end

#gcal_parse_2_jobsObject

gcalのイベントをAtMduleが食べれる形に変換する 共通のJOBクラスで包もうかしら?



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lib/mygcal.rb', line 40

def gcal_parse_2_jobs
  @gcal_jobs = []
  q = @gcal_query ||= '[Gcal2PusherTail'
  @gcal_events.each do |event|
    begin
      kind,filename = event.title.split(']')
      if(kind == @gcal_query && filename != nil)
        @gcal_jobs << {:filename => filename,
          :start => event.st,
          :end => event.en,
          :object => event}
      end
    rescue =>ex
      p ex
      #握りつぶす
    end
  end
  return self
end

#gcal_readObject



20
21
22
23
24
# File 'lib/lib/mygcal.rb', line 20

def gcal_read
  service
  @gcal_events = @gcal.events
  return self
end

#gcal_write(eventdata) ⇒ Object

GCalへ書きこむ



27
28
29
30
31
32
33
34
35
36
# File 'lib/lib/mygcal.rb', line 27

def gcal_write(eventdata)
  service
  event = @gcal.create_event
  event.title = eventdata[:title]
  event.st = eventdata[:start]
  event.en = eventdata[:end]
  event.save!
  @gcal_event = event
  return self
end

#serviceObject

GCalへのアクセス



68
69
70
71
72
73
74
75
# File 'lib/lib/mygcal.rb', line 68

def service
  if @gcal_srv.nil?
    require 'gcalapi'
    @c = MyConfig.get['gmail']
    @gcal_srv = GoogleCalendar::Service.new(@c['address'],@c['pass'])
  end
  @gcal = GoogleCalendar::Calendar::new(@gcal_srv, @c['feedurl'])
end