divshare 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
  require 'divshare/divshare_file'
3
3
  include Divshare
4
4
 
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+ require 'divshare/client'
3
+ require 'divshare/encoder'
4
+ include Divshare
5
+
6
+ module EncoderSpecHelper
7
+ def basic_args(to_merge={})
8
+ {'api_key' => 'api_key', "api_session_key" => 'api_session_key'}.merge(to_merge)
9
+ end
10
+
11
+ def login_args(to_merge={})
12
+ args = basic_args(to_merge).reject { |k,v| %w(api_session_key).include? k }
13
+ args.merge({'method' => 'login'})
14
+ end
15
+
16
+ def logout_args(to_merge={})
17
+ basic_args.merge({'method' => 'logout'})
18
+ end
19
+
20
+ def excluding_sig(hash)
21
+ return hash.reject {|k,v| k == 'api_sig'}
22
+ end
23
+
24
+ def common_setup
25
+ @key = 'api_key'
26
+ @secret = 'api_secret'
27
+ @encoder = Encoder.new(@key, @secret)
28
+ # @client = mock('client')
29
+ # @client.should_receive(:api_key).and_return('api_key')
30
+ @login = {'user_email' => 'email', 'user_password' => 'password'}
31
+ @login_as_symbols = {:user_email => :email, :user_password => :password}
32
+ end
33
+ end
34
+
35
+ describe "An Encoder" do
36
+ include EncoderSpecHelper
37
+
38
+ before(:each) do
39
+ common_setup
40
+ end
41
+
42
+ it "should record key" do
43
+ @encoder.key.should == @key
44
+ end
45
+
46
+ it "should record secret" do
47
+ @encoder.secret.should == @secret
48
+ end
49
+
50
+ it "should generate appropriate arguments for login" do
51
+ @encoder.encode(:login, @login).should == login_args(@login)
52
+ end
53
+
54
+ it "should stringify keys and values for login" do
55
+ @encoder.encode(:login, @login_as_symbols).should == login_args(@login)
56
+ end
57
+
58
+ end
59
+
60
+ describe "An Encoder, after client login" do
61
+ include EncoderSpecHelper
62
+
63
+ before(:each) do
64
+ common_setup
65
+ # Simulates login
66
+ @session_key = 'api_session_key'
67
+ @encoder.session_key = @session_key
68
+ end
69
+
70
+ it "should generate appropriate arguments for logout" do
71
+ result = @encoder.encode(:logout,{})
72
+ excluding_sig(result).should == basic_args({'method' => 'logout'})
73
+ end
74
+
75
+ it "should work without additional hash of arguments" do
76
+ result = @encoder.encode(:logout)
77
+ excluding_sig(result).should == basic_args({'method' => 'logout'})
78
+ end
79
+
80
+ it "should convert symbol keys and values to strings" do
81
+ args_as_symbols = {:file_id => :abc123}
82
+ args_as_strings = {'file_id' => 'abc123'}
83
+ result = @encoder.encode(:get_files, args_as_symbols)
84
+ expected = basic_args.merge(args_as_strings)
85
+ expected.merge!("method" => "get_files")
86
+ excluding_sig(result).should == expected
87
+ end
88
+
89
+ it "should generate proper arguments for post request" do
90
+ method = :get_user_files
91
+ args = {:offset => 3, :limit => 10}
92
+ # api_sig is the md5 digest of 'api_secretapi_session_keylimit10offset3'
93
+ @encoder.encode(method, args).should == {'method' => 'get_user_files',
94
+ 'api_sig' => '1bfa96cc8e92807f96f5694d641d810b',
95
+ 'offset' => '3',
96
+ 'limit' => '10',
97
+ 'api_key' => @key,
98
+ 'api_session_key' => @session_key}
99
+ end
100
+ end
@@ -1,6 +1,3 @@
1
- lib_path = File.join(File.dirname(__FILE__), '..', 'lib')
2
- $:.unshift(lib_path) unless $:.include?(lib_path)
3
-
4
1
  # From http://www.divshare.com/integrate/api
5
2
  module DivshareMockXML
6
3
  def get_user_info_xml
@@ -129,6 +126,15 @@ module DivshareMockXML
129
126
  EOS
130
127
  end
131
128
 
