gdrivestrg 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Rakefile +2 -0
  2. data/app/assets/javascripts/gdrivestrg/application.js +15 -0
  3. data/app/assets/javascripts/gdrivestrg/params.js +2 -0
  4. data/app/assets/stylesheets/gdrivestrg/application.css +13 -0
  5. data/app/assets/stylesheets/gdrivestrg/params.css +4 -0
  6. data/app/assets/stylesheets/scaffold.css +56 -0
  7. data/app/controllers/gdrivestrg/application_controller.rb +4 -0
  8. data/app/controllers/gdrivestrg/params_controller.rb +87 -0
  9. data/app/helpers/gdrivestrg/application_helper.rb +4 -0
  10. data/app/helpers/gdrivestrg/params_helper.rb +4 -0
  11. data/app/models/gdrivestrg/param.rb +7 -0
  12. data/app/models/gdrivestrg/param.rb~ +18 -0
  13. data/app/views/gdrivestrg/params/_form.html.erb +29 -0
  14. data/app/views/gdrivestrg/params/edit.html.erb +6 -0
  15. data/app/views/gdrivestrg/params/index.html.erb +27 -0
  16. data/app/views/gdrivestrg/params/new.html.erb +5 -0
  17. data/app/views/gdrivestrg/params/show.html.erb +20 -0
  18. data/app/views/layouts/gdrivestrg/application.html.erb +14 -0
  19. data/config/routes.rb +4 -0
  20. data/db/migrate/20121107140721_create_gdrivestrg_params.rb +27 -0
  21. data/db/migrate/20121107140721_create_gdrivestrg_params.rb~ +29 -0
  22. data/db/migrate/20121108121038_add_user_id_to_gdrivestrg_params.rb +5 -0
  23. data/db/migrate/20121108121038_add_user_id_to_gdrivestrg_params.rb~ +5 -0
  24. data/lib/gdrivestrg/engine.rb +7 -0
  25. data/lib/gdrivestrg/engine.rb~ +5 -0
  26. data/lib/gdrivestrg/gdrivestrg.rb +24 -21
  27. data/lib/gdrivestrg/gdrivestrg.rb~ +25 -22
  28. data/lib/gdrivestrg/version.rb +1 -1
  29. data/lib/gdrivestrg.rb +3 -0
  30. data/lib/gdrivestrg.rb~ +4 -0
  31. data/test/dummy/config/initializers/secret_token.rb +1 -1
  32. data/test/dummy/config/routes.rb +2 -56
  33. data/test/fixtures/gdrivestrg/params.yml +11 -0
  34. data/test/functional/gdrivestrg/params_controller_test.rb +51 -0
  35. data/test/integration/navigation_test.rb +10 -0
  36. data/test/unit/gdrivestrg/param_test.rb +9 -0
  37. data/test/unit/helpers/gdrivestrg/params_helper_test.rb +6 -0
  38. metadata +55 -9
  39. data/lib/generators/cloudstrg_generator.rb~ +0 -19
  40. data/lib/generators/dropboxstrg_generator.rb~ +0 -19
  41. data/lib/generators/gdrivestrg_generator.rb +0 -16
  42. data/lib/generators/gdrivestrg_generator.rb~ +0 -16
  43. data/lib/templates/create_gdrivestrgfields.rb +0 -17
data/Rakefile CHANGED
@@ -20,6 +20,8 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
23
25
 
24
26
 
