dropboxstrg 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/Rakefile +2 -0
  2. data/app/assets/javascripts/dropboxstrg/application.js +15 -0
  3. data/app/assets/javascripts/dropboxstrg/params.js +2 -0
  4. data/app/assets/stylesheets/dropboxstrg/application.css +13 -0
  5. data/app/assets/stylesheets/dropboxstrg/params.css +4 -0
  6. data/app/assets/stylesheets/scaffold.css +56 -0
  7. data/app/controllers/dropboxstrg/application_controller.rb +4 -0
  8. data/app/controllers/dropboxstrg/params_controller.rb +87 -0
  9. data/app/helpers/dropboxstrg/application_helper.rb +4 -0
  10. data/app/helpers/dropboxstrg/params_helper.rb +4 -0
  11. data/app/models/dropboxstrg/param.rb +8 -0
  12. data/app/models/dropboxstrg/param.rb~ +23 -0
  13. data/app/views/dropboxstrg/params/_form.html.erb +25 -0
  14. data/app/views/dropboxstrg/params/edit.html.erb +6 -0
  15. data/app/views/dropboxstrg/params/index.html.erb +25 -0
  16. data/app/views/dropboxstrg/params/new.html.erb +5 -0
  17. data/app/views/dropboxstrg/params/show.html.erb +15 -0
  18. data/app/views/layouts/dropboxstrg/application.html.erb +14 -0
  19. data/config/routes.rb +4 -0
  20. data/db/migrate/20121107102730_create_dropboxstrg_params.rb +27 -0
  21. data/db/migrate/20121107102730_create_dropboxstrg_params.rb~ +27 -0
  22. data/lib/dropboxstrg.rb +3 -0
  23. data/lib/dropboxstrg.rb~ +4 -0
  24. data/lib/dropboxstrg/dropboxstrg.rb +33 -29
  25. data/lib/dropboxstrg/dropboxstrg.rb~ +34 -30
  26. data/lib/dropboxstrg/engine.rb +7 -0
  27. data/lib/dropboxstrg/engine.rb~ +5 -0
  28. data/lib/dropboxstrg/version.rb +1 -1
  29. data/lib/dropboxstrg/version.rb~ +3 -0
  30. data/test/dummy/config/initializers/secret_token.rb +1 -1
  31. data/test/dummy/config/routes.rb +2 -56
  32. data/test/fixtures/dropboxstrg/params.yml +9 -0
  33. data/test/functional/dropboxstrg/params_controller_test.rb +51 -0
  34. data/test/integration/navigation_test.rb +10 -0
  35. data/test/unit/dropboxstrg/param_test.rb +9 -0
  36. data/test/unit/helpers/dropboxstrg/params_helper_test.rb +6 -0
  37. metadata +54 -18
  38. data/lib/dropboxstrg/dropboxstorage.rb~ +0 -118
  39. data/lib/generators/cloudstrg_generator.rb~ +0 -19
  40. data/lib/generators/dropboxstrg_generator.rb +0 -16
  41. data/lib/generators/dropboxstrg_generator.rb~ +0 -19
  42. data/lib/templates/cloudstrgdata.rb~ +0 -3
  43. data/lib/templates/cloudstrglist.rb~ +0 -3
  44. data/lib/templates/cloudstrguser.rb~ +0 -0
  45. data/lib/templates/create_cloudstrgdata.rb~ +0 -0
  46. data/lib/templates/create_cloudstrgfields.rb~ +0 -13
  47. data/lib/templates/create_cloudstrglist.rb~ +0 -13
  48. data/lib/templates/create_cloudstrgusers.rb~ +0 -0
  49. data/lib/templates/create_dropboxstrgfields.rb +0 -15
  50. data/lib/templates/create_dropboxstrgfields.rb~ +0 -11
  51. data/lib/templates/create_gdrivestrgfields.rb~ +0 -13
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 Dropboxstrg
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,87 @@
1
+ require_dependency "dropboxstrg/application_controller"
2
+
3
+ module Dropboxstrg
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 Dropboxstrg
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Dropboxstrg
2
+ module ParamsHelper
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ module Dropboxstrg
2
+ class Param < ActiveRecord::Base
3
+
4
+ attr_accessible :akey, :asecret
5
+
6
+ belongs_to :user, :class_name => Dropboxstrg.user_class
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ module Dropboxstrg
2
+ class Param < ActiveRecord::Base
3
+
4
+ attr_accessible :akey, :asecret
5
+
6
+ attr_accessor :user_email
7
+ belongs_to :user, :class_name => Dropboxstrg.user_class
8
+
9
+ before_save :set_user
10
+
11
+ private
12
+ def set_user
13
+ if self.user_id
14
+ self.user = Dropboxstrg.user_class.constantize.find(self.user_id)
15
+ else
16
+ self.user = Dropboxstrg.user_class.constantize.find_by_email(user_email)
17
+ end
18
+ if not self.user
19
+ return false
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
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 :akey %><br />
16
+ <%= f.text_field :akey %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :asecret %><br />
20
+ <%= f.text_field :asecret %>
21
+ </div>
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% 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,25 @@
1
+ <h1>Listing params</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Akey</th>
6
+ <th>Asecret</th>
7
+ <th></th>
8
+ <th></th>
9
+ <th></th>
10
+ </tr>
11
+
12
+ <% @params.each do |param| %>
13
+ <tr>
14
+ <td><%= param.akey %></td>
15
+ <td><%= param.asecret %></td>
16
+ <td><%= link_to 'Show', param %></td>
17
+ <td><%= link_to 'Edit', edit_param_path(param) %></td>
18
+ <td><%= link_to 'Destroy', param, method: :delete, data: { confirm: 'Are you sure?' } %></td>
19
+ </tr>
20
+ <% end %>
21
+ </table>
22
+
23
+ <br />
24
+
25
+ <%= 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,15 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Akey:</b>
5
+ <%= @param.akey %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Asecret:</b>
10
+ <%= @param.asecret %>
11
+ </p>
12
+
13
+
14
+ <%= link_to 'Edit', edit_param_path(@param) %> |
15
+ <%= link_to 'Back', params_path %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dropboxstrg</title>
5
+ <%= stylesheet_link_tag "dropboxstrg/application", :media => "all" %>
6
+ <%= javascript_include_tag "dropboxstrg/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
+ Dropboxstrg::Engine.routes.draw do
2
+ resources :params
3
+
4
+ end
@@ -0,0 +1,27 @@
1
+ require 'dropboxstrg/version'
2
+
3
+ class CreateDropboxstrgParams < ActiveRecord::Migration
4
+ def change
5
+ create_table :dropboxstrg_params do |t|
6
+ t.integer "#{Dropboxstrg.user_class.downcase}_id".to_sym
7
+ t.string :akey
8
+ t.string :asecret
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ plugin = Cloudstrg::Cloudstrgplugin.find_by_plugin_name("dropbox")
14
+ if not plugin
15
+ puts "Inserting Dropbox plugin"
16
+ Cloudstrg::Cloudstrgplugin.create :plugin_name => "dropbox", :version => Dropboxstrg::VERSION
17
+ else
18
+ if Dropboxstrg::VERSION > plugin.version
19
+ puts "Updating Dropbox plugin version: #{Dropboxstrg::VERSION}"
20
+ plugin.version = Dropboxstrg::VERSION
21
+ plugin.save
22
+ else
23
+ puts "Dropbox plugin is up to date"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'dropboxstrg/version'
2
+
3
+ class CreateDropboxstrgParams < ActiveRecord::Migration
4
+ def change
5
+ create_table :dropboxstrg_params do |t|
6
+ t.integer "#{Dropboxstrg.user_class}_id".to_sym
7
+ t.string :akey
8
+ t.string :asecret
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ plugin = Cloudstrg::Cloudstrgplugin.find_by_plugin_name("dropbox")
14
+ if not plugin
15
+ puts "Inserting Dropbox plugin"
16
+ Cloudstrg::Cloudstrgplugin.create :plugin_name => "dropbox", :version => Dropboxstrg::VERSION
17
+ else
18
+ if Dropboxstrg::VERSION > plugin.version
19
+ puts "Updating Dropbox plugin version: #{Dropboxstrg::VERSION}"
20
+ plugin.version = Dropboxstrg::VERSION
21
+ plugin.save
22
+ else
23
+ puts "Dropbox plugin is up to date"
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/dropboxstrg.rb CHANGED
@@ -1,2 +1,5 @@
1
+ require "dropboxstrg/engine"
2
+
1
3
  module Dropboxstrg
