Skip to content

Instantly share code, notes, and snippets.

@bosko
Created February 7, 2012 21:51
Show Gist options
  • Save bosko/1762305 to your computer and use it in GitHub Desktop.
Save bosko/1762305 to your computer and use it in GitHub Desktop.
API v3 snippets
require 'google_suite/oauth/calendar_oauth'
require 'google_suite/oauth/calendar_oauth2'
class Calendar < Scope
# At this moment we must know what is version of API
# that we are created for. In other words client must already
# be created before any of "data" classes are used
case GoogleSuite.client.api_version
when "2.0"
include(GoogleSuite::CalendarOAuth)
when "3.0"
include(GoogleSuite::CalendarOAuth2)
end
def hidden
attributes["hidden"] ||= false #Note we are using method attributes instead of member variable @attributes
end
end
module GoogleSuite
APP_NAME = "google_suite.gem"
API_VERSION = "3.0"
class << self
attr_accessor :logger
def client
Thread.current[:google_client]
end
# credentials:
# Hash of :consumer_key, :consumer_secret and :account
# (Google account name) in the case of OAuth.
#
# Hash of :client_id, :client_secret, :access_token
# (corresponding to the scope which is actually site which
# will be accessed and account).
def connection(credentials, version = ::GoogleSuite::API_VERSION)
autoload :Client, "google_suite/client"
autoload :Service, "google_suite/service"
autoload :Contact, "google_suite/contact"
autoload :ContactGroup, "google_suite/contact_group"
autoload :Calendar, "google_suite/calendar"
autoload :Event, "google_suite/event"
autoload :EventRecurrence, "google_suite/event_recurrence"
autoload :Document, "google_suite/document"
autoload :DocumentCollection, "google_suite/document_collection"
begin
Thread.current[:google_client] = Client.new(credentials, version)
yield if block_given?
rescue
Thread.current[:google_client] = nil
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment