Class: GCal::Client
- Inherits:
-
Object
- Object
- GCal::Client
- Defined in:
- lib/gcal/client.rb
Constant Summary collapse
- BASE_URL =
'https://www.google.com'
- API_URL =
"#{BASE_URL}/calendar/feeds"
Instance Method Summary collapse
- #all_calendars ⇒ Object
- #call(uri) ⇒ Object
- #events(calendar_id, options = {}) ⇒ Object
-
#initialize(api_key = nil, api_secret = nil, token = nil, secret = nil) ⇒ Client
constructor
A new instance of Client.
- #own_calendars ⇒ Object
Constructor Details
#initialize(api_key = nil, api_secret = nil, token = nil, secret = nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 |
# File 'lib/gcal/client.rb', line 9 def initialize(api_key = nil, api_secret = nil, token = nil, secret = nil) @api_key, @api_secret = api_key, api_secret @client = ::Typhoeus::Hydra.new # if api call protected, create token and consumer if protected_api_call? @consumer = ::OAuth::Consumer.new(api_key, api_secret, :site => BASE_URL) @token = ::OAuth::Token.new(token, secret) end end |
Instance Method Details
#all_calendars ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/gcal/client.rb', line 27 def all_calendars path = "/default/allcalendars/full/" xml = call(path) calendars = [] xml['entry'].each do |entry| calendars << GCal::Calendar.parse(entry, path) end if xml['entry'] calendars end |
#call(uri) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/gcal/client.rb', line 19 def call(uri) request = ::Typhoeus::Request.new(API_URL + uri) (request) if protected_api_call? @client.queue(request) @client.run XmlSimple.xml_in(request.response.body) end |
#events(calendar_id, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/gcal/client.rb', line 47 def events(calendar_id, = {}) xml = call("/#{calendar_id}/private/full#{GCal::Event.()}") events = [] xml['entry'].each do |entry| events << GCal::Event.parse(calendar_id, entry) end if xml['entry'] events end |