4
+ mattr_accessor :user_class
2
5
  end
@@ -0,0 +1,4 @@
1
+ require "dropboxstrg/engine"
2
+
3
+ module Dropboxstrg
4
+ end
@@ -10,7 +10,7 @@ class DropboxStrg < CloudStrg::CloudStorage
10
10
  mattr_accessor :session, :client, :user, :redirect_path
11
11
  @session = nil
12
12
  @client = nil
13
- @username = nil
13
+ @user = nil
14
14
  @redirect_path = nil
15
15
 
16
16
  def initialize params
@@ -19,8 +19,11 @@ class DropboxStrg < CloudStrg::CloudStorage
19
19
 
20
20
  def config params
21
21
  @redirect_path = params[:redirect]
22
- @username = params[:username]
23
- user = Cloudstrguser.find_by_name(@username)
22
+ @user = params[:user]
23
+ user_params = @user.dropboxstrgparams
24
+ if not user_params
25
+ user_params = @user.build_dropboxstrgparams
26
+ end
24
27
 
25
28
  session = params[:session]
26
29
 
@@ -28,26 +31,26 @@ class DropboxStrg < CloudStrg::CloudStorage
28
31
  begin
29
32
  @session.set_request_token(session[:dropbox_rkey], session[:dropbox_rsecret])
