Skip to content

Commit

Permalink
Merge branch 'master' of github.com:joshsoftware/lightair
Browse files Browse the repository at this point in the history
Conflicts:
	Gemfile
	Gemfile.lock
	app/views/layouts/application.html.haml
	config/routes.rb
	spec/spec_helper.rb
  • Loading branch information
kanhaiyasharma007 committed Jul 15, 2014
2 parents 7db9f6f + cb502c2 commit 5a84beb
Show file tree
Hide file tree
Showing 34 changed files with 2,560 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ build/
/log/
/tmp
*.log
test.html.haml

26 changes: 19 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ gem 'spring', group: :development
# gem 'debugger', group: [:development, :test]

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

# Use linkedin to interface with linkedin api
#gem 'omniauth-linkedin-oauth2'
gem 'linkedin'

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

# The following gems for testing purpose in development and testing environment
group :development, :test do
# Rspec is used to write the test cases
# Rspec is used to write the test cases
gem 'rspec-rails'
# Use factory girl to pass random data for test cases
# Use factory girl to pass random data for test cases
gem 'factory_girl_rails'
# Use faker to generate fake strings and data
# Use faker to generate fake strings and data
gem 'faker'
# Use to clean database after executing a test case
# Use to clean database after executing a test case
gem 'database_cleaner'
# Use to track how much code has been tested
gem 'simplecov'
# Use to track how much code has been tested
gem 'simplecov', '~> 0.7.1'
end

group :test do
# Webmock to stub http requests
gem 'webmock'
# VCR to record the responses from web and replay them when needed
gem 'vcr'
end