129
+ def unsuccessful_logout_xml
130
+ <<-EOS
131
+ <?xml version="1.0" encoding="UTF-8"?>
132
+ <response status="0">
133
+ <logged_out>false</logged_out>
134
+ </response>
135
+ EOS
136
+ end
137
+
132
138
  def error_xml(message)
133
139
  <<-EOS
134
140
  <?xml version="1.0" encoding="UTF-8"?>
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
  require 'divshare/user'
3
3
  include Divshare
4
4
 
@@ -13,6 +13,4 @@ describe "A basic User" do
13
13
  user.name.should == 'Rob'
14
14
  user.email.should == 'support@divshare.com'
15
15
  end
16
-
17
-
18
16
  end
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.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Watson
@@ -9,10 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-19 00:00:00 -05:00
12
+ date: 2009-11-10 00:00:00 -06:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hpricot
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mime-types
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
16
35
  description: A Ruby interface to the DivShare file hosting service
17
36
  email: wasnotrice@gmail.com
18
37
  executables: []
@@ -20,53 +39,27 @@ executables: []
20
39
  extensions: []
21
40
 
22
41
  extra_rdoc_files:
23
- - History.txt
24
- - License.txt
25
- - Manifest.txt
26
- - README.txt
27
- - website/index.txt
42
+ - LICENSE
43
+ - README
28
44
  files:
29
- - History.txt
30
- - License.txt
31
- - Manifest.txt
32
- - README.txt
45
+ - LICENSE
46
+ - README
33
47
  - Rakefile
34
- - config/hoe.rb
35
- - config/requirements.rb
48
+ - VERSION
36
49
  - lib/divshare.rb
37
50
  - lib/divshare/client.rb
38
51
  - lib/divshare/divshare_file.rb
52
+ - lib/divshare/encoder.rb
39
53
  - lib/divshare/errors.rb
40
- - lib/divshare/post_args.rb
54
+ - lib/divshare/multipart.rb
41
55
  - lib/divshare/user.rb
42
- - lib/divshare/version.rb
43
- - log/debug.log
44
- - script/destroy
45
- - script/generate
46
- - script/test_run_client
47
- - script/txt2html
48
- - setup.rb
49
- - spec/client_spec.rb
50
- - spec/divshare_file_spec.rb
51
- - spec/fixtures/divshare_mock_valid_audio.html
52
- - spec/fixtures/divshare_mock_valid_video.html
53
- - spec/post_args_spec.rb
54
- - spec/spec_helper.rb
55
- - spec/user_spec.rb
56
- - tasks/deployment.rake
57
- - tasks/environment.rake
58
- - tasks/website.rake
59
- - website/index.html
60
- - website/index.txt
61
- - website/javascripts/rounded_corners_lite.inc.js
62
- - website/stylesheets/screen.css
63
- - website/template.rhtml
64
56
  has_rdoc: true
65
- homepage: http://divshare.rubyforge.org
57
+ homepage: http://github.com/wasnotrice/divshare
58
+ licenses: []
59
+
66
60
  post_install_message:
67
61
  rdoc_options:
68
- - --main
69
- - README.txt
62
+ - --charset=UTF-8
70
63
  require_paths:
71
64
  - lib
72
65
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -84,9 +77,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
77
  requirements: []
85
78
 
86
79
  rubyforge_project: divshare
87
- rubygems_version: 1.0.1
80
+ rubygems_version: 1.3.5
88
81
  signing_key:
89
- specification_version: 2
82
+ specification_version: 3
90
83
  summary: A Ruby interface to the DivShare file hosting service