30
33
  @session.get_access_token()
31
- user.dropbox_akey = @session.access_token.key
32
- user.dropbox_asecret = @session.access_token.secret
34
+ user_params.akey = @session.access_token.key
35
+ user_params.asecret = @session.access_token.secret
33
36
  session[:dropbox_rkey] = nil
34
37
  session[:dropbox_rsecret] = nil
35
- user.save()
38
+ user_params.save()
36
39
  rescue DropboxAuthError
37
40
  @session = DropboxSession.new(APP_KEY, APP_SECRET)
38
- user.dropbox_akey = nil
39
- user.dropbox_asecret = nil
41
+ user_params.akey = nil
42
+ user_params.asecret = nil
40
43
  session[:dropbox_rkey] = nil
41
44
  session[:dropbox_rsecret] = nil
42
- user.save()
45
+ user_params.save()
43
46
  params[:session] = session
44
47
  return config params
45
48
  end
46
49
  else
47
50
  @session.get_request_token()
48
51
 
49
- if user.dropbox_akey and user.dropbox_asecret
50
- @session.set_access_token(user.dropbox_akey, user.dropbox_asecret)
52
+ if user_params.akey and user_params.asecret
53
+ @session.set_access_token(user_params.akey, user_params.asecret)
51
54
  else
52
55
  session[:dropbox_rkey] = @session.request_token.key
53
56
  session[:dropbox_rsecret] = @session.request_token.secret
@@ -63,25 +66,26 @@ class DropboxStrg < CloudStrg::CloudStorage
63
66
  return false
64
67
  end
65
68
  filename = params[:filename]
66
- filename += ".json" if not filename.include? ".json"
67
- @client.put_file("/#{@username}/#{filename}", params[:file_content])
68
- true
69
- end
70
69
 
71
- def create_folder params
72
- if not @client
73
- return false
74
- end
75
- @client.file_create_folder("/#{@username}")
70
+ @client.put_file("/#{filename}", params[:file_content])
71
+
72
+ file_id = save_remoteobject(@user, filename, params[:file_content], filename)
73
+ return file_id
76
74
  end
