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:



88
89
90
91
92
93
# File 'lib/when_exe/google_api.rb', line 88

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:



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

def calendar_id
  @calendar_id
end

#clientGoogle::APIClient (readonly)

APIClient のインスタンス

Returns:

  • (Google::APIClient)


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

def client
  @client
end

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

Calendar に属する Event

Returns:



42
43
44
# File 'lib/when_exe/google_api.rb', line 42

def events
  @events
end

#serviceGoogle::APIClient::API (readonly)

Calendar API のインスタンス

Returns:

  • (Google::APIClient::API)


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

def service
  @service
end

Class Method Details

.list(client, service, calendar_id) ⇒ Object

GoogleAPI の Calendar を生成する

Parameters:

  • client (Google::APIClient)
  • service (Google::APIClient::API)
  • calendar_id (String)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/when_exe/google_api.rb', line 52

def list(client, service, calendar_id)
  events = []
  result = client.execute({:api_method => service.events.list,
                           :parameters => {'calendarId' => calendar_id}})
  loop do
    events += result.data.items.map {|event| event.to_hash}
    page_token = result.data.next_page_token
    break unless page_token
    result = client.execute({:api_method => service.events.list,
                             :parameters => {'calendarId' => calendar_id,
                                             'pageToken'  => page_token}})
  end
  calendar = new(events)
  calendar.instance_variable_set(:@client, client)
  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)


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

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