Class: GoogleCalendarApiV2::Event
- Inherits:
-
Object
- Object
- GoogleCalendarApiV2::Event
- Includes:
- Base
- Defined in:
- lib/google_calendar_api_v2/event.rb
Instance Attribute Summary collapse
-
#calendar ⇒ Object
readonly
Returns the value of attribute calendar.
Attributes included from Base
Instance Method Summary collapse
- #all(url = nil, redirect_count = 0) ⇒ Object
- #create(params = {}, url = nil, redirect_count = 0) ⇒ Object
- #find(event_token, url = nil, redirect_count = 0) ⇒ Object
-
#initialize(connection, calendar) ⇒ Event
constructor
A new instance of Event.
Constructor Details
#initialize(connection, calendar) ⇒ Event
Returns a new instance of Event.
7 8 9 10 |
# File 'lib/google_calendar_api_v2/event.rb', line 7 def initialize(connection, calendar) @connection = connection @calendar = calendar end |
Instance Attribute Details
#calendar ⇒ Object (readonly)
Returns the value of attribute calendar.
5 6 7 |
# File 'lib/google_calendar_api_v2/event.rb', line 5 def calendar @calendar end |
Instance Method Details
#all(url = nil, redirect_count = 0) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/google_calendar_api_v2/event.rb', line 26 def all(url = nil, redirect_count = 0) url ||= "https://www.google.com/calendar/feeds/#{@calendar.token}/private/full?alt=jsonc&futureevents=false" response = @connection.get url, Client::HEADERS if success? response # Response::Event.new(response, @connection, @calendar) if items = JSON.parse(response.body)['data']['items'] items.map {|item| Response::Event.new(item, @connection, @calendar) } else [] end elsif redirect? response all(response['location'], redirect_count += 1) end end |
#create(params = {}, url = nil, redirect_count = 0) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/google_calendar_api_v2/event.rb', line 42 def create(params = {}, url = nil, redirect_count = 0) url ||= "/calendar/feeds/#{@calendar.token}/private/full?alt=jsonc" response = @connection.post url, { :data => { :title => "Undefined event", :hidden => false }.merge(params) }.to_json, Client::HEADERS raise 'Redirection Loop' if redirect_count > 3 if success? response item = JSON.parse(response.body)['data'] Response::Event.new(item, @connection, @calendar) elsif redirect? response create(params, response['location'], redirect_count += 1) else false end end |
#find(event_token, url = nil, redirect_count = 0) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/google_calendar_api_v2/event.rb', line 12 def find(event_token, url = nil, redirect_count = 0) url ||= "https://www.google.com/calendar/feeds/#{@calendar.token}/private/full/#{event_token}?alt=jsonc" response = @connection.get url, Client::HEADERS raise 'Redirection Loop' if redirect_count > 3 if success? response item = JSON.parse(response.body)['data'] Response::Event.new(item, @connection, @calendar) elsif redirect? response find(event_token, response['location'], redirect_count += 1) end end |