25
27
 
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,4 @@
1
+ module Gdrivestrg
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,87 @@
1
+ require_dependency "gdrivestrg/application_controller"
2
+
3
+ module Gdrivestrg
4
+ class ParamsController < ApplicationController
5
+ # GET /params
6
+ # GET /params.json
7
+ def index
8
+ @params = Param.all
9
+
10
+ respond_to do |format|
11
+ format.html # index.html.erb
12
+ format.json { render json: @params }
13
+ end
14
+ end
15
+
16
+ # GET /params/1
17
+ # GET /params/1.json
18
+ def show
19
+ @param = Param.find(params[:id])
20
+
21
+ respond_to do |format|
22
+ format.html # show.html.erb
23
+ format.json { render json: @param }
24
+ end
25
+ end
26
+
27
+ # GET /params/new
28
+ # GET /params/new.json
29
+ def new
30
+ @param = Param.new
31
+
32
+ respond_to do |format|
33
+ format.html # new.html.erb
34
+ format.json { render json: @param }
35
+ end
36
+ end
37
+
38
+ # GET /params/1/edit
39
+ def edit
40
+ @param = Param.find(params[:id])
41
+ end
42
+
43
+ # POST /params
44
+ # POST /params.json
45
+ def create
46
+ @param = Param.new(params[:param])
47
+
48
+ respond_to do |format|
49
+ if @param.save
50
+ format.html { redirect_to @param, notice: 'Param was successfully created.' }
51
+ format.json { render json: @param, status: :created, location: @param }
52
+ else
53
+ format.html { render action: "new" }
54
+ format.json { render json: @param.errors, status: :unprocessable_entity }
55
+ end
56
+ end
57
+ end
58
+
59
+ # PUT /params/1
60
+ # PUT /params/1.json
61
+ def update
62
+ @param = Param.find(params[:id])
63
+
64
+ respond_to do |format|
65
+ if @param.update_attributes(params[:param])
66
+ format.html { redirect_to @param, notice: 'Param was successfully updated.' }
67
+ format.json { head :no_content }
68
+ else
69
+ format.html { render action: "edit" }
70
+ format.json { render json: @param.errors, status: :unprocessable_entity }
71
+ end
72
+ end
73
+ end
74
+
75
+ # DELETE /params/1
76
+ # DELETE /params/1.json
77
+ def destroy
78
+ @param = Param.find(params[:id])
79
+ @param.destroy
80
+
81
+ respond_to do |format|
82
+ format.html { redirect_to params_url }
83
+ format.json { head :no_content }
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,4 @@
1
+ module Gdrivestrg
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Gdrivestrg
2
+ module ParamsHelper
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module Gdrivestrg
2
+ class Param < ActiveRecord::Base
3
+ attr_accessible :expires_in, :issued_at, :refresh_token
4
+
5
+ belongs_to :user, :class_name => Gdrivestrg.user_class
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module Gdrivestrg
2
+ class Param < ActiveRecord::Base
3
+ attr_accessible :expires_in, :issued_at, :refresh_token
4
+
5
+ attr_accessor :user_email
6
+ belongs_to :user, :class_name => Gdrivestrg.user_class
7
+
8
+ before_save :set_user
9
+
10
+ private
11
+ def set_user
12
+ self.user = Gdrivestrg.user_class.constantize.find_by_email(user_email)
13
+ if not self.user
14
+ return false
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ <%= form_for(@param) do |f| %>
2
+ <% if @param.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@param.errors.count, "error") %> prohibited this param from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @param.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :refresh_token %><br />
16
+ <%= f.text_field :refresh_token %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :expires_in %><br />
20
+ <%= f.number_field :expires_in %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :issued_at %><br />
24
+ <%= f.date_select :issued_at %>
25
+ </div>
26
+ <div class="actions">
27
+ <%= f.submit %>
28
+ </div>
29
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing param</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @param %> |
6
+ <%= link_to 'Back', params_path %>
@@ -0,0 +1,27 @@
1
+ <h1>Listing params</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Refresh token</th>
6
+ <th>Expires in</th>
7
+ <th>Issued at</th>
8
+ <th></th>
9
+ <th></th>
10
+ <th></th>
11
+ </tr>
12
+
13
+ <% @params.each do |param| %>
14
+ <tr>
15
+ <td><%= param.refresh_token %></td>
16
+ <td><%= param.expires_in %></td>
17
+ <td><%= param.issued_at %></td>
18
+ <td><%= link_to 'Show', param %></td>
19
+ <td><%= link_to 'Edit', edit_param_path(param) %></td>
20
+ <td><%= link_to 'Destroy', param, method: :delete, data: { confirm: 'Are you sure?' } %></td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+
25
+ <br />
26
+
27
+ <%= link_to 'New Param', new_param_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New param</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', params_path %>
@@ -0,0 +1,20 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Refresh token:</b>
5
+ <%= @param.refresh_token %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Expires in:</b>
10
+ <%= @param.expires_in %>
11
+ </p>
12
+
13
+ <p>
14
+ <b>Issued at:</b>
15
+ <%= @param.issued_at %>
16
+ </p>
17
+
18
+
19
+ <%= link_to 'Edit', edit_param_path(@param) %> |
20
+ <%= link_to 'Back', params_path %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Gdrivestrg</title>
5
+ <%= stylesheet_link_tag "gdrivestrg/application", :media => "all" %>
6
+ <%= javascript_include_tag "gdrivestrg/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Gdrivestrg::Engine.routes.draw do
2
+ resources :params
3
+
4
+ end
@@ -0,0 +1,27 @@
1
+ require 'gdrivestrg/version'
2
+
3
+ class CreateGdrivestrgParams < ActiveRecord::Migration
4
+ def change
5
+ create_table :gdrivestrg_params do |t|
6
+ t.string :refresh_token
7
+ t.integer :expires_in
8
+ t.date :issued_at
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ plugin = Cloudstrg::Cloudstrgplugin.find_by_plugin_name("gdrive")
14
+ if not plugin
15
+ puts "Inserting Google Drive plugin"
16
+ Cloudstrg::Cloudstrgplugin.create :plugin_name => "gdrive", :version => Gdrivestrg::VERSION
17
+ else
18
+ if Gdrivestrg::VERSION > plugin.version
19
+ puts "Updating Google Drive plugin version: #{Gdrivestrg::VERSION}"
20
+ plugin.version = Gdrivestrg::VERSION
21
+ plugin.save
22
+ else
23
+ puts "Google Drive plugin is up to date"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ require 'gdrivestrg/version'
2
+
3
+ class CreateGdrivestrgParams < ActiveRecord::Migration
4
+ def change
5
+ create_table :gdrivestrg_params do |t|
6
+ t.string :refresh_token
7
+ t.integer :expires_in
8
+ t.date :issued_at
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ plugins = Cloudstrg::Cloudstrgplugin.find_by_plugin_name("gdrive")
14
+ if not plugins
15
+ puts "Inserting Google Drive plugin"
16
+ Cloudstrg::Cloudstrgplugin.create :plugin_name => "gdrive", :version => Gdrivestrg::VERSION
17
+ else
18
+ plugins.each do |plugin|
19
+ if Gdrivestrg::VERSION > plugin.version
20
+ puts "Updating Google Drive plugin version: #{Gdrivestrg::VERSION}"
21
+ plugin.version = Gdrivestrg::VERSION
22
+ plugin.save
23
+ else
24
+ puts "Google Drive plugin is up to date"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ class AddUserIdToGdrivestrgParams < ActiveRecord::Migration
2
+ def change
3
+ add_column :gdrivestrg_params, "#{Gdrivestrg.user_class.downcase}_id".to_sym, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddUserIdToGdrivestrgParams < ActiveRecord::Migration
2
+ def change
3
+ add_column :gdrivestrg_params, "#{Gdrivestrg.user_class}_id".to_sym, :integer
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'cloudstrg/engine'
2
+
3
+ module Gdrivestrg
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Gdrivestrg
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Gdrivestrg
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Gdrivestrg
4
+ end
5
+ end
@@ -25,23 +25,26 @@ class GdriveStrg < CloudStrg::CloudStorage
25
25
  def config params