77
75
 
76
+ #def create_folder params
77
+ # if not @client
78
+ # return false
79
+ # end
80
+ # @client.file_create_folder("/#{@username}")
81
+ #end
82
+
78
83
  def get_file params
79
84
  if not @client
80
85
  return false
81
86
  end
82
87
  filename = params[:fileid]
83
- filename += ".json" if not filename.include? ".json"
84
- return filename, filename, @client.get_file("/#{@username}/#{filename}")
88
+ return filename, filename, @client.get_file("/#{filename}")
85
89
  end
86
90
 
87
91
  def update_file params
@@ -89,9 +93,10 @@ class DropboxStrg < CloudStrg::CloudStorage
89
93
  return false
90
94
  end
91
95
  filename = params[:fileid]
92
- filename += ".json" if not filename.include? ".json"
93
- @client.put_file("/#{@username}/#{filename}", params[:file_content], overwrite=true)
94
- true
96
+
97
+ @client.put_file("/#{filename}", params[:file_content], overwrite=true)
98
+
99
+ return save_remoteobject(@user, filename, params[:file_content], filename)
95
100
  end
96
101
 
97
102
  def remove_file params
@@ -99,18 +104,17 @@ class DropboxStrg < CloudStrg::CloudStorage
99
104
  return false
100
105
  end
101
106
  filename = params[:fileid]
102
- filename += ".json" if not filename.include? ".json"
103
- @client.file_delete("/#{@username}/#{filename}")
107
+ @client.file_delete("/#{filename}")
104
108
  end
105
109
 
106
110
  def list_files
107
111
  if not @client
108
112
  return false
109
113
  end
110
- data = @client.metadata("/#{@username}/")
114
+ data = @client.metadata("/")
111
115
  lines = []
112
116
  data["contents"].each do |line|
113
- lines.append([line["path"].split("/")[-1],line["path"].split("/")[-1]]) if line["path"].include? ".json"
117
+ lines.append([line["path"].split("/")[-1],line["path"].split("/")[-1]])
114
118
  end
115
119
  return lines
116
120
  end
@@ -1,6 +1,6 @@
1
1
  require 'cloudstrg/cloudstrg'
2
2
 
3
- class DropboxStorage < CloudStrg::CloudStorage
3
+ class DropboxStrg < CloudStrg::CloudStorage
4
4
  require 'dropbox_sdk'
5
5
 
6
6
  APP_KEY = 'ebwn2abt7mznz56'
@@ -10,7 +10,7 @@ class DropboxStorage < CloudStrg::CloudStorage
10
10
  mattr_accessor :session, :client, :user, :redirect_path
11
11
  @session = nil
12
12
  @client = nil
13
- @username = nil
13
+ @user = nil
14
14
  @redirect_path = nil
15
15
 
16
16
  def initialize params
@@ -19,8 +19,11 @@ class DropboxStorage < CloudStrg::CloudStorage
19
19
 
20
20
  def config params
21
21
  @redirect_path = params[:redirect]
22
- @username = params[:username]
23
- user = Cloudstrguser.find_by_name(@username)
22
+ @user = params[:user]
23
+ user_params = @user.dropboxstrgparams
24
+ if not user_params
25
+ user_params = @user.build_dropboxstrgparams
26
+ end
24
27
 
25
28
  session = params[:session]
26
29
 
@@ -28,26 +31,26 @@ class DropboxStorage < CloudStrg::CloudStorage
28
31
  begin
29
32
  @session.set_request_token(session[:dropbox_rkey], session[:dropbox_rsecret])
30
33
  @session.get_access_token()
31
- user.dropbox_akey = @session.access_token.key
32
- user.dropbox_asecret = @session.access_token.secret
34
+ user_params.akey = @session.access_token.key
35
+ user_params.asecret = @session.access_token.secret
33
36
  session[:dropbox_rkey] = nil
34
37
  session[:dropbox_rsecret] = nil
