divshare 0.3.0 → 0.3.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.
data/README CHANGED
@@ -1,14 +1,26 @@
1
- == Description
1
+ divshare
2
+ ========
2
3
 
3
- The divshare gem makes it easier to use the divshare API. To use it, you need
4
+ Description
5
+ -----------
6
+
7
+ The divshare gem makes it easier to use the Divshare API. To use it, you need
4
8
  to create a Divshare account and sign up for an API key.
5
9
 
6
- == Usage
10
+ Usage
11
+ -----
7
12
 
8
- Here's a brief script that illustrates the basic operations:
13
+ Here's a brief walkthrough of the basic operations (see `examples/` for more information):
9
14
 
10
- require 'rubygems'
11
15
  require 'divshare'
16
+
17
+ # Set these for your divshare account
18
+ api_key = 'your api key'
19
+ api_secret = 'your api secret'
20
+ email = 'your login email address'
21
+ password = 'your password'
22
+ filename = 'a file you want to upload'
23
+
12
24
  client = Divshare::Client.new(api_key, api_secret)
13
25
  client.login(email, password)
14
26
  all_my_files = client.get_user_files
@@ -16,6 +28,9 @@ Here's a brief script that illustrates the basic operations:
16
28
  print "#{f.file_name} (#{f.file_size}) "
17
29
  puts "was last downloaded #{Time.at(f.last_downloaded_at.to_i)}"
18
30
  end
31
+ ticket = client.get_upload_ticket
32
+ uploaded_id = client.upload(ticket, filename)
33
+ puts "#{filename} uploaded with new id: #{uploaded_id}"
19
34
  client.logout
20
35
 
21
36
  Now, going through the same script step-by-step. Use your Divshare API
@@ -38,13 +53,22 @@ Do something with the files:
38
53
  puts "was last downloaded #{Time.at(f.last_downloaded_at.to_i)}"
39
54
  end
40
55
 
56
+ Upload a file, and capture its id:
57
+
58
+ ticket = client.get_upload_ticket
59
+ uploaded_id = client.upload(ticket, filename)
60
+
41
61
  Logout
42
62
 
43
63
  client.logout
44
64
 
45
- == Installation
65
+ Installation
66
+ ------------
46
67
 
47
68
  Install using rubygems:
48
69
 
49
70
  sudo gem install divshare
50
71
 
72
+ Or clone from github
73
+
74
+ git clone git://github.com/wasnotrice/divshare.git
data/Rakefile CHANGED
@@ -5,19 +5,17 @@ begin
5
5
  t.spec_files = FileList['spec/**/*_spec.rb']
6
6
  t.libs = ['spec', 'lib']
7
7
  t.spec_opts = ["-c", "-f s"]
8
- t.ruby_opts = ["-r rubygems"] # If you want to use rubygems for requires
8
+ t.ruby_opts = ["-r rubygems"] # Remove to require dependencies another way
9
9
  end
10
10
  rescue LoadError
11
11
  puts "RSpec not available. Can't run specs without it. Install with: sudo gem install rspec"
12
12
  end
13
13
 
14
- task :default => :spec
15
-
16
14
  begin
17
15
  require "jeweler"
18
16
  Jeweler::Tasks.new do |gemspec|
19
17
  gemspec.name = "divshare"
20
- gemspec.description = "A Ruby interface to the DivShare file hosting service"
18
+ gemspec.description = File.read('README')
21
19
  gemspec.summary = "A Ruby interface to the DivShare file hosting service"
22
20
  gemspec.date = Time.now.strftime("%Y-%m-%d")
23
21
  gemspec.files = ["README", "LICENSE", "VERSION", "Rakefile", Dir::glob("lib/**/**")].flatten
@@ -27,8 +25,11 @@ begin
27
25
  gemspec.rubyforge_project = "divshare"
28
26
 
29
27
  gemspec.add_dependency "hpricot"
30
- gemspec.add_dependency "mime-types"
28
+ gemspec.add_dependency "mime-types", ">= 1.16"
31
29
  end
32
30
  rescue LoadError
33
31
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
34
32
  end