26
26
  @client.authorization.redirect_uri = params[:redirect]
27
27
 
28
- @username = params[:username]
29
- user = Cloudstrguser.find_by_name(@username)
28
+ @user = params[:user]
29
+ user_params = @user.gdrivestrgparams
30
+ if not user_params
31
+ user_params = @user.build_gdrivestrgparams
32
+ end
30
33
 
31
34
  session = params[:session]
32
35
 
33
- @client.authorization.update_token!(:access_token => session[:gdrive_access_token] , #:access_token => user.gdrive_access_token,
34
- :refresh_token => user.gdrive_refresh_token,
35
- :expires_in => user.gdrive_expires_in,
36
- :issued_at => user.gdrive_issued_at)
36
+ @client.authorization.update_token!(:access_token => session[:gdrive_access_token] , #:access_token => user_params.access_token,
37
+ :refresh_token => user_params.refresh_token,
38
+ :expires_in => user_params.expires_in,
39
+ :issued_at => user_params.issued_at)
37
40
  if @client.authorization.refresh_token && @client.authorization.expired?
38
41
  @client.authorization.fetch_access_token!
39
42
  session[:gdrive_access_token] = @client.authorization.access_token
40
43
  # user.gdrive_access_token = @client.authorization.access_token
41
- user.gdrive_refresh_token = @client.authorization.refresh_token
42
- user.gdrive_expires_in = @client.authorization.expires_in
43
- user.gdrive_issued_at = @client.authorization.issued_at
44
- user.save()
44
+ user_params.refresh_token = @client.authorization.refresh_token
45
+ user_params.expires_in = @client.authorization.expires_in
46
+ user_params.issued_at = @client.authorization.issued_at
47
+ user_params.save()
45
48
  end