35
- user.save()
38
+ user_params.save()
36
39
  rescue DropboxAuthError
37
40
  @session = DropboxSession.new(APP_KEY, APP_SECRET)
38
- user.dropbox_akey = nil
39
- user.dropbox_asecret = nil
41
+ user_params.akey = nil
42
+ user_params.asecret = nil
40
43
  session[:dropbox_rkey] = nil
41
44
  session[:dropbox_rsecret] = nil
42
- user.save()
45
+ user_params.save()
43
46
  params[:session] = session
44
47
  return config params
45
48
  end
46
49
  else
47
50
  @session.get_request_token()
48
51
 
49
- if user.dropbox_akey and user.dropbox_asecret
50
- @session.set_access_token(user.dropbox_akey, user.dropbox_asecret)
52
+ if user_params.akey and user_params.asecret
53
+ @session.set_access_token(user_params.akey, user_params.asecret)
51
54
  else
52
55
  session[:dropbox_rkey] = @session.request_token.key
53
56
  session[:dropbox_rsecret] = @session.request_token.secret
@@ -63,25 +66,26 @@ class DropboxStorage < CloudStrg::CloudStorage
63
66
  return false
64
67
  end
65
68
  filename = params[:filename]
66
- filename += ".json" if not filename.include? ".json"
67
- @client.put_file("/#{@username}/#{filename}", params[:file_content])
68
- true
69
- end
70
69
 
71
- def create_folder params
72
- if not @client
73
- return false
74
- end
75
- @client.file_create_folder("/#{@username}")
70
+ @client.put_file("/#{filename}", params[:file_content])
71
+
72
+ file_id = save_remoteobject(@user, filename, params[:file_content], filename)
73
+ return file_id
76
74
  end
77
75
 
76
+ #def create_folder params
77
+ # if not @client
78
+ # return false
79
+ # end
80
+ # @client.file_create_folder("/#{@username}")
81
+ #end
82
+
78
83
  def get_file params
79
84
  if not @client
80
85
  return false
81
86
  end
82
87
  filename = params[:fileid]
83
- filename += ".json" if not filename.include? ".json"
84
- return filename, filename, @client.get_file("/#{@username}/#{filename}")
88
+ return filename, filename, @client.get_file("/#{filename}")
85
89
  end
86
90
 
87
91
  def update_file params
@@ -89,9 +93,10 @@ class DropboxStorage < CloudStrg::CloudStorage
89
93
  return false
90
94
  end
91
95
  filename = params[:fileid]
92
- filename += ".json" if not filename.include? ".json"
93
- @client.put_file("/#{@username}/#{filename}", params[:file_content], overwrite=true)
94
- true
96
+
97
+ @client.put_file("/#{filename}", params[:file_content], overwrite=true)
98
+
99
+ return save_remoteobject(@user, filename, params[:file_content], filename)
95
100
  end
96
101
 
97
102
  def remove_file params
@@ -99,18 +104,17 @@ class DropboxStorage < CloudStrg::CloudStorage
99
104
  return false
100
105
  end
101
106
  filename = params[:fileid]
102
- filename += ".json" if not filename.include? ".json"
103
- @client.file_delete("/#{@username}/#{filename}")
107
+ @client.file_delete("/#{filename}")
104
108
  end
105
109
 
106
110
  def list_files
107
111
  if not @client
108
112
  return false
109
113
  end
110
- data = @client.metadata("/#{@username}/")
114
+ data = @client.metadata("/")
111
115
  lines = []
112
116
  data["contents"].each do |line|
113
- lines.append([line["path"].split("/")[-1],line["path"].split("/")[-1]]) if line["path"].include? ".json"
117
+ lines.append([line["path"].split("/")[-1],line["path"].split("/")[-1]])
114
118
  end
115
119
  return lines
116
120
  end
