Class: GRuby::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/g_ruby/auth.rb

Class Method Summary collapse

Class Method Details

.oauth2(state, scope) ⇒ Object

GRuby::Auth.oauth2(state)



13
14
15
16
17
# File 'lib/g_ruby/auth.rb', line 13

def self.oauth2(state, scope)
 a = "https://accounts.google.com/o/oauth2/auth?response_type=code&access_type=offline&approval_prompt=auto&client_id=#{GOOGLE_CLIENTID}&redirect_uri=#{GOOGLE_CALLBACK}&scope=#{scope}"
 a = a + "&state=#{state}"  if !state.blank?
 return a
end

.oauth2_url(state) ⇒ Object

GRuby::Auth.oauth2_url(state)



6
7
8
9
10
# File 'lib/g_ruby/auth.rb', line 6

def self.oauth2_url(state)
 a = "https://accounts.google.com/o/oauth2/auth?response_type=code&access_type=offline&approval_prompt=auto&client_id=#{GOOGLE_CLIENTID}&redirect_uri=#{GOOGLE_CALLBACK}&scope=https://www.googleapis.com/auth/analytics.readonly"
 a = a + "&state=#{state}"  if !state.blank?
 return a
end

.refresh(refresh_token) ⇒ Object

GRuby::Auth.refresh(refresh_token)



26
27
28
29
# File 'lib/g_ruby/auth.rb', line 26

def self.refresh(refresh_token) 
  g = Nestful.post "https://accounts.google.com/o/oauth2/token?method=POST&grant_type=refresh_token&refresh_token=#{refresh_token}&client_id=#{GOOGLE_CLIENTID}&client_secret=#{GOOGLE_SECRET}"
  return GRuby::Util.get_json(g)
end

.token(auth_code) ⇒ Object

GRuby::Auth.token(auth_code)



20
21
22
23
# File 'lib/g_ruby/auth.rb', line 20

def self.token(auth_code)
  g = Nestful.post "https://accounts.google.com/o/oauth2/token?method=POST&grant_type=authorization_code&code=#{auth_code}&client_id=#{GOOGLE_CLIENTID}&client_secret=#{GOOGLE_SECRET}&redirect_uri=#{GOOGLE_CALLBACK}"
  return GRuby::Util.get_json(g)
end