46
49
 
47
50
 
@@ -50,10 +53,10 @@ class GdriveStrg < CloudStrg::CloudStorage
50
53
 
51
54
  session[:gdrive_access_token] = @client.authorization.access_token
52
55
  # user.gdrive_access_token = @client.authorization.access_token
53
- user.gdrive_refresh_token = @client.authorization.refresh_token
54
- user.gdrive_expires_in = @client.authorization.expires_in
55
- user.gdrive_issued_at = @client.authorization.issued_at
56
- user.save()
56
+ user_params.refresh_token = @client.authorization.refresh_token
57
+ user_params.expires_in = @client.authorization.expires_in
58
+ user_params.issued_at = @client.authorization.issued_at
59
+ user_params.save()
57
60
  elsif params[:error] # User denied the oauth grant
58
61
  puts "Denied: #{params[:error]}"
59
62
  end
@@ -68,7 +71,6 @@ class GdriveStrg < CloudStrg::CloudStorage
68
71
 
69
72
  def create_file params
70
73
  filename = params[:filename]
71
- filename += ".json" if not filename.include? ".json"
72
74
 
73
75
  file = @drive_api.files.insert.request_schema.new({'title' => filename, 'description' => 'Netlab scenario', 'mimeType' => 'text/json'})
74
76
  media=Google::APIClient::UploadIO.new(StringIO.new(params[:file_content]), 'text/json')
@@ -76,11 +78,12 @@ class GdriveStrg < CloudStrg::CloudStorage
76
78
  if r.status != 200
77
79
  return false
78
80
  end
79
- true
81
+ return save_remoteobject(@user, filename, params[:file_content], r.data.id)
82
+
80
83
  end
81
84
 
82
- def create_folder params
83
- end
85
+ #def create_folder params
86
+ #end
84
87
 
85
88
  def get_file params
86
89
  r = @client.execute!(:api_method => @drive_api.files.get, :parameters => {'fileId' => params[:fileid]})
@@ -98,7 +101,6 @@ class GdriveStrg < CloudStrg::CloudStorage
98
101
 
99
102
  def update_file params
100
103
  filename = params[:filename]
101
- filename += ".json" if not filename.include? ".json"
102
104
 
103
105
  file = @drive_api.files.insert.request_schema.new({'title' => filename, 'description' => 'Netlab scenario', 'mimeType' => 'text/json'})
104
106
  media=Google::APIClient::UploadIO.new(StringIO.new(params[:file_content]), 'text/json')
@@ -106,7 +108,8 @@ class GdriveStrg < CloudStrg::CloudStorage
106
108
  if r.status != 200
107
109
  return false
108
110
  end
109
- true
111
+ return save_remoteobject(@user, filename, params[:file_content], params[:file_id])
112
+
110
113
  end
111
114
 
112
115
  def remove_file params
@@ -121,7 +124,7 @@ class GdriveStrg < CloudStrg::CloudStorage
121
124
 
122
125
  lines = []
123
126
  r.data.items.each do |line|
124
- lines.append([line.title, line.id]) if line.title.include? ".json"
127
+ lines.append([line.title, line.id])
125
128
  end
126
129
  return lines
127
130
  end
@@ -1,6 +1,6 @@
1
1
  require 'cloudstrg/cloudstrg'
2
2
 
3
- class GdriveStorage < CloudStrg::CloudStorage
3
+ class GdriveStrg < CloudStrg::CloudStorage
4
4
  require 'google/api_client'
5
5
 
6
6
  CLIENT_ID = "867108581948.apps.googleusercontent.com"
@@ -25,23 +25,26 @@ class GdriveStorage < CloudStrg::CloudStorage
25
25
  def config params
26
26
  @client.authorization.redirect_uri = params[:redirect]
27
27
 
28
- @username = params[:username]
29
- user = Cloudstrguser.find_by_name(@username)
28
+ @user = params[:user]
29
+ user_params = @user.gdrivestrgparams
30
+ if not user_params
31
+ user_params = @user.gdrivestrgparams.build
32
+ end
30
33
 