91
- test_files: []
92
-
84
+ test_files:
85
+ - spec/client_spec.rb
86
+ - spec/divshare_file_spec.rb
87
+ - spec/encoder_spec.rb
88
+ - spec/spec_helper.rb
89
+ - spec/user_spec.rb
@@ -1,4 +0,0 @@
1
- == 0.1.0 2008-03-19
2
-
3
- * 1 major enhancement:
4
- * Initial release
@@ -1,35 +0,0 @@
1
- History.txt
2
- License.txt
3
- Manifest.txt
4
- README.txt
5
- Rakefile
6
- config/hoe.rb
7
- config/requirements.rb
8
- lib/divshare.rb
9
- lib/divshare/client.rb
10
- lib/divshare/divshare_file.rb
11
- lib/divshare/errors.rb
12
- lib/divshare/post_args.rb
13
- lib/divshare/user.rb
14
- lib/divshare/version.rb
15
- log/debug.log
16
- script/destroy
17
- script/generate
18
- script/test_run_client
19
- script/txt2html
20
- setup.rb
21
- spec/client_spec.rb
22
- spec/divshare_file_spec.rb
23
- spec/fixtures/divshare_mock_valid_audio.html
24
- spec/fixtures/divshare_mock_valid_video.html
25
- spec/post_args_spec.rb
26
- spec/spec_helper.rb
27
- spec/user_spec.rb
28
- tasks/deployment.rake
29
- tasks/environment.rake
30
- tasks/website.rake
31
- website/index.html
32
- website/index.txt
33
- website/javascripts/rounded_corners_lite.inc.js
34
- website/stylesheets/screen.css
35
- website/template.rhtml
@@ -1,72 +0,0 @@
1
- require 'divshare/version'
2
-
3
- AUTHOR = 'Eric Watson' # can also be an array of Authors
4
- EMAIL = "wasnotrice@gmail.com"
5
- DESCRIPTION = "A Ruby interface to the DivShare file hosting service"
6
- GEM_NAME = 'divshare' # what ppl will type to install your gem
7
- RUBYFORGE_PROJECT = 'divshare' # The unix name for your project
8
- HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
- DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
-
11
- @config_file = "~/.rubyforge/user-config.yml"
12
- @config = nil
13
- RUBYFORGE_USERNAME = "unknown"
14
- def rubyforge_username
15
- unless @config
16
- begin
17
- @config = YAML.load(File.read(File.expand_path(@config_file)))
18
- rescue
19
- puts <<-EOS
20
- ERROR: No rubyforge config file found: #{@config_file}
21
- Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
- - See http://newgem.rubyforge.org/rubyforge.html for more details
23
- EOS
24
- exit
25
- end
26
- end
27
- RUBYFORGE_USERNAME.replace @config["username"]
28
- end
29
-
30
-
31
- REV = nil
32
- # UNCOMMENT IF REQUIRED:
33
- # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
- VERS = Divshare::VERSION::STRING + (REV ? ".#{REV}" : "")
35
- RDOC_OPTS = ['--quiet', '--title', 'divshare documentation',
36
- "--opname", "index.html",
37
- "--line-numbers",
38
- "--main", "README",
39
- "--inline-source"]
40
-
41
- class Hoe
42
- def extra_deps
43
- @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
- @extra_deps
45
- end
46
- end
47
-
48
- # Generate all the Rake tasks
49
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
- hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
- p.author = AUTHOR
52
- p.description = DESCRIPTION
53
- p.email = EMAIL
54
- p.summary = DESCRIPTION
55
- p.url = HOMEPATH
56
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
- p.test_globs = ["test/**/test_*.rb"]
58
- p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
- p.remote_rdoc_dir = '' # Release to root
60
-
61
- # == Optional
62
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
63
- #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
64
-
65
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
66
-
67
- end
68
-
69
- CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
- PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
- hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
- hoe.rsync_args = '-av --delete --ignore-errors'
@@ -1,17 +0,0 @@
1
- require 'fileutils'
2
- include FileUtils
3
-
4
- require 'rubygems'
5
- %w[rake hoe newgem rubigen].each do |req_gem|
6
- begin
7
- require req_gem
8
- rescue LoadError
9
- puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
- puts "Installation: gem install #{req_gem} -y"
11
- exit
12
- end
13
- end
14
-
15
- $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
-
17
- require 'divshare'
@@ -1,16 +0,0 @@
1
- module Divshare
2
- # This is a simple hash that initializes itself in a state appropriate to
3
- # the request. Converts all keys and values to strings.
4
- class PostArgs < Hash
5
- def initialize(client, method, args)
6
- post_args = args.merge({'method' => method, 'api_key' => client.api_key})
7
- if client.api_session_key #&& method.to_sym != :logout
8
- api_sig = client.sign(method, post_args)
9
- post_args.merge!({'api_session_key' => client.api_session_key, 'api_sig' => api_sig})
10
- end
11
- post_args.each { |k,v| self[k.to_s] = v.to_s }
12
- end
13
-
14
-
15
- end
16
- end
@@ -1,9 +0,0 @@
1
- module Divshare #:nodoc:
2
- module VERSION #:nodoc:
3
- MAJOR = 0
4
- MINOR = 1
5
- TINY = 0
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
9
- end
File without changes
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/destroy'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Destroy.new.run(ARGV)