Skip to content

Commit 5a84beb

Browse files
Merge branch 'master' of github.com:joshsoftware/lightair
Conflicts: Gemfile Gemfile.lock app/views/layouts/application.html.haml config/routes.rb spec/spec_helper.rb
2 parents 7db9f6f + cb502c2 commit 5a84beb

34 files changed

+2560
-45
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ build/
4848
/log/
4949
/tmp
5050
*.log
51+
test.html.haml
52+

Gemfile

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ gem 'spring', group: :development
4242
# gem 'debugger', group: [:development, :test]
4343

4444
# Use google_drive to read/write files or spreadsheets from google drive
45-
gem 'google_drive'
45+
gem 'omniauth-google-oauth2'
46+
gem 'google-api-client', require: 'google/api_client'
47+
gem 'google_drive', git: 'git://github.com/SixiS/google-drive-ruby'
4648

4749
# Use linkedin to interface with linkedin api
50+
#gem 'omniauth-linkedin-oauth2'
4851
gem 'linkedin'
4952

5053
# Use sendrid to access sendgrid api to send mails and get their status
@@ -68,16 +71,23 @@ gem 'bootstrap-datepicker-rails'
6871

6972
# The following gems for testing purpose in development and testing environment
7073
group :development, :test do
71-
# Rspec is used to write the test cases
74+
# Rspec is used to write the test cases
7275
gem 'rspec-rails'
73-
# Use factory girl to pass random data for test cases
76+
# Use factory girl to pass random data for test cases
7477
gem 'factory_girl_rails'
75-
# Use faker to generate fake strings and data
78+
# Use faker to generate fake strings and data
7679
gem 'faker'
77-
# Use to clean database after executing a test case
80+
# Use to clean database after executing a test case
7881
gem 'database_cleaner'
79-
# Use to track how much code has been tested
80-
gem 'simplecov'
82+
# Use to track how much code has been tested
83+
gem 'simplecov', '~> 0.7.1'
84+
end
85+
86+
group :test do
87+
# Webmock to stub http requests
88+
gem 'webmock'
89+
# VCR to record the responses from web and replay them when needed
90+
gem 'vcr'
8191
end
8292

8393
gem 'simple_form'
@@ -88,3 +98,5 @@ gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
8898
gem 'mini_magick'
8999
gem 'redis-rails'
90100
gem 'redis-namespace'
101+
gem 'pry'
102+
gem 'rest_client'