31
34
  session = params[:session]
32
35
 
33
- @client.authorization.update_token!(:access_token => session[:gdrive_access_token] , #:access_token => user.gdrive_access_token,
34
- :refresh_token => user.gdrive_refresh_token,
35
- :expires_in => user.gdrive_expires_in,
36
- :issued_at => user.gdrive_issued_at)
36
+ @client.authorization.update_token!(:access_token => session[:gdrive_access_token] , #:access_token => user_params.access_token,
37
+ :refresh_token => user_params.refresh_token,
38
+ :expires_in => user_params.expires_in,
39
+ :issued_at => user_params.issued_at)
37
40
  if @client.authorization.refresh_token && @client.authorization.expired?
38
41
  @client.authorization.fetch_access_token!
39
42
  session[:gdrive_access_token] = @client.authorization.access_token
40
43
  # user.gdrive_access_token = @client.authorization.access_token
41
- user.gdrive_refresh_token = @client.authorization.refresh_token
42
- user.gdrive_expires_in = @client.authorization.expires_in
43
- user.gdrive_issued_at = @client.authorization.issued_at
44
- user.save()
44
+ user_params.refresh_token = @client.authorization.refresh_token
45
+ user_params.expires_in = @client.authorization.expires_in
46
+ user_params.issued_at = @client.authorization.issued_at
47
+ user_params.save()
45
48
  end
46
49
 
47
50
 
@@ -50,10 +53,10 @@ class GdriveStorage < CloudStrg::CloudStorage
50
53
 
51
54
  session[:gdrive_access_token] = @client.authorization.access_token
52
55
  # user.gdrive_access_token = @client.authorization.access_token
53
- user.gdrive_refresh_token = @client.authorization.refresh_token
54
- user.gdrive_expires_in = @client.authorization.expires_in
55
- user.gdrive_issued_at = @client.authorization.issued_at
56
- user.save()
56
+ user_params.refresh_token = @client.authorization.refresh_token
57
+ user_params.expires_in = @client.authorization.expires_in
58
+ user_params.issued_at = @client.authorization.issued_at
59
+ user_params.save()
57
60
  elsif params[:error] # User denied the oauth grant
58
61
  puts "Denied: #{params[:error]}"
59
62
  end
@@ -68,7 +71,6 @@ class GdriveStorage < CloudStrg::CloudStorage
68
71
 
69
72
  def create_file params
70
73
  filename = params[:filename]
71
- filename += ".json" if not filename.include? ".json"
72
74
 
73
75
  file = @drive_api.files.insert.request_schema.new({'title' => filename, 'description' => 'Netlab scenario', 'mimeType' => 'text/json'})
74
76
  media=Google::APIClient::UploadIO.new(StringIO.new(params[:file_content]), 'text/json')
@@ -76,11 +78,12 @@ class GdriveStorage < CloudStrg::CloudStorage
76
78
  if r.status != 200
77
79
  return false
78
80
  end
79
- true
81
+ return save_remoteobject(@user, filename, params[:file_content], r.data.id)
82
+
80
83
  end
81
84
 
82
- def create_folder params
83
- end
85
+ #def create_folder params
86
+ #end
84
87
 
85
88
  def get_file params
86
89
  r = @client.execute!(:api_method => @drive_api.files.get, :parameters => {'fileId' => params[:fileid]})
@@ -98,7 +101,6 @@ class GdriveStorage < CloudStrg::CloudStorage
98
101
 
99
102
  def update_file params
100
103
  filename = params[:filename]
101
- filename += ".json" if not filename.include? ".json"
102
104
 
103
105
  file = @drive_api.files.insert.request_schema.new({'title' => filename, 'description' => 'Netlab scenario', 'mimeType' => 'text/json'})
104
106
  media=Google::APIClient::UploadIO.new(StringIO.new(params[:file_content]), 'text/json')
@@ -106,7 +108,8 @@ class GdriveStorage < CloudStrg::CloudStorage
106
108
  if r.status != 200
107
109
  return false
108
110
  end
109
- true
111
+ return save_remoteobject(@user, filename, params[:file_content], params[:file_id])
112
+
110
113
  end
111
114
 
112
115
  def remove_file params
@@ -121,7 +124,7 @@ class GdriveStorage < CloudStrg::CloudStorage
121
124
 