gem 'simple_form'
Expand All @@ -88,3 +98,5 @@ gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
gem 'mini_magick'
gem 'redis-rails'
gem 'redis-namespace'
gem 'pry'
gem 'rest_client'
87 changes: 75 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: git://github.com/SixiS/google-drive-ruby
revision: 7a58b426959727aef9d7e99a9942e945f836875a
specs:
google_drive (0.3.9)
nokogiri (>= 1.4.4, != 1.5.2, != 1.5.1)
oauth (>= 0.3.6)
oauth2 (>= 0.5.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -27,7 +36,12 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
addressable (2.3.6)
arel (5.0.1.20140414130214)
autoparse (0.3.3)
addressable (>= 2.3.1)
extlib (>= 0.9.15)
multi_json (>= 1.0.0)
bcrypt (3.1.7)
bootstrap-datepicker-rails (1.3.0.2)
railties (>= 3.0)
Expand All @@ -46,6 +60,7 @@ GEM
mongoid-grid_fs (>= 1.3, < 3.0)
celluloid (0.15.2)
timers (~> 1.1.0)
coderay (1.1.0)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
Expand All @@ -54,6 +69,8 @@ GEM
execjs
coffee-script-source (1.7.0)
connection_pool (2.0.0)
crack (0.4.2)
safe_yaml (~> 1.0.0)
database_cleaner (1.3.0)
devise (3.2.4)
bcrypt (~> 3.0)
Expand All @@ -65,9 +82,9 @@ GEM
actionmailer (>= 3.2.6, < 5)
devise (>= 3.2.0)
diff-lcs (1.2.5)
docile (1.1.5)
erubis (2.7.0)
execjs (2.2.1)
extlib (0.9.16)
factory_girl (4.4.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.4.1)
Expand All @@ -77,10 +94,17 @@ GEM
i18n (~> 0.5)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
google_drive (0.3.9)
nokogiri (>= 1.4.4, != 1.5.2, != 1.5.1)
oauth (>= 0.3.6)
oauth2 (>= 0.5.0)
google-api-client (0.7.1)
addressable (>= 2.3.2)
autoparse (>= 0.3.3)
extlib (>= 0.9.15)
faraday (>= 0.9.0)
jwt (>= 0.1.5)
launchy (>= 2.1.1)
multi_json (>= 1.0.0)
retriable (>= 1.4)
signet (>= 0.5.0)
uuidtools (>= 2.1.0)
haml (4.0.5)
tilt
haml-rails (0.5.3)
Expand All @@ -99,6 +123,8 @@ GEM
thor (>= 0.14, < 2.0)
json (1.8.1)
jwt (1.0.0)
launchy (2.4.2)
addressable (~> 2.3)
libv8 (3.16.14.3)
linkedin (0.4.7)
hashie (~> 2.0)
Expand All @@ -107,6 +133,7 @@ GEM
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8.2)
mime-types (1.25.1)
mini_magick (3.7.0)
subexec (~> 0.2.1)
Expand All @@ -127,6 +154,7 @@ GEM
multi_json (1.10.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
netrc (0.7.7)
nokogiri (1.6.2.1)
mini_portile (= 0.6.0)
oauth (0.4.7)
Expand All @@ -136,10 +164,25 @@ GEM
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
omniauth (1.2.1)
hashie (>= 1.2, < 3)
rack (~> 1.0)
omniauth-google-oauth2 (0.2.4)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)
omniauth-oauth2 (1.1.2)
faraday (>= 0.8, < 0.10)
multi_json (~> 1.3)
oauth2 (~> 0.9.3)
omniauth (~> 1.2)
optionable (0.2.0)
origin (2.1.1)
orm_adapter (0.5.0)
polyglot (0.3.5)
pry (0.10.0)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
Expand Down Expand Up @@ -185,6 +228,9 @@ GEM
redis-store (1.1.4)
redis (>= 2.2)
ref (1.0.5)
rest_client (1.7.3)
netrc (~> 0.7.7)
retriable (1.4.1)
rspec-core (3.0.2)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.2)
Expand All @@ -201,6 +247,7 @@ GEM
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.2)
safe_yaml (1.0.3)
sass (3.2.19)
sass-rails (4.0.3)
railties (>= 4.0.0, < 5.0)
Expand All @@ -219,14 +266,19 @@ GEM
json
redis (>= 3.0.6)
redis-namespace (>= 1.3.1)
signet (0.5.1)
addressable (>= 2.2.3)
faraday (>= 0.9.0.rc5)
jwt (>= 0.1.5)
multi_json (>= 1.0.0)
simple_form (3.0.2)
actionpack (~> 4.0)
activemodel (~> 4.0)
simplecov (0.8.2)
docile (~> 1.1.0)
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
slop (3.5.0)
spring (1.1.3)
sprockets (2.11.0)
hike (~> 1.2)
Expand Down Expand Up @@ -255,8 +307,13 @@ GEM
uglifier (2.5.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
uuidtools (2.1.4)
vcr (2.9.2)
warden (1.2.3)
rack (>= 1.0)
webmock (1.18.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)

PLATFORMS
ruby
Expand All @@ -272,26 +329,32 @@ DEPENDENCIES
devise_invitable
factory_girl_rails
faker
google_drive
google-api-client
google_drive!
haml
haml-rails
jbuilder (~> 2.0)
jquery-rails
linkedin
mini_magick
mongoid
omniauth-google-oauth2
pry
rails (= 4.1.2)
redactor-rails
redis-namespace
redis-rails
rest_client
rspec-rails
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
sendgrid
sidekiq
simple_form
simplecov
simplecov (~> 0.7.1)
spring
therubyracer
turbolinks
uglifier (>= 1.3.0)
vcr
webmock
6 changes: 6 additions & 0 deletions app/assets/javascripts/spreadsheets.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 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/
xyz = ->
alert "welcome"
return
1 change: 1 addition & 0 deletions app/assets/stylesheets/bootstrap_config.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "bootstrap";

body
{
padding-top: 80px;
Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/spreadsheets.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the spreadsheets controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
70 changes: 70 additions & 0 deletions app/controllers/spreadsheets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class SpreadsheetsController < ApplicationController
require 'google'
include Google::Spreadsheets

def index
@spreadsheets = Spreadsheet.all.to_a
end

def new
if params[:access_token]
spreadsheet = Spreadsheet.where(access_token: params['access_token'])[0]
else
spreadsheet = Spreadsheet.new
spreadsheet.add_tokens(request.env['omniauth.auth'].fetch('credentials'))
end

if spreadsheet.save
# Spreadsheets from google
@spreadsheets = list(spreadsheet)
@token = spreadsheet.access_token
else
# Handle if data does not get saved
@msg = 'Getting same access token. Try deleting '
end
end

def edit
token = spreadsheet_params['token']
spreadsheet = Spreadsheet.where(access_token: token)[0]

if spreadsheet.add_spreadsheet_credentials(spreadsheet_params)
spreadsheet.save
else
@error = 'Already Present'
end

@spreadsheets = Spreadsheet.all.to_a

render action: 'index'
end

def update
spreadsheet = Spreadsheet.find(params['id'])
@worksheet = worksheets(spreadsheet)
User.add_users_from_worksheet(@worksheet)

redirect_to users_path
end

def destroy
Spreadsheet.find(params['id']).delete
redirect_to spreadsheets_path
end

def failure
if params['message'].match('access_denied')
@msg = 'Account integration Failed. User Refused to grant permissions'
end
@spreadsheets = Spreadsheet.all.to_a
render action: 'index'
end

#################################
private
#################################

def spreadsheet_params
params.permit(:title, :id, :token)
end
end
2 changes: 2 additions & 0 deletions app/helpers/spreadsheets_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SpreadsheetsHelper
end
27 changes: 27 additions & 0 deletions app/models/spreadsheet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Spreadsheet
include Mongoid::Document

field :spreadsheet_id, type: String
field :spreadsheet_title, type: String
field :refresh_token, type: String
field :expires_at, type: Time
field :access_token, type: String

validates :access_token, presence: true, uniqueness: true

def add_tokens(tokens = {})
self['access_token'] = tokens.fetch('token')
self['refresh_token'] = tokens.fetch('refresh_token')
self['expires_at'] = tokens.fetch('expires_at')
end

def add_spreadsheet_credentials(credentials = {})
self['spreadsheet_id'] = credentials['id']
self['spreadsheet_title'] = credentials['title']
end

def access_token
self['access_token']
end

end
Loading

0 comments on commit 5a84beb

Please sign in to comment.