@@ -0,0 +1,7 @@
1
+ require 'cloudstrg/engine'
2
+
3
+ module Dropboxstrg
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Dropboxstrg
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Dropboxstrg
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Dropboxstrg
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Dropboxstrg
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,3 @@
1
+ module Dropboxstrg
2
+ VERSION = "0.0.1"
3
+ 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 = 'b5637da4d9e2fb1b1ba52547664344a38cadff0bf04a559c594dc0b15cabe1e40d950b27d9e3a61892d51ee0337b482c3de97285b53dbbaa5d320fd382e1c6d5'
7
+ Dummy::Application.config.secret_token = '2eee1d3f0ea340b55014f702efa5c4ccd485d0c4e39cd957428a7ff007998fc850c0e5a7c1c2de6bf52a83d2b0fef611229a8b5bc4fc62a37e8553b2d426375e'
@@ -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 Dropboxstrg::Engine => "/dropboxstrg"
58
4
  end
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ akey: MyString
5
+ asecret: MyString
6
+
7
+ two:
8
+ akey: MyString
9
+ asecret: MyString
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ module Dropboxstrg
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: { akey: @param.akey, asecret: @param.asecret }
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: { akey: @param.akey, asecret: @param.asecret }
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 Dropboxstrg
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 Dropboxstrg
4
+ class ParamsHelperTest < ActionView::TestCase
5
+ end
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropboxstrg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
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: dropbox-sdk
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
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'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: sqlite3
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -66,30 +82,45 @@ executables: []
66
82
  extensions: []
67
83
  extra_rdoc_files: []
68
84
  files:
85
+ - app/helpers/dropboxstrg/params_helper.rb
86
+ - app/helpers/dropboxstrg/application_helper.rb
87
+ - app/models/dropboxstrg/param.rb~
88
+ - app/models/dropboxstrg/param.rb
89
+ - app/assets/stylesheets/scaffold.css
90
+ - app/assets/stylesheets/dropboxstrg/params.css
91
+ - app/assets/stylesheets/dropboxstrg/application.css
92
+ - app/assets/javascripts/dropboxstrg/params.js
93
+ - app/assets/javascripts/dropboxstrg/application.js
94
+ - app/views/layouts/dropboxstrg/application.html.erb
95
+ - app/views/dropboxstrg/params/new.html.erb
96
+ - app/views/dropboxstrg/params/show.html.erb
97
+ - app/views/dropboxstrg/params/edit.html.erb
98
+ - app/views/dropboxstrg/params/_form.html.erb
99
+ - app/views/dropboxstrg/params/index.html.erb
100
+ - app/controllers/dropboxstrg/application_controller.rb
101
+ - app/controllers/dropboxstrg/params_controller.rb
102
+ - config/routes.rb
103
+ - db/migrate/20121107102730_create_dropboxstrg_params.rb~
104
+ - db/migrate/20121107102730_create_dropboxstrg_params.rb
69
105
  - lib/dropboxstrg.rb
70
106
  - lib/tasks/dropboxstrg_tasks.rake
71
- - lib/generators/dropboxstrg_generator.rb~
72
- - lib/generators/dropboxstrg_generator.rb
73
- - lib/generators/cloudstrg_generator.rb~
74
- - lib/templates/create_cloudstrgdata.rb~
75
- - lib/templates/create_gdrivestrgfields.rb~
76
- - lib/templates/create_dropboxstrgfields.rb
77
- - lib/templates/cloudstrguser.rb~
78
- - lib/templates/create_cloudstrgusers.rb~
79
- - lib/templates/create_cloudstrgfields.rb~
80
- - lib/templates/cloudstrglist.rb~
81
- - lib/templates/cloudstrgdata.rb~
82
- - lib/templates/create_cloudstrglist.rb~
83
- - lib/templates/create_dropboxstrgfields.rb~
107
+ - lib/dropboxstrg.rb~
84
108
  - lib/dropboxstrg/version.rb
85
109
  - lib/dropboxstrg/dropboxstrg.rb
110
+ - lib/dropboxstrg/version.rb~
111
+ - lib/dropboxstrg/engine.rb
86
112
  - lib/dropboxstrg/dropboxstrg.rb~