122
125
  lines = []
123
126
  r.data.items.each do |line|
124
- lines.append([line.title, line.id]) if line.title.include? ".json"
127
+ lines.append([line.title, line.id])
125
128
  end
126
129
  return lines
127
130
  end
@@ -1,3 +1,3 @@
1
1
  module Gdrivestrg
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/gdrivestrg.rb CHANGED
@@ -1,2 +1,5 @@
1
+ require "gdrivestrg/engine"
2
+
1
3
  module Gdrivestrg
4
+ mattr_accessor :user_class
2
5
  end
@@ -0,0 +1,4 @@
1
+ require "gdrivestrg/engine"
2
+
3
+ module Gdrivestrg
4
+ end
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- Dummy::Application.config.secret_token = '5a059206fe025e69690a26767dbaf238ef0241c858ad60c41343abfe96d7c3c1848adee7a5f0087e283831edd03486208c5ebd6eddeafb5ea2b7125420ef5e2b'
7
+ Dummy::Application.config.secret_token = '73d8e44752ea24886d813d64ace8177575cc20b31acde6bee82530d049375092ad382809cd8a43042533753d258be2e13e59b529b3a910e24d914598ca3b86bd'
@@ -1,58 +1,4 @@
1
- Dummy::Application.routes.draw do
2
- # The priority is based upon order of creation:
3
- # first created -> highest priority.
1
+ Rails.application.routes.draw do
4
2
 
5
- # Sample of regular route:
6
- # match 'products/:id' => 'catalog#view'
7
- # Keep in mind you can assign values other than :controller and :action
8
-
9
- # Sample of named route:
10
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
- # This route can be invoked with purchase_url(:id => product.id)
12
-
13
- # Sample resource route (maps HTTP verbs to controller actions automatically):
14
- # resources :products
15
-
16
- # Sample resource route with options:
17
- # resources :products do
18
- # member do
19
- # get 'short'
20
- # post 'toggle'
21
- # end
22
- #
23
- # collection do
24
- # get 'sold'
25
- # end
26
- # end
27
-
28
- # Sample resource route with sub-resources:
29
- # resources :products do
30
- # resources :comments, :sales
31
- # resource :seller
32
- # end
33
-
34
- # Sample resource route with more complex sub-resources
35
- # resources :products do
36
- # resources :comments
37
- # resources :sales do
38
- # get 'recent', :on => :collection
39
- # end
40
- # end
41
-
42
- # Sample resource route within a namespace:
43
- # namespace :admin do
44
- # # Directs /admin/products/* to Admin::ProductsController
45
- # # (app/controllers/admin/products_controller.rb)
46
- # resources :products
47
- # end
48
-
49
- # You can have the root of your site routed with "root"
50
- # just remember to delete public/index.html.
51
- # root :to => 'welcome#index'
52
-
53
- # See how all your routes lay out with "rake routes"
54
-
55
- # This is a legacy wild controller route that's not recommended for RESTful applications.
56
- # Note: This route will make all actions in every controller accessible via GET requests.
57
- # match ':controller(/:action(/:id))(.:format)'
3
+ mount Gdrivestrg::Engine => "/gdrivestrg"
58
4
  end
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ refresh_token: MyString
5
+ expires_in: 1
6
+ issued_at: 2012-11-07
7
+
8
+ two:
9
+ refresh_token: MyString
10
+ expires_in: 1
11
+ issued_at: 2012-11-07
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ module Gdrivestrg
4
+ class ParamsControllerTest < ActionController::TestCase
5
+ setup do
6
+ @param = params(:one)
7
+ end
8
+
9
+ test "should get index" do
10
+ get :index
11
+ assert_response :success
12
+ assert_not_nil assigns(:params)
13
+ end
14
+
15
+ test "should get new" do
16
+ get :new
17
+ assert_response :success
18
+ end
19
+
20
+ test "should create param" do
21
+ assert_difference('Param.count') do
22
+ post :create, param: { expires_in: @param.expires_in, issued_at: @param.issued_at, refresh_token: @param.refresh_token }
23
+ end
24
+
25
+ assert_redirected_to param_path(assigns(:param))
26
+ end
27
+
28
+ test "should show param" do
29
+ get :show, id: @param
30
+ assert_response :success
31
+ end
32
+
33
+ test "should get edit" do
34
+ get :edit, id: @param
35
+ assert_response :success
36
+ end
37
+
38
+ test "should update param" do
39
+ put :update, id: @param, param: { expires_in: @param.expires_in, issued_at: @param.issued_at, refresh_token: @param.refresh_token }
40
+ assert_redirected_to param_path(assigns(:param))
41
+ end
42
+
43
+ test "should destroy param" do
44
+ assert_difference('Param.count', -1) do
45
+ delete :destroy, id: @param
46
+ end
47
+
48
+ assert_redirected_to params_path
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module Gdrivestrg
4
+ class ParamTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ module Gdrivestrg
4
+ class ParamsHelperTest < ActionView::TestCase
5
+ end
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gdrivestrg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-05 00:00:00.000000000 Z
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.0.3
37
+ version: 0.0.6
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,23 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.0.3
45
+ version: 0.0.6
46
+ - !ruby/object:Gem::Dependency
47
+ name: google-api-client
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.4.4
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.4
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: sqlite3
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -66,21 +82,46 @@ executables: []
66
82
  extensions: []