Gemfile.lock

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
GIT
2+
remote: git://github.com/SixiS/google-drive-ruby
3+
revision: 7a58b426959727aef9d7e99a9942e945f836875a
4+
specs:
5+
google_drive (0.3.9)
6+
nokogiri (>= 1.4.4, != 1.5.2, != 1.5.1)
7+
oauth (>= 0.3.6)
8+
oauth2 (>= 0.5.0)
9+
110
GEM
211
remote: https://rubygems.org/
312
specs:
@@ -27,7 +36,12 @@ GEM
2736
minitest (~> 5.1)
2837
thread_safe (~> 0.1)
2938
tzinfo (~> 1.1)
39+
addressable (2.3.6)
3040
arel (5.0.1.20140414130214)
41+
autoparse (0.3.3)
42+
addressable (>= 2.3.1)
43+
extlib (>= 0.9.15)
44+
multi_json (>= 1.0.0)
3145
bcrypt (3.1.7)
3246
bootstrap-datepicker-rails (1.3.0.2)
3347
railties (>= 3.0)
@@ -46,6 +60,7 @@ GEM
4660
mongoid-grid_fs (>= 1.3, < 3.0)
4761
celluloid (0.15.2)
4862
timers (~> 1.1.0)
63+
coderay (1.1.0)
4964
coffee-rails (4.0.1)
5065
coffee-script (>= 2.2.0)
5166
railties (>= 4.0.0, < 5.0)
@@ -54,6 +69,8 @@ GEM
5469
execjs
5570
coffee-script-source (1.7.0)
5671
connection_pool (2.0.0)
72+
crack (0.4.2)
73+
safe_yaml (~> 1.0.0)
5774
database_cleaner (1.3.0)
5875
devise (3.2.4)
5976
bcrypt (~> 3.0)
@@ -65,9 +82,9 @@ GEM
6582
actionmailer (>= 3.2.6, < 5)
6683
devise (>= 3.2.0)
6784
diff-lcs (1.2.5)
68-
docile (1.1.5)
6985
erubis (2.7.0)
7086
execjs (2.2.1)
87+
extlib (0.9.16)
7188
factory_girl (4.4.0)
7289
activesupport (>= 3.0.0)
7390
factory_girl_rails (4.4.1)
@@ -77,10 +94,17 @@ GEM
7794
i18n (~> 0.5)
7895
faraday (0.9.0)
7996
multipart-post (>= 1.2, < 3)
80-
google_drive (0.3.9)
81-
nokogiri (>= 1.4.4, != 1.5.2, != 1.5.1)
82-
oauth (>= 0.3.6)
83-
oauth2 (>= 0.5.0)
97+
google-api-client (0.7.1)
98+
addressable (>= 2.3.2)
99+
autoparse (>= 0.3.3)
100+
extlib (>= 0.9.15)
101+
faraday (>= 0.9.0)
102+
jwt (>= 0.1.5)
103+
launchy (>= 2.1.1)
104+
multi_json (>= 1.0.0)
105+
retriable (>= 1.4)
106+
signet (>= 0.5.0)
107+
uuidtools (>= 2.1.0)
84108
haml (4.0.5)
85109
tilt
86110
haml-rails (0.5.3)
@@ -99,6 +123,8 @@ GEM
99123
thor (>= 0.14, < 2.0)
100124
json (1.8.1)
101125
jwt (1.0.0)
126+
launchy (2.4.2)
127+
addressable (~> 2.3)
102128
libv8 (3.16.14.3)
103129
linkedin (0.4.7)
104130
hashie (~> 2.0)
@@ -107,6 +133,7 @@ GEM
107133
mail (2.5.4)
108134
mime-types (~> 1.16)
109135
treetop (~> 1.4.8)
136+
method_source (0.8.2)
110137
mime-types (1.25.1)
111138
mini_magick (3.7.0)
112139
subexec (~> 0.2.1)
@@ -127,6 +154,7 @@ GEM
127154
multi_json (1.10.1)
128155
multi_xml (0.5.5)
129156
multipart-post (2.0.0)
157+
netrc (0.7.7)
130158
nokogiri (1.6.2.1)
131159
mini_portile (= 0.6.0)
132160
oauth (0.4.7)
@@ -136,10 +164,25 @@ GEM
136164
multi_json (~> 1.3)
137165
multi_xml (~> 0.5)
138166
rack (~> 1.2)
167+
omniauth (1.2.1)
168+
hashie (>= 1.2, < 3)
169+
rack (~> 1.0)
170+
omniauth-google-oauth2 (0.2.4)
171+
omniauth (~> 1.0)
172+
omniauth-oauth2 (~> 1.1)
173+
omniauth-oauth2 (1.1.2)
174+
faraday (>= 0.8, < 0.10)
175+
multi_json (~> 1.3)
176+
oauth2 (~> 0.9.3)
177+
omniauth (~> 1.2)
139178
optionable (0.2.0)
140179
origin (2.1.1)
141180
orm_adapter (0.5.0)
142181
polyglot (0.3.5)
182+
pry (0.10.0)
183+
coderay (~> 1.1.0)
184+
method_source (~> 0.8.1)
185+
slop (~> 3.4)
143186
rack (1.5.2)
144187
rack-test (0.6.2)
145188
rack (>= 1.0)
@@ -185,6 +228,9 @@ GEM
185228
redis-store (1.1.4)
186229
redis (>= 2.2)
187230
ref (1.0.5)
231+
rest_client (1.7.3)
232+
netrc (~> 0.7.7)
233+
retriable (1.4.1)
188234
rspec-core (3.0.2)
189235
rspec-support (~> 3.0.0)
190236
rspec-expectations (3.0.2)
@@ -201,6 +247,7 @@ GEM
201247
rspec-mocks (~> 3.0.0)
202248
rspec-support (~> 3.0.0)
203249
rspec-support (3.0.2)
250+
safe_yaml (1.0.3)
204251
sass (3.2.19)
205252
sass-rails (4.0.3)
206253
railties (>= 4.0.0, < 5.0)
@@ -219,14 +266,19 @@ GEM
219266
json
220267
redis (>= 3.0.6)
221268
redis-namespace (>= 1.3.1)
269+
signet (0.5.1)
270+
addressable (>= 2.2.3)
271+
faraday (>= 0.9.0.rc5)
272+
jwt (>= 0.1.5)
273+
multi_json (>= 1.0.0)
222274
simple_form (3.0.2)
223275
actionpack (~> 4.0)
224276
activemodel (~> 4.0)
225-
simplecov (0.8.2)
226-
docile (~> 1.1.0)
227-
multi_json
228-
simplecov-html (~> 0.8.0)
229-
simplecov-html (0.8.0)
277+
simplecov (0.7.1)
278+
multi_json (~> 1.0)
279+
simplecov-html (~> 0.7.1)
280+
simplecov-html (0.7.1)
281+
slop (3.5.0)
230282
spring (1.1.3)
231283
sprockets (2.11.0)
232284
hike (~> 1.2)
@@ -255,8 +307,13 @@ GEM
255307
uglifier (2.5.1)
256308
execjs (>= 0.3.0)
257309
json (>= 1.8.0)
310+
uuidtools (2.1.4)
311+
vcr (2.9.2)
258312
warden (1.2.3)
259313
rack (>= 1.0)
314+
webmock (1.18.0)
315+
addressable (>= 2.3.6)
316+
crack (>= 0.3.2)
260317

