Class: When::GoogleAPI::Calendar

Inherits:
Object
  • Object
show all
Defined in:
lib/when_exe/google_api.rb

Overview

GoogleAPI の Calendar API v3 に対応した Calendar クラス

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events) ⇒ Calendar

Calendar インスタンスを生成する

Parameters:



78
79
80
81
82
83
# File 'lib/when_exe/google_api.rb', line 78

def initialize(events)
  @events = events.map {|event|
    next nil unless event[:status] == 'confirmed'
    When::V::Event.new(event)
  }.compact
end

Instance Attribute Details

#calendar_idString (readonly)

calendar の id

Returns:



31
32
33
# File 'lib/when_exe/google_api.rb', line 31

def calendar_id
  @calendar_id
end

#eventsArray<When::V::Event> (readonly)

Calendar に属する Event

Returns:



37
38
39
# File 'lib/when_exe/google_api.rb', line 37

def events
  @events
end

#serviceGoogle::Apis::CalendarV3::CalendarService (readonly)

Calendar API のインスタンス

Returns:

  • (Google::Apis::CalendarV3::CalendarService)


25
26
27
# File 'lib/when_exe/google_api.rb', line 25

def service
  @service
end

Class Method Details

.list(service, calendar_id) ⇒ Object

GoogleAPI の Calendar を生成する

Parameters:

  • service (Google::Apis::CalendarV3::CalendarService)
  • calendar_id (String)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/when_exe/google_api.rb', line 46

def list(service, calendar_id)
  events = []
  result = service.list_events(calendar_id)
  loop do
    events += result.items.map {|event| event.to_h}
    page_token = result.next_page_token
    break unless page_token
    result = service.list_events(calendar_id, page_token: page_token)
  end
  calendar = new(events)
  calendar.instance_variable_set(:@service, service)
  calendar.instance_variable_set(:@calendar_id, calendar_id)
  calendar
end

Instance Method Details

#enum_for(*args) ⇒ Enumerator Also known as: to_enum

イベントを順に取り出す enumerator

Parameters:

Returns:

  • (Enumerator)


68
69
70
# File 'lib/when_exe/google_api.rb', line 68

def enum_for(*args)
  When::Parts::Enumerator::Integrated.new(self, @events.map {|event| event.enum_for(*args)}, *args)
end