67
83
  extra_rdoc_files: []
68
84
  files:
85
+ - app/helpers/gdrivestrg/params_helper.rb
86
+ - app/helpers/gdrivestrg/application_helper.rb
87
+ - app/models/gdrivestrg/param.rb~
88
+ - app/models/gdrivestrg/param.rb
89
+ - app/assets/stylesheets/scaffold.css
90
+ - app/assets/stylesheets/gdrivestrg/params.css
91
+ - app/assets/stylesheets/gdrivestrg/application.css
92
+ - app/assets/javascripts/gdrivestrg/params.js
93
+ - app/assets/javascripts/gdrivestrg/application.js
94
+ - app/views/gdrivestrg/params/new.html.erb
95
+ - app/views/gdrivestrg/params/show.html.erb
96
+ - app/views/gdrivestrg/params/edit.html.erb
97
+ - app/views/gdrivestrg/params/_form.html.erb
98
+ - app/views/gdrivestrg/params/index.html.erb
99
+ - app/views/layouts/gdrivestrg/application.html.erb
100
+ - app/controllers/gdrivestrg/application_controller.rb
101
+ - app/controllers/gdrivestrg/params_controller.rb
102
+ - config/routes.rb
103
+ - db/migrate/20121107140721_create_gdrivestrg_params.rb~
104
+ - db/migrate/20121107140721_create_gdrivestrg_params.rb
105
+ - db/migrate/20121108121038_add_user_id_to_gdrivestrg_params.rb
106
+ - db/migrate/20121108121038_add_user_id_to_gdrivestrg_params.rb~
69
107
  - lib/tasks/gdrivestrg_tasks.rake
70
- - lib/generators/gdrivestrg_generator.rb
71
- - lib/generators/dropboxstrg_generator.rb~
72
- - lib/generators/gdrivestrg_generator.rb~
73
- - lib/generators/cloudstrg_generator.rb~
108
+ - lib/gdrivestrg.rb~
74
109
  - lib/gdrivestrg/version.rb
110
+ - lib/gdrivestrg/engine.rb
75
111
  - lib/gdrivestrg/gdrivestrg.rb~
76
112
  - lib/gdrivestrg/gdrivestrg.rb
113
+ - lib/gdrivestrg/engine.rb~
77
114
  - lib/gdrivestrg.rb
78
- - lib/templates/create_gdrivestrgfields.rb
79
115
  - MIT-LICENSE
80
116
  - Rakefile
81
117
  - README.rdoc
118
+ - test/functional/gdrivestrg/params_controller_test.rb
82
119
  - test/gdrivestrg_test.rb
120
+ - test/unit/helpers/gdrivestrg/params_helper_test.rb
121
+ - test/unit/gdrivestrg/param_test.rb
83
122
  - test/test_helper.rb
123
+ - test/integration/navigation_test.rb
124
+ - test/fixtures/gdrivestrg/params.yml
84
125
  - test/dummy/script/rails
85
126
  - test/dummy/config.ru
86
127
  - test/dummy/app/helpers/application_helper.rb
@@ -134,8 +175,13 @@ signing_key:
134
175
  specification_version: 3
135
176
  summary: Ruby plugin that installs a Google Drive driver
136
177
  test_files:
