Skip to content

Commit be8827b

Browse files
committed
cleaned up code
1 parent c8c50db commit be8827b

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

Diff for: app/controllers/callbacks_controller.rb

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class CallbacksController < ApplicationController
22

33
def index
4-
#Token.delete_all
54
tkn = Token.first
65

76
if tkn.nil?
@@ -17,7 +16,6 @@ def index
1716

1817
def omniauth
1918
tkn = Token.new
20-
req = request.env["omniauth.auth"]
2119
auth_token = request.env["omniauth.auth"].fetch("credentials")
2220
tkn["access_token"] = auth_token.fetch("token")
2321
tkn["refresh_token"] = auth_token.fetch("refresh_token")
@@ -35,7 +33,6 @@ def omniauth
3533
def getSheet(tkn)
3634
client = Google::APIClient.new
3735
client.authorization.access_token = tkn['access_token']
38-
#session = GoogleDrive.login_with_oauth(tkn["access_token"])
3936
drive = client.discovered_api('drive', 'v2')
4037

4138
wks = client.execute(
@@ -62,17 +59,14 @@ def insertEmailInDatabase(tkn)
6259
@ws = session.spreadsheet_by_key(@tkn['spreadsheet_id']).worksheets[0]
6360

6461
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
7462

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+
7670
end
7771

7872
def refresh_token(tkn)
@@ -83,14 +77,7 @@ def refresh_token(tkn)
8377
grant_type: 'refresh_token'
8478
}
8579
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+
9481
sheets = Token.where(spreadsheet_id: tkn['spreadsheet_id'])[0]
9582
sheets['access_token'] = re['access_token']
9683
sheets['expires_at'] = (Time.now + re['expires_in'].second).localtime

0 commit comments

Comments
 (0)