diff --git a/app/assets/javascripts/callbacks.js.coffee b/app/assets/javascripts/callbacks.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/callbacks.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/callbacks.css.scss b/app/assets/stylesheets/callbacks.css.scss deleted file mode 100644 index e4c4d53..0000000 --- a/app/assets/stylesheets/callbacks.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the callbacks controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/callbacks_controller.rb b/app/controllers/callbacks_controller.rb deleted file mode 100644 index ee64347..0000000 --- a/app/controllers/callbacks_controller.rb +++ /dev/null @@ -1,101 +0,0 @@ -class CallbacksController < ApplicationController - - def index - tkn = Token.first - - if tkn.nil? - redirect_to "/auth/google" and return - else - if tkn['spreadsheet_id'].nil? - @ws = getSheet(tkn) - render action: 'create' and return - end - end - @sheets = Token.all.to_a - end - - def omniauth - tkn = Token.new - auth_token = request.env["omniauth.auth"].fetch("credentials") - tkn["access_token"] = auth_token.fetch("token") - tkn["refresh_token"] = auth_token.fetch("refresh_token") - tkn["expires_at"] = auth_token.fetch("expires_at") - - if tkn.save - @ws = getSheet(tkn) - else - @ws = {error: "not able to save"} - end - - render action: 'create' and return - end - - def getSheet(tkn) - client = Google::APIClient.new - client.authorization.access_token = tkn['access_token'] - drive = client.discovered_api('drive', 'v2') - - wks = client.execute( - api_method: drive.files.list, - parameters: {}, - headers: {'Content-Type'=>'application/json'} - ) - JSON.parse(wks.data.to_json) - end - - def setSheet - tkn = Token.first - tkn['spreadsheet_id'] = params['id'] - tkn.save - - insertEmailInDatabase(tkn) - - redirect_to users_path - end - - def insertEmailInDatabase(tkn) - @tkn = tkn - session = GoogleDrive.login_with_oauth(@tkn["access_token"]) - @ws = session.spreadsheet_by_key(@tkn['spreadsheet_id']).worksheets[0] - - rowcount = @ws.rows.count - - (rowcount).times do |i| - User.create(email_id: @ws[i + 1, 1], - is_subscribed: true, - joined_on: Date.today, - source: "Google Spreadsheet") - end - - end - - def refresh_token(tkn) - data = { - client_id: ENV['GOOGLE_ID'], - client_secret: ENV['GOOGLE_KEY'], - refresh_token: tkn['refresh_token'], - grant_type: 'refresh_token' - } - re = ActiveSupport::JSON.decode(RestClient.post 'https://accounts.google.com/o/oauth2/token', data) - - sheets = Token.where(spreadsheet_id: tkn['spreadsheet_id'])[0] - sheets['access_token'] = re['access_token'] - sheets['expires_at'] = (Time.now + re['expires_in'].second).localtime - sheets.save - - re - end - - def update - tkn = Token.where(spreadsheet_id: params['id']) - @tkn = tkn[0] - unless Time.now > tkn[0]['expires_at'] - @ref = refresh_token tkn[0] - end - tkn = Token.where(spreadsheet_id: params['id']) - insertEmailInDatabase(tkn[0]) - redirect_to users_path - #render action: 'test' - end - -end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 8d69641..95f2992 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,22 +1,4 @@ class HomeController < ApplicationController def index end - - def add_from_google - @sheets = Token.first - @client = Google::APIClient.new - @client.authorization.access_token = @sheets['access_token'] - @client.authorization.client_id = ENV["GOOGLE_ID"] - @client.authorization.client_secret = ENV["GOOGLE_KEY"] - @client.authorization.refresh_token = @sheets["refresh_token"] - @re = @client.auto_refresh_token - #session = GoogleDrive.login_with_oauth(tkn["access_token"]) - drive = @client.discovered_api('drive', 'v2') - - @wks = @client.execute( - api_method: drive.files.watch, - parameters: {fileId: @sheets["spreadsheet_id"]}, - headers: {'Content-Type'=>'application/json'} - ) - end end diff --git a/app/models/token.rb b/app/models/token.rb deleted file mode 100644 index a356603..0000000 --- a/app/models/token.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Token - include Mongoid::Document - - field :spreadsheet_id, type: String - field :refresh_token, type: String - field :expires_at, type: Time - field :access_token, type: String -end \ No newline at end of file diff --git a/app/views/callbacks/create.html.haml b/app/views/callbacks/create.html.haml deleted file mode 100644 index 416830f..0000000 --- a/app/views/callbacks/create.html.haml +++ /dev/null @@ -1,4 +0,0 @@ --count = @ws["items"].count --count.times do |i| - =link_to @ws["items"][i]["title"], set_sheet_path(@ws["items"][i]["id"]) if @ws["items"][i]["mimeType"].include?("spreadsheet") - %br \ No newline at end of file diff --git a/app/views/callbacks/createv1.html.erb b/app/views/callbacks/createv1.html.erb deleted file mode 100644 index 2cdb756..0000000 --- a/app/views/callbacks/createv1.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<% #@ws['items'].each do |i| %> - <% #i.each do |j| %> - <%#=j%> - <%# end %> -<%# end %> - -<% @ws['items'].each do |i| %> - <%= link_to i['title'], set_sheet_path(i['id']) if i['mimeType'].include?("spreadsheet") %>
-<% end %> \ No newline at end of file diff --git a/app/views/callbacks/failure.html.haml b/app/views/callbacks/failure.html.haml deleted file mode 100644 index 2395e1d..0000000 --- a/app/views/callbacks/failure.html.haml +++ /dev/null @@ -1 +0,0 @@ -this is callbacks#failure \ No newline at end of file diff --git a/app/views/callbacks/index.html.haml b/app/views/callbacks/index.html.haml deleted file mode 100644 index 42a9da8..0000000 --- a/app/views/callbacks/index.html.haml +++ /dev/null @@ -1,14 +0,0 @@ -=@msg -=#debug @ref - -%br -= Time.now -%table.table - -@sheets.count.times do |i| - %tr - %td - = @sheets[i]["access_token"] - %td - = link_to "Update", callback_update_path(@sheets[i]["spreadsheet_id"]) - %td - = @sheets[i]["expires_at"] \ No newline at end of file diff --git a/app/views/callbacks/setSheet.html.erb b/app/views/callbacks/setSheet.html.erb deleted file mode 100644 index 3fd2d7a..0000000 --- a/app/views/callbacks/setSheet.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<% @ws.rows.each do |r| %> - <% r.each do |c| %> - <%= c %>
- <%end%> -<%end%> \ No newline at end of file diff --git a/app/views/callbacks/test.html.haml b/app/views/callbacks/test.html.haml deleted file mode 100644 index d3356e4..0000000 --- a/app/views/callbacks/test.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -=debug @tkn -=debug @ref.class -=debug @ref -=debug @tkn['expires_at'].localtime \ No newline at end of file diff --git a/app/views/create.html.erb b/app/views/create.html.erb deleted file mode 100644 index 2cdb756..0000000 --- a/app/views/create.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<% #@ws['items'].each do |i| %> - <% #i.each do |j| %> - <%#=j%> - <%# end %> -<%# end %> - -<% @ws['items'].each do |i| %> - <%= link_to i['title'], set_sheet_path(i['id']) if i['mimeType'].include?("spreadsheet") %>
-<% end %> \ No newline at end of file diff --git a/app/views/failure.html.erb b/app/views/failure.html.erb deleted file mode 100644 index 812fb59..0000000 --- a/app/views/failure.html.erb +++ /dev/null @@ -1 +0,0 @@ -this is callbacks#failure diff --git a/app/views/home/add_from_google.html.haml b/app/views/home/add_from_google.html.haml deleted file mode 100644 index 47f8914..0000000 --- a/app/views/home/add_from_google.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -=@sheets["spreadsheet_id"] -%br -=#@client.authorization.methods -=debug @re -%br - -=#debug @wks \ No newline at end of file diff --git a/app/views/setSheet.html.erb b/app/views/setSheet.html.erb deleted file mode 100644 index 3fd2d7a..0000000 --- a/app/views/setSheet.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<% @ws.rows.each do |r| %> - <% r.each do |c| %> - <%= c %>
- <%end%> -<%end%> \ No newline at end of file diff --git a/spec/controllers/callbacks_controller_spec.rb b/spec/controllers/callbacks_controller_spec.rb deleted file mode 100644 index 08d5496..0000000 --- a/spec/controllers/callbacks_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CallbacksController, :type => :controller do - -end diff --git a/spec/factories/tokens.rb b/spec/factories/tokens.rb deleted file mode 100644 index 37cbfd0..0000000 --- a/spec/factories/tokens.rb +++ /dev/null @@ -1,6 +0,0 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl - -FactoryGirl.define do - factory :token do - end -end diff --git a/spec/helpers/callbacks_helper_spec.rb b/spec/helpers/callbacks_helper_spec.rb deleted file mode 100644 index d10c6fd..0000000 --- a/spec/helpers/callbacks_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the CallbacksHelper. For example: -# -# describe CallbacksHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe CallbacksHelper, :type => :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/token_spec.rb b/spec/models/token_spec.rb deleted file mode 100644 index 76bf2eb..0000000 --- a/spec/models/token_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Token, :type => :model do - pending "add some examples to (or delete) #{__FILE__}" -end