178
+ - test/functional/gdrivestrg/params_controller_test.rb
137
179
  - test/gdrivestrg_test.rb
180
+ - test/unit/helpers/gdrivestrg/params_helper_test.rb
181
+ - test/unit/gdrivestrg/param_test.rb
138
182
  - test/test_helper.rb
183
+ - test/integration/navigation_test.rb
184
+ - test/fixtures/gdrivestrg/params.yml
139
185
  - test/dummy/script/rails
140
186
  - test/dummy/config.ru
141
187
  - test/dummy/app/helpers/application_helper.rb
@@ -1,19 +0,0 @@
1
- require 'rails/generators'
2
- require 'rails/generators/migration'
3
-
4
- class CloudstrgGenerator < Rails::Generators::Base
5
- include Rails::Generators::Migration
6
- source_root File.expand_path('../../templates', __FILE__)
7
-
8
- def self.next_migration_number(path)
9
- Time.now.utc.strftime("%Y%m%d%H%M%S%6N")
10
- end
11
-
12
- def create_model_file
13
- template "cloudstrglist.rb", "app/models/cloudstrglist.rb"
14
- template "cloudstrguser.rb", "app/models/cloudstrguser.rb"
15
- migration_template "create_cloudstrglists.rb", "db/migrate/create_cloudstrglists.rb"
16
- migration_template "create_cloudstrgusers.rb", "db/migrate/create_cloudstrguser.rb"
17
- end
18
- end
19
-
@@ -1,19 +0,0 @@
1
- require 'rails/generators'
2
- require 'rails/generators/migration'
3
-
4
- class CloudstrgGenerator < Rails::Generators::Base
5
- include Rails::Generators::Migration
6
- source_root File.expand_path('../../templates', __FILE__)
7
-
8
- def self.next_migration_number(path)
9
- Time.now.utc.strftime("%Y%m%d%H%M%S%6N")
10
- end
11
-
12
- def create_model_file
13
- template "cloudstrglist.rb", "app/models/cloudstrglist.rb"
14
- template "cloudstrguser.rb", "app/models/cloudstrguser.rb"
15
- migration_template "create_cloudstrglists.rb", "db/migrate/create_cloudstrglists.rb"
16
- migration_template "create_cloudstrgusers.rb", "db/migrate/create_cloudstrgusers.rb"
17
- end
18
- end
19
-
@@ -1,16 +0,0 @@
1
- require 'rails/generators'
2
- require 'rails/generators/migration'
3
-
4
- class GdrivestrgGenerator < Rails::Generators::Base
5
- include Rails::Generators::Migration
6
- source_root File.expand_path('../../templates', __FILE__)
7
-
8
- def self.next_migration_number(path)
9
- Time.now.utc.strftime("%Y%m%d%H%M%S%6N")
10
- end
11
-
12
- def create_model_file
13
- migration_template "create_gdrivestrgfields.rb", "db/migrate/create_gdrivestrgfields.rb"
14
- end
15
- end
16
-
@@ -1,16 +0,0 @@
1
- require 'rails/generators'
2
- require 'rails/generators/migration'
3
-
4
- class CloudstrgGenerator < Rails::Generators::Base
5
- include Rails::Generators::Migration
6
- source_root File.expand_path('../../templates', __FILE__)
7
-
8
- def self.next_migration_number(path)
9
- Time.now.utc.strftime("%Y%m%d%H%M%S%6N")
10
- end
11
-
12
- def create_model_file
13
- migration_template "create_dropboxstrgfields.rb", "db/migrate/create_dropboxstrgfields.rb"
14
- end
15
- end
16
-
@@ -1,17 +0,0 @@
1
- class CreateGdrivestrgfields < ActiveRecord::Migration
2
- def up
3
- add_column :cloudstrgusers, :gdrive_refresh_token, :string
4
- add_column :cloudstrgusers, :gdrive_expires_in, :integer
5
- add_column :cloudstrgusers, :gdrive_issued_at, :date
6
-
7
- Cloudstrglist.create :plugin_name => "gdrive"
8
- end
9
-
10
- def down
11
- remove_column :cloudstrgusers, :gdrive_refresh_token
12
- remove_column :cloudstrgusers, :gdrive_expires_in
13
- remove_column :cloudstrgusers, :gdrive_issued_at
14
-
15
- Cloudstrglist.delete_all :plugin_name => "gdrive"
16
- end
17
- end