dropbox-api-petems 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+
3
+ describe Dropbox::API::Dir do
4
+
5
+ before do
6
+ @client = Dropbox::Spec.instance
7
+ @dirname = "#{Dropbox::Spec.test_dir}/spec-dir-test-#{Time.now.to_i}"
8
+ @dir = @client.mkdir @dirname
9
+ end
10
+
11
+ after do
12
+ # @dir.delete
13
+ end
14
+
15
+ describe "#copy" do
16
+
17
+ it "copies the dir properly" do
18
+ new_dirname = @dirname + "-copied"
19
+ @dir.copy new_dirname
20
+ @dir.path.should == new_dirname
21
+ end
22
+
23
+ end
24
+
25
+ describe "#move" do
26
+
27
+ it "moves the dir properly" do
28
+ new_dirname = @dirname + "-copied"
29
+ @dir.move new_dirname
30
+ @dir.path.should == new_dirname
31
+ end
32
+
33
+ end
34
+
35
+ describe "#destroy" do
36
+
37
+ it "destroys the dir properly" do
38
+ @dir.destroy
39
+ @dir.is_deleted.should == true
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,126 @@
1
+ require "spec_helper"
2
+
3
+ describe Dropbox::API::File do
4
+
5
+ before do
6
+ @client = Dropbox::Spec.instance
7
+ @filename = "#{Dropbox::Spec.test_dir}/spec-test-#{Time.now.to_i}.txt"
8
+ @file = @client.upload @filename, "spec file"
9
+ end
10
+
11
+ after do
12
+ # @file.delete
13
+ end
14
+
15
+ describe "#copy" do
16
+
17
+ it "copies the file properly" do
18
+ new_filename = @filename + ".copied"
19
+ @file.copy new_filename
20
+ @file.path.should == new_filename
21
+ end
22
+
23
+ end
24
+
25
+ describe "#move" do
26
+
27
+ it "moves the file properly" do
28
+ new_filename = @filename + ".copied"
29
+ @file.move new_filename
30
+ @file.path.should == new_filename
31
+ end
32
+
33
+ end
34
+
35
+ describe "#destroy" do
36
+
37
+ it "destroys the file properly" do
38
+ @file.destroy
39
+ @file.is_deleted.should == true
40
+ end
41
+
42
+ end
43
+
44
+ describe "#revisions" do
45
+
46
+ it "retrieves all revisions as an Array of File objects" do
47
+ @client.upload @file.path, "Updated content"
48
+
49
+ revisions = @file.revisions
50
+ revisions.size.should == 2
51
+ revisions.collect { |f| f.class }.should == [Dropbox::API::File, Dropbox::API::File]
52
+ end
53
+
54
+ end
55
+
56
+ describe "#restore" do
57
+
58
+ it "restores the file to a specific revision" do
59
+ old_rev = @file.rev
60
+
61
+ @client.upload @file.path, "Updated content"
62
+
63
+ file = @filename.split('/').last
64
+
65
+ found = @client.find(@file.path)
66
+
67
+ found.rev.should_not == old_rev
68
+
69
+ newer_rev = found.rev
70
+
71
+ @file.restore(old_rev)
72
+
73
+ found = @client.find(@file.path)
74
+
75
+ found.rev.should_not == old_rev
76
+ found.rev.should_not == newer_rev
77
+
78
+ end
79
+
80
+ end
81
+
82
+ describe "#share_url" do
83
+
84
+ it "returns an Url object" do
85
+
86
+ result = @file.share_url
87
+ result.should be_an_instance_of(Dropbox::API::Object)
88
+ result.keys.sort.should == ['expires', 'url']
89
+
90
+ end
91
+
92
+ end
93
+
94
+ describe "#copy_ref" do
95
+
96
+ it "returns a copy_ref object" do
97
+
98
+ result = @file.copy_ref
99
+ result.should be_an_instance_of(Dropbox::API::Object)
100
+ result.keys.sort.should == ['copy_ref', 'expires']
101
+
102
+ end
103
+
104
+ end
105
+
106
+ describe "#direct_url" do
107
+
108
+ it "returns an Url object" do
109
+
110
+ result = @file.direct_url
111
+ result.should be_an_instance_of(Dropbox::API::Object)
112
+ result.keys.sort.should == ['expires', 'url']
113
+
114
+ end
115
+
116
+ end
117
+
118
+ describe "#download" do
119
+
120
+ it "should download the file" do
121
+ @file.download.should == 'spec file'
122
+ end
123
+
124
+ end
125
+
126
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ describe Dropbox::API::OAuth do
4
+
5
+ describe ".consumer" do
6
+
7
+ it "raises an error if config options are not provided" do
8
+ Dropbox::API::Config.stub(:app_key).and_return(nil)
9
+ lambda {
10
+ Dropbox::API::OAuth.consumer :main
11
+ }.should raise_error(Dropbox::API::Error::Config)
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+ require "fileutils"
3
+
4
+ describe Dropbox::API::File do
5
+
6
+ before do
7
+ @io = StringIO.new
8
+ @client = Dropbox::Spec.instance
9
+ @filename = "#{Dropbox::Spec.test_dir}/spec-test-#{Time.now.to_i}.jpg"
10
+ jpeg = File.read("spec/fixtures/dropbox.jpg")
11
+ @file = @client.upload @filename, jpeg
12
+ end
13
+
14
+ describe "#thumbnail" do
15
+
16
+ it "downloads a thumbnail" do
17
+ result = @file.thumbnail
18
+
19
+ @io << result
20
+ @io.rewind
21
+
22
+ jpeg = JPEG.new(@io)
23
+ jpeg.height.should == 64
24
+ jpeg.width.should == 64
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,27 @@
1
+ $:.push File.expand_path("../../lib", __FILE__)
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter 'spec'
6
+ end
7
+ require 'dropbox-api'
8
+ require 'rspec'
9
+
10
+ # If you wand to change the json, you can do it here
11
+ # I still believe yajl is the best :) - marcinbunsch
12
+ MultiJson.engine= :yajl
13
+
14
+ module Dropbox
15
+ Spec = Hashie::Mash.new
16
+ end
17
+
18
+ Dir.glob("#{File.dirname(__FILE__)}/support/*.rb").each { |f| require f }
19
+
20
+ # Clean up after specs, remove test-directory
21
+ RSpec.configure do |config|
22
+ config.after(:all) do
23
+ test_dir = Dropbox::Spec.instance.find(Dropbox::Spec.test_dir) rescue nil
24
+ test_dir.destroy if test_dir and !test_dir.is_deleted?
25
+ end
26
+ end
27
+
@@ -0,0 +1,15 @@
1
+ require "yaml"
2
+
3
+ config = YAML.load_file "spec/connection.yml"
4
+
5
+ Dropbox::API::Config.app_key = config['app_key']
6
+ Dropbox::API::Config.app_secret = config['app_secret']
7
+ Dropbox::API::Config.mode = config['mode']
8
+
9
+ Dropbox::Spec.token = config['token']
10
+ Dropbox::Spec.secret = config['secret']
11
+
12
+ Dropbox::Spec.namespace = Time.now.to_i
13
+ Dropbox::Spec.instance = Dropbox::API::Client.new(:token => Dropbox::Spec.token,
14
+ :secret => Dropbox::Spec.secret)
15
+ Dropbox::Spec.test_dir = "test-#{Time.now.to_i}"
@@ -0,0 +1,39 @@
1
+ class JPEG
2
+ attr_reader :width, :height, :bits
3
+
4
+ def initialize(file)
5
+ examine(file)
6
+ end
7
+
8
+ private
9
+ def examine(io)
10
+ raise 'malformed JPEG' unless io.getbyte == 0xFF && io.getbyte == 0xD8 # SOI
11
+
12
+ class << io
13
+ def readint; (getbyte << 8) + getbyte; end
14
+ def readframe; read(readint - 2); end
15
+ def readsof; [readint, getbyte, readint, readint, getbyte]; end
16
+ def next
17
+ c = getbyte while c != 0xFF
18
+ c = getbyte while c == 0xFF
19
+ c
20
+ end
21
+ end
22
+
23
+ while marker = io.next
24
+ case marker
25
+ when 0xC0..0xC3, 0xC5..0xC7, 0xC9..0xCB, 0xCD..0xCF # SOF markers
26
+ length, @bits, @height, @width, components = io.readsof
27
+ raise 'malformed JPEG' unless length == 8 + components * 3
28
+ when 0xD9, 0xDA
29
+ break # EOI, SOS
30
+ when 0xFE
31
+ @comment = io.readframe # COM
32
+ when 0xE1
33
+ io.readframe # APP1, contains EXIF tag
34
+ else
35
+ io.readframe # ignore frame
36
+ end
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dropbox-api-petems
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Peter Souter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: oauth
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: hashie
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'
62
+ description: To deliver a more Rubyesque experience when using the DropBox API.
63
+ email:
64
+ - p.morsou@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .ruby-version
72
+ - Gemfile
73
+ - LICENSE
74
+ - README.markdown
75
+ - Rakefile
76
+ - dropbox-api.gemspec
77
+ - lib/dropbox-api.rb
78
+ - lib/dropbox-api/client.rb
79
+ - lib/dropbox-api/client/files.rb
80
+ - lib/dropbox-api/client/raw.rb
81
+ - lib/dropbox-api/connection.rb
82
+ - lib/dropbox-api/connection/requests.rb
83
+ - lib/dropbox-api/objects/delta.rb
84
+ - lib/dropbox-api/objects/dir.rb
85
+ - lib/dropbox-api/objects/file.rb
86
+ - lib/dropbox-api/objects/fileops.rb
87
+ - lib/dropbox-api/objects/object.rb
88
+ - lib/dropbox-api/tasks.rb
89
+ - lib/dropbox-api/util/config.rb
90
+ - lib/dropbox-api/util/error.rb
91
+ - lib/dropbox-api/util/oauth.rb
92
+ - lib/dropbox-api/util/util.rb
93
+ - lib/dropbox-api/version.rb
94
+ - spec/connection.sample.yml
95
+ - spec/fixtures/dropbox.jpg
96
+ - spec/lib/dropbox-api/client_spec.rb
97
+ - spec/lib/dropbox-api/connection_spec.rb
98
+ - spec/lib/dropbox-api/dir_spec.rb
99
+ - spec/lib/dropbox-api/file_spec.rb
100
+ - spec/lib/dropbox-api/oauth_spec.rb
101
+ - spec/lib/dropbox-api/thumbnail_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/support/config.rb
104
+ - spec/support/jpeg.rb
105
+ homepage: http://github.com/petems/dropbox-api-petems
106
+ licenses: []
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project: dropbox-api
125
+ rubygems_version: 1.8.23
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: A Ruby client for the DropBox REST API (Originally by marcinbunsch, forked
129
+ by petems)
130
+ test_files:
131
+ - spec/connection.sample.yml
132
+ - spec/fixtures/dropbox.jpg
133
+ - spec/lib/dropbox-api/client_spec.rb
134
+ - spec/lib/dropbox-api/connection_spec.rb
135
+ - spec/lib/dropbox-api/dir_spec.rb
136
+ - spec/lib/dropbox-api/file_spec.rb
137
+ - spec/lib/dropbox-api/oauth_spec.rb
138
+ - spec/lib/dropbox-api/thumbnail_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/support/config.rb
141
+ - spec/support/jpeg.rb