87
- - lib/dropboxstrg/dropboxstorage.rb~
113
+ - lib/dropboxstrg/engine.rb~
88
114
  - MIT-LICENSE
89
115
  - Rakefile
90
116
  - README.rdoc
117
+ - test/functional/dropboxstrg/params_controller_test.rb
91
118
  - test/dropboxstrg_test.rb
119
+ - test/unit/helpers/dropboxstrg/params_helper_test.rb
120
+ - test/unit/dropboxstrg/param_test.rb
92
121
  - test/test_helper.rb
122
+ - test/integration/navigation_test.rb
123
+ - test/fixtures/dropboxstrg/params.yml
93
124
  - test/dummy/script/rails
94
125
  - test/dummy/config.ru
95
126
  - test/dummy/app/helpers/application_helper.rb
@@ -143,8 +174,13 @@ signing_key:
143
174
  specification_version: 3
144
175
  summary: Ruby plugin that installs the Dropbox driver
145
176
  test_files:
177
+ - test/functional/dropboxstrg/params_controller_test.rb
146
178
  - test/dropboxstrg_test.rb
179
+ - test/unit/helpers/dropboxstrg/params_helper_test.rb
180
+ - test/unit/dropboxstrg/param_test.rb
147
181
  - test/test_helper.rb
182
+ - test/integration/navigation_test.rb
183
+ - test/fixtures/dropboxstrg/params.yml
148
184
  - test/dummy/script/rails
149
185
  - test/dummy/config.ru
150
186
  - test/dummy/app/helpers/application_helper.rb
