Class: Calendar
- Inherits:
-
Object
- Object
- Calendar
- Defined in:
- lib/calendar.rb
Constant Summary collapse
- CALENDAR_API_URL =
"https://www.googleapis.com/calendar/v3/"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#max_results ⇒ Object
Returns the value of attribute max_results.
Instance Method Summary collapse
- #fetch_events_from(calendar_id) ⇒ Object
-
#initialize(api_key = nil, max_results = 4) ⇒ Calendar
constructor
A new instance of Calendar.
Constructor Details
#initialize(api_key = nil, max_results = 4) ⇒ Calendar
Returns a new instance of Calendar.
5 6 7 8 9 |
# File 'lib/calendar.rb', line 5 def initialize(api_key=nil, max_results=4) @api_key = api_key if api_key @api_key = Configuration[:google_api_key] @max_results = max_results end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
2 3 4 |
# File 'lib/calendar.rb', line 2 def api_key @api_key end |
#max_results ⇒ Object
Returns the value of attribute max_results.
2 3 4 |
# File 'lib/calendar.rb', line 2 def max_results @max_results end |
Instance Method Details
#fetch_events_from(calendar_id) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/calendar.rb', line 11 def fetch_events_from(calendar_id) req = HTTParty.get(CALENDAR_API_URL+"calendars/#{calendar_id}/events?key=#{@api_key}&maxResults=#{@max_results}") if req.code == 200 json = ActiveSupport::JSON.decode(req.body) return json['items'] end [] end |