1
1
class CallbacksController < ApplicationController
2
2
3
3
def index
4
- #Token.delete_all
5
4
tkn = Token . first
6
5
7
6
if tkn . nil?
@@ -17,7 +16,6 @@ def index
17
16
18
17
def omniauth
19
18
tkn = Token . new
20
- req = request . env [ "omniauth.auth" ]
21
19
auth_token = request . env [ "omniauth.auth" ] . fetch ( "credentials" )
22
20
tkn [ "access_token" ] = auth_token . fetch ( "token" )
23
21
tkn [ "refresh_token" ] = auth_token . fetch ( "refresh_token" )
@@ -35,7 +33,6 @@ def omniauth
35
33
def getSheet ( tkn )
36
34
client = Google ::APIClient . new
37
35
client . authorization . access_token = tkn [ 'access_token' ]
38
- #session = GoogleDrive.login_with_oauth(tkn["access_token"])
39
36
drive = client . discovered_api ( 'drive' , 'v2' )
40
37
41
38
wks = client . execute (
@@ -62,17 +59,14 @@ def insertEmailInDatabase(tkn)
62
59
@ws = session . spreadsheet_by_key ( @tkn [ 'spreadsheet_id' ] ) . worksheets [ 0 ]
63
60
64
61
rowcount = @ws . rows . count
65
- usercount = User . count
66
- #if rowcount > usercount
67
- ( rowcount ) . times do |i |
68
- User . create ( email_id : @ws [ i + 1 , 1 ] , # + usercount, 1],
69
- is_subscribed : true ,
70
- joined_on : Date . today ,
71
- source : "Google Spreadsheet" )
72
- end
73
- #end
74
62
75
- #render action: "test"
63
+ ( rowcount ) . times do |i |
64
+ User . create ( email_id : @ws [ i + 1 , 1 ] ,
65
+ is_subscribed : true ,
66
+ joined_on : Date . today ,
67
+ source : "Google Spreadsheet" )
68
+ end
69
+
76
70
end
77
71
78
72
def refresh_token ( tkn )
@@ -83,14 +77,7 @@ def refresh_token(tkn)
83
77
grant_type : 'refresh_token'
84
78
}
85
79
re = ActiveSupport ::JSON . decode ( RestClient . post 'https://accounts.google.com/o/oauth2/token' , data )
86
- =begin
87
- client = Google::APIClient.new
88
- client.authorization.access_token = tkn['access_token']
89
- client.authorization.client_id = ENV["GOOGLE_ID"]
90
- client.authorization.client_secret = ENV["GOOGLE_KEY"]
91
- client.authorization.refresh_token = tkn["refresh_token"]
92
- re = client.authorization.update_token!
93
- =end
80
+
94
81
sheets = Token . where ( spreadsheet_id : tkn [ 'spreadsheet_id' ] ) [ 0 ]
95
82
sheets [ 'access_token' ] = re [ 'access_token' ]
96
83
sheets [ 'expires_at' ] = ( Time . now + re [ 'expires_in' ] . second ) . localtime
0 commit comments