@@ -1,118 +0,0 @@
1
- require 'cloudstorage'
2
-
3
- class DropboxStorage < CloudStorage::CloudStorage
4
- require 'dropbox_sdk'
5
-
6
- APP_KEY = 'ebwn2abt7mznz56'
7
- APP_SECRET = 'g03si51tws05re3'
8
- ACCESS_TYPE = :app_folder
9
-
10
- mattr_accessor :session, :client, :user, :redirect_path
11
- @session = nil
12
- @client = nil
13
- @username = nil
14
- @redirect_path = nil
15
-
16
- def initialize params
17
- @session = DropboxSession.new(APP_KEY, APP_SECRET)
18
- end
19
-
20
- def config params
21
- @redirect_path = params[:redirect]
22
- @username = params[:username]
23
- user = Person.find_by_name(@username)
24
-
25
- session = params[:session]
26
-
27
- if session[:dropbox_rkey] and session[:dropbox_rsecret]
28
- begin
29
- @session.set_request_token(session[:dropbox_rkey], session[:dropbox_rsecret])
30
- @session.get_access_token()
31
- user.dropbox_akey = @session.access_token.key
32
- user.dropbox_asecret = @session.access_token.secret
33
- session[:dropbox_rkey] = nil
34
- session[:dropbox_rsecret] = nil
35
- user.save()
36
- rescue DropboxAuthError
37
- @session = DropboxSession.new(APP_KEY, APP_SECRET)
38
- user.dropbox_akey = nil
39
- user.dropbox_asecret = nil
40
- session[:dropbox_rkey] = nil
41
- session[:dropbox_rsecret] = nil
42
- user.save()
43
- params[:session] = session
44
- return config params
45
- end
46
- else
47
- @session.get_request_token()
48
-
49
- if user.dropbox_akey and user.dropbox_asecret
50
- @session.set_access_token(user.dropbox_akey, user.dropbox_asecret)
51
- else
52
- session[:dropbox_rkey] = @session.request_token.key
53
- session[:dropbox_rsecret] = @session.request_token.secret
54
- return session, @session.get_authorize_url(callback=@redirect_path)
55
- end
56
- end
57
- @client = DropboxClient.new(@session, ACCESS_TYPE)
58
- return session, false
59
- end
60
-
61
- def create_file params
62
- if not @client
63
- return false
64
- end
65
- filename = params[:filename]
66
- filename += ".json" if not filename.include? ".json"
67
- @client.put_file("/#{@username}/#{filename}", params[:file_content])
68
- true
69
- end
70
-
71
- def create_folder params
72
- if not @client
73
- return false
74
- end
75
- @client.file_create_folder("/#{@username}")
76
- end
77
-
78
- def get_file params
79
- if not @client
80
- return false
81
- end
82
- filename = params[:fileid]
83
- filename += ".json" if not filename.include? ".json"
84
- return filename, filename, @client.get_file("/#{@username}/#{filename}")
85
- end
86
-
87
- def update_file params
88
- if not @client
89
- return false
90
- end
91
- filename = params[:fileid]
92
- filename += ".json" if not filename.include? ".json"
93
- @client.put_file("/#{@username}/#{filename}", params[:file_content], overwrite=true)
94
- true
95
- end
96
-
97
- def remove_file params
98
- if not @client
99
- return false
100
- end
101
- filename = params[:fileid]
102
- filename += ".json" if not filename.include? ".json"
103
- @client.file_delete("/#{@username}/#{filename}")
104
- end
105
-
106
- def list_files
107
- if not @client
108
- return false
109
- end
110
- data = @client.metadata("/#{@username}/")
111
- lines = []
112
- data["contents"].each do |line|
113
- lines.append([line["path"].split("/")[-1],line["path"].split("/")[-1]]) if line["path"].include? ".json"
114
- end
115
- return lines
116
- end
117
-
118
- end
@@ -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,16 +0,0 @@
1
- require 'rails/generators'
2
- require 'rails/generators/migration'
3
-
4
- class DropboxstrgGenerator < 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,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,3 +0,0 @@
1
- class Person < ActiveRecord::Base
2
- attr_accessible :name
3
- end
@@ -1,3 +0,0 @@
1
- class CloudstrgList < ActiveRecord::Base
2
- attr_accessible :plugin_name
3
- end
File without changes
File without changes
@@ -1,13 +0,0 @@
1
- class CreateCloudstrglists < ActiveRecord::Migration
2
- def up
3
- create_table :cloudstrglists do |t|
4
- t.string :plugin_name
5
-
6
- t.timestamps
7
- end
8
- end
9
-
10
- def down
11
- drop_table :cloudstrglists
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- class CreateCloudstrglists < ActiveRecord::Migration
2
- def up
3
- create_table :cloudstrglists do |t|
4
- t.string :plugin_name
5
-
6
- t.timestamps
7
- end
8
- end
9
-
10
- def down
11
- drop_table :cloudstrglist
12
- end
13
- end
File without changes
@@ -1,15 +0,0 @@
1
- class CreateDropboxstrgfields < ActiveRecord::Migration
2
- def up
3
- add_column :cloudstrgusers, :dropbox_akey, :string
4
- add_column :cloudstrgusers, :dropbox_asecret, :string
5
-
6
- Cloudstrglist.create :plugin_name => "dropbox"
7
- end
8
-
9
- def down
10
- remove_column :cloudstrgusers, :dropbox_akey
11
- remove_column :cloudstrgusers, :dropbox_asecret
12
-
13
- Cloudstrglist.delete_all :plugin_name => "dropbox"
14
- end
15
- end
@@ -1,11 +0,0 @@
1
- class CreateDropboxstrgfields < ActiveRecord::Migration
2
- def up
3
- add_column :cloudstrgusers, :dropbox_akey, :string
4
- add_column :cloudstrgusers, :dropbox_asecret, :string
5
- end
6
-
7
- def down
8
- remove_column :cloudstrgusers, :dropbox_akey
9
- remove_column :cloudstrgusers, :dropbox_asecrets
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- class CreateCloudstrgfields < 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
- end
7
-
8
- def down
9
- remove_column :cloudstrgusers, :gdrive_refresh_token
10
- remove_column :cloudstrgusers, :gdrive_expires_in
11
- remove_column :cloudstrgusers, :gdrive_issued_at
12
- end
13
- end