33
+
34
+ task :default => :spec
35
+ task :build => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -0,0 +1,22 @@
1
+ #/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'divshare'
4
+
5
+ # Set these as needed
6
+ api_key = 'your api key'
7
+ api_secret = 'your api secret'
8
+ email = 'your login email address'
9
+ password = 'your password'
10
+ filename = 'a file you want to upload'
11
+
12
+ client = Divshare::Client.new(api_key, api_secret)
13
+ client.login(email, password)
14
+ all_my_files = client.get_user_files
15
+ all_my_files.each do |f|
16
+ print "#{f.file_name} (#{f.file_size}) "
17
+ puts "was last downloaded #{Time.at(f.last_downloaded_at.to_i)}"
18
+ end
19
+ ticket = client.get_upload_ticket
20
+ uploaded_id = client.upload(ticket, filename)
21
+ puts "#{filename} uploaded with new id: #{uploaded_id}"
22
+ client.logout
@@ -1,37 +1,37 @@
1
- # This is based on this article from Pivot Labs:
2
- # http://pivots.pivotallabs.com/users/damon/blog/articles/227-standup-04-27-07-testing-file-uploads
3
-
4
- require 'net/https'
5
- require "mime/types" # Requires gem install mime-types
6
-
7
- module Net #:nodoc:all
8
- class HTTP::Post
9
- def multipart_params=(param_hash={})
10
- boundary_token = [Array.new(8) {rand(256)}].join
11
- self.content_type = "multipart/form-data; boundary=#{boundary_token}"
12
- boundary_marker = "--#{boundary_token}\r\n"
13
- self.body = param_hash.map { |param_name, param_value|
14
- boundary_marker + case param_value
15
- when File
16
- file_to_multipart(param_name, param_value)
17
- else
18
- text_to_multipart(param_name, param_value.to_s)
19
- end
20
- }.join('') + "--#{boundary_token}--\r\n"
21
- end
22
-
23
- protected
24
- def file_to_multipart(key,file)
25
- filename = File.basename(file.path)
26
- mime_types = MIME::Types.of(filename)
27
- mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
28
- part = %Q|Content-Disposition: form-data; name="#{key}"; filename="#{filename}"\r\n|
29
- part += "Content-Transfer-Encoding: binary\r\n"
30
- part += "Content-Type: #{mime_type}\r\n\r\n#{file.read}\r\n"
31
- end
32
-
33
- def text_to_multipart(key,value)
34
- "Content-Disposition: form-data; name=\"#{key}\"\r\n\r\n#{value}\r\n"
35
- end
36
- end
37
- end
1
+ # This is based on this article from Pivot Labs:
2
+ # http://pivots.pivotallabs.com/users/damon/blog/articles/227-standup-04-27-07-testing-file-uploads
3
+
4
+ require 'net/https'
5
+ require "mime/types" # To use this library as a gem: gem install mime-types
6
+
7
+ module Net #:nodoc:all
8
+ class HTTP::Post
9
+ def multipart_params=(param_hash={})
10
+ boundary_token = [Array.new(8) {rand(256)}].join
11
+ self.content_type = "multipart/form-data; boundary=#{boundary_token}"
12
+ boundary_marker = "--#{boundary_token}\r\n"
13
+ self.body = param_hash.map { |param_name, param_value|
14
+ boundary_marker + case param_value
15
+ when File
16
+ file_to_multipart(param_name, param_value)
17
+ else
18
+ text_to_multipart(param_name, param_value.to_s)
19
+ end
20
+ }.join('') + "--#{boundary_token}--\r\n"
21
+ end
22
+
23
+ protected
24
+ def file_to_multipart(key,file)
25
+ filename = File.basename(file.path)
26
+ mime_types = MIME::Types.of(filename)
27
+ mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
28
+ part = %Q|Content-Disposition: form-data; name="#{key}"; filename="#{filename}"\r\n|
29
+ part += "Content-Transfer-Encoding: binary\r\n"
30
+ part += "Content-Type: #{mime_type}\r\n\r\n#{file.read}\r\n"
31
+ end
32
+
33
+ def text_to_multipart(key,value)
34
+ "Content-Disposition: form-data; name=\"#{key}\"\r\n\r\n#{value}\r\n"
35
+ end
36
+ end
37
+ end
@@ -22,14 +22,23 @@ module ClientSpecHelper
22
22
  @client = Client.new(@api_key, @api_secret)
23
23
  end
24
24
 
25
- def login_setup
25
+ def login_setup(opts={})
26
26
  @mock_response = mock('response')
27
27
  @mock_login_response = mock('login_response')
28
- Net::HTTP.should_receive(:post_form).twice.and_return(@mock_login_response, @mock_response)
28
+ Net::HTTP.should_receive(:post_form).twice.and_return(@mock_login_response, @mock_response)
29
29
  @mock_login_response.should_receive(:body).and_return(successful_login_xml)
