Class: Goauth2::Client
- Inherits:
-
Object
- Object
- Goauth2::Client
- Defined in:
- lib/goauth2/client.rb,
lib/goauth2/calendar.rb,
lib/goauth2/contacts.rb
Constant Summary collapse
- SCOPES =
{ :calendar => 'https://www.google.com/calendar/feeds/', :contacts => 'https://www.google.com/m8/feeds/', :gmail => 'https://mail.google.com/mail/feed/atom/' }
Instance Method Summary collapse
- #access_token ⇒ Object
- #all_calendars(params = {}, headers = {}) ⇒ Object
- #authorize(options = {}) ⇒ Object
- #authorize_url(options = {}) ⇒ Object
- #client ⇒ Object
- #contacts ⇒ Object
- #events(event_feed, params = {}, headers = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #own_calendars(params = {}, headers = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/goauth2/client.rb', line 14 def initialize( = {}) @client_id = [:client_id] @client_secret = [:client_secret] @redirect_uri = [:redirect_uri] @scope = [:scope] || SCOPES.values.join(' ') @token = [:token] @refresh_token = [:refresh_token] @expires_at = [:expires_at] @expires_in = [:expires_in] end |
Instance Method Details
#access_token ⇒ Object
57 58 59 60 |
# File 'lib/goauth2/client.rb', line 57 def access_token @access_token ||= OAuth2::AccessToken.new(client, @token, :refresh_token => @refresh_token, :expires_at => @expires_at, :expires_in => @expires_in) refresh! end |
#all_calendars(params = {}, headers = {}) ⇒ Object
3 4 5 |
# File 'lib/goauth2/calendar.rb', line 3 def all_calendars(params = {}, headers = {}) _get_jsonc('https://www.google.com/calendar/feeds/default/allcalendars/full', params, headers.merge({'GData-Version' => '2'})) end |
#authorize(options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/goauth2/client.rb', line 33 def ( = {}) @access_token ||= client.auth_code.get_token( [:code], :redirect_uri => [:redirect_uri] || @redirect_uri ) @token = @access_token.token @refresh_token = @access_token.refresh_token @expires_at = @access_token.expires_at @expires_in = @access_token.expires_in @access_token end |
#authorize_url(options = {}) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/goauth2/client.rb', line 26 def ( = {}) client.auth_code.( :redirect_uri => [:redirect_uri] || @redirect_uri, :scope => [:scope] || @scope ) end |
#client ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/goauth2/client.rb', line 45 def client @client ||= OAuth2::Client.new( @client_id, @client_secret, { :site => "https://accounts.google.com", :authorize_url => '/o/oauth2/auth', :token_url => '/o/oauth2/token' } ) end |
#contacts ⇒ Object
4 5 6 |
# File 'lib/goauth2/contacts.rb', line 4 def contacts _get_json('https://www.google.com/m8/feeds/contacts/default/full') end |
#events(event_feed, params = {}, headers = {}) ⇒ Object
11 12 13 |
# File 'lib/goauth2/calendar.rb', line 11 def events(event_feed, params = {}, headers = {}) _get_jsonc(event_feed, params, headers.merge({'GData-Version' => '2'})) end |
#own_calendars(params = {}, headers = {}) ⇒ Object
7 8 9 |
# File 'lib/goauth2/calendar.rb', line 7 def own_calendars(params = {}, headers = {}) _get_jsonc('https://www.google.com/calendar/feeds/default/owncalendars/full', params, headers.merge({'GData-Version' => '2'})) end |