261318
PLATFORMS
262319
ruby
@@ -272,26 +329,32 @@ DEPENDENCIES
272329
devise_invitable
273330
factory_girl_rails
274331
faker
275-
google_drive
332+
google-api-client
333+
google_drive!
276334
haml
277335
haml-rails
278336
jbuilder (~> 2.0)
279337
jquery-rails
280338
linkedin
281339
mini_magick
282340
mongoid
341+
omniauth-google-oauth2
342+
pry
283343
rails (= 4.1.2)
284344
redactor-rails
285345
redis-namespace
286346
redis-rails
347+
rest_client
287348
rspec-rails
288349
sass-rails (~> 4.0.3)
289350
sdoc (~> 0.4.0)
290351
sendgrid
291352
sidekiq
292353
simple_form
293-
simplecov
354+
simplecov (~> 0.7.1)
294355
spring
295356
therubyracer
296357
turbolinks
297358
uglifier (>= 1.3.0)
359+
vcr
360+
webmock
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://coffeescript.org/
4+
xyz = ->
5+
alert "welcome"
6+
return

app/assets/stylesheets/bootstrap_config.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import "bootstrap";
2+
23
body
34
{
45
padding-top: 80px;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the spreadsheets controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
class SpreadsheetsController < ApplicationController
2+
require 'google'
3+
include Google::Spreadsheets
4+
5+
def index
6+
@spreadsheets = Spreadsheet.all.to_a
7+
end
8+
9+
def new
10+
if params[:access_token]
11+
spreadsheet = Spreadsheet.where(access_token: params['access_token'])[0]
12+
else
13+
spreadsheet = Spreadsheet.new
14+
spreadsheet.add_tokens(request.env['omniauth.auth'].fetch('credentials'))
15+
end
16+
17+
if spreadsheet.save
18+
# Spreadsheets from google
19+
@spreadsheets = list(spreadsheet)
20+
@token = spreadsheet.access_token
21+
else
22+
# Handle if data does not get saved
23+
@msg = 'Getting same access token. Try deleting '
24+
end
25+
end
26+
27+
def edit
28+
token = spreadsheet_params['token']
29+
spreadsheet = Spreadsheet.where(access_token: token)[0]
30+
31+
if spreadsheet.add_spreadsheet_credentials(spreadsheet_params)
32+
spreadsheet.save
33+
else
34+
@error = 'Already Present'
35+
end
36+
37+
@spreadsheets = Spreadsheet.all.to_a
38+
39+
render action: 'index'
40+
end
41+
42+
def update
43+
spreadsheet = Spreadsheet.find(params['id'])
44+
@worksheet = worksheets(spreadsheet)
45+
User.add_users_from_worksheet(@worksheet)
46+
47+
redirect_to users_path
48+
end
49+
50+
def destroy
51+
Spreadsheet.find(params['id']).delete
52+
redirect_to spreadsheets_path
53+
end
54+
55+
def failure
56+
if params['message'].match('access_denied')
57+
@msg = 'Account integration Failed. User Refused to grant permissions'
58+
end
59+
@spreadsheets = Spreadsheet.all.to_a
60+
render action: 'index'
61+
end
62+
63+
#################################
64+
private
65+
#################################
66+
67+
def spreadsheet_params
68+
params.permit(:title, :id, :token)
69+
end
70+
end

app/helpers/spreadsheets_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module SpreadsheetsHelper
2+
end

app/models/spreadsheet.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Spreadsheet
2+
include Mongoid::Document
3+
4+
field :spreadsheet_id, type: String
5+
field :spreadsheet_title, type: String
6+
field :refresh_token, type: String
7+
field :expires_at, type: Time
8+
field :access_token, type: String
9+
10+
validates :access_token, presence: true, uniqueness: true
11+
12+
def add_tokens(tokens = {})
13+
self['access_token'] = tokens.fetch('token')
14+
self['refresh_token'] = tokens.fetch('refresh_token')
15+
self['expires_at'] = tokens.fetch('expires_at')
16+
end
17+
18+
def add_spreadsheet_credentials(credentials = {})
19+
self['spreadsheet_id'] = credentials['id']
20+
self['spreadsheet_title'] = credentials['title']
21+
end
22+
23+
def access_token
24+
self['access_token']
25+
end
26+
27+
end

0 commit comments

Comments
 (0)