30
+ _extra_upload_setup if opts[:request_type] == :upload
30
31
  @client = Client.new(@api_key, @api_secret)
31
32
  @client.login(@user_email, @password)
32
33
  end
34
+
35
+ private
36
+ def _extra_upload_setup
37
+ @mock_http = mock('http')
38
+ Net::HTTP.should_receive(:new).and_return(@mock_http)
39
+ @mock_http.should_receive(:read_timeout=)
40
+ @mock_http.should_receive(:request).and_return({'location' => "http://any.old.url/?file1=123-abcdefghijkl"})
41
+ end
33
42
  end
34
43
 
35
44
  describe "A new Divshare Client" do
@@ -208,4 +217,25 @@ describe "A Divshare Client, unsuccessfully logging out" do
208
217
  @mock_response.should_receive(:body).and_return(unsuccessful_logout_xml)
209
218
  lambda {@client.logout}.should raise_error(Divshare::APIError)
210
219
  end
211
- end
220
+ end
221
+
222
+ describe "A Divshare Client, uploading a file" do
223
+ include ClientSpecHelper
224
+
225
+ before :all do
226
+ common_setup
227
+ end
228
+
229
+ before :each do
230
+ login_setup(:request_type => :upload)
231
+ @mock_response.should_receive(:body).and_return(get_upload_ticket_xml)
232
+ end
233
+
234
+ it "should upload an image file" do
235
+ ticket = @client.get_upload_ticket
236
+ filepath = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/divshare_logo.png'))
237
+ @client.upload(ticket, filepath).should == '123-abcdefghijkl'
238
+ end
239
+ end
240
+
241
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: divshare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Watson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-10 00:00:00 -06:00
12
+ date: 2009-11-19 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,9 +30,83 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: "0"
33
+ version: "1.16"
34
34
  version:
35
- description: A Ruby interface to the DivShare file hosting service
35
+ description: |-
36
+ divshare
37
+ ========
38
+
39
+ Description
40
+ -----------
41
+
42
+ The divshare gem makes it easier to use the Divshare API. To use it, you need
43
+ to create a Divshare account and sign up for an API key.
44
+
45
+ Usage
46
+ -----
47
+
48
+ Here's a brief walkthrough of the basic operations (see `examples/` for more information):
49
+
50
+ require 'divshare'
51
+
52
+ # Set these for your divshare account
53
+ api_key = 'your api key'
54
+ api_secret = 'your api secret'
55
+ email = 'your login email address'
56
+ password = 'your password'
57
+ filename = 'a file you want to upload'
58
+
59
+ client = Divshare::Client.new(api_key, api_secret)
60
+ client.login(email, password)
61
+ all_my_files = client.get_user_files
62
+ all_my_files.each do |f|
63
+ print "#{f.file_name} (#{f.file_size}) "
64
+ puts "was last downloaded #{Time.at(f.last_downloaded_at.to_i)}"
65
+ end
66
+ ticket = client.get_upload_ticket
67
+ uploaded_id = client.upload(ticket, filename)
68
+ puts "#{filename} uploaded with new id: #{uploaded_id}"
69
+ client.logout
70
+
71
+ Now, going through the same script step-by-step. Use your Divshare API
72
+ key and secret (comes with key) to create a client:
73
+
74
+ client = Divshare::Client.new(api_key, api_secret)
75
+
76
+ Login using the credentials for your Divshare account:
77
+
78
+ client.login(email, password)
79
+
80
+ Get an array of all of your files:
81
+
82
+ all_my_files = client.get_user_files
83
+
84
+ Do something with the files:
85
+
86
+ all_my_files.each do |f|
87
+ print "#{f.file_name} (#{f.file_size}) "
88
+ puts "was last downloaded #{Time.at(f.last_downloaded_at.to_i)}"
89
+ end
90
+
91
+ Upload a file, and capture its id:
92
+
93
+ ticket = client.get_upload_ticket
94
+ uploaded_id = client.upload(ticket, filename)
95
+
96
+ Logout
97
+
98
+ client.logout
99
+
100
+ Installation
101
+ ------------
102
+
103
+ Install using rubygems:
104
+
105
+ sudo gem install divshare
106
+
107
+ Or clone from github
108
+
109
+ git clone git://github.com/wasnotrice/divshare.git
36
110
  email: wasnotrice@gmail.com
37
111
  executables: []
38
112
 
@@ -87,3 +161,4 @@ test_files:
87
161
  - spec/encoder_spec.rb
88
162
  - spec/spec_helper.rb
89
163
  - spec/user_spec.rb
164
+ - examples/example.rb