rscribd 1.0.3 → 1.0.4

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,12 @@
1
+ old_dir = Dir.getwd
2
+ Dir.chdir(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rscribd'
4
+
5
+ describe Scribd::ResponseError do
6
+ it "should set the code attribute on initialization" do
7
+ error = Scribd::ResponseError.new(123)
8
+ error.code.should eql(123)
9
+ end
10
+ end
11
+
12
+ Dir.chdir old_dir
@@ -0,0 +1,126 @@
1
+ old_dir = Dir.getwd
2
+ Dir.chdir(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rscribd'
4
+
5
+ describe Scribd::Resource do
6
+ describe "initialized from attributes" do
7
+ before :each do
8
+ @resource = Scribd::Resource.new
9
+ end
10
+
11
+ it "should be unsaved" do
12
+ @resource.should_not be_saved
13
+ end
14
+
15
+ it "should be uncreated" do
16
+ @resource.should_not be_created
17
+ end
18
+ end
19
+
20
+ describe ".save" do
21
+ it "should create a new instance and save it and return it" do
22
+ resource = mock('Scribd::Resource resource')
23
+ resource.should_receive(:save).once
24
+ Scribd::Resource.stub!(:new).and_return(resource)
25
+ Scribd::Resource.create.should eql(resource)
26
+ end
27
+ end
28
+
29
+ it "should not implement save" do
30
+ lambda { Scribd::Resource.new.save }.should raise_error(NotImplementedError)
31
+ end
32
+
33
+ it "should not implement find" do
34
+ lambda { Scribd::Resource.find(1) }.should raise_error(NotImplementedError)
35
+ end
36
+
37
+ it "should not implement destroy" do
38
+ lambda { Scribd::Resource.new.destroy }.should raise_error(NotImplementedError)
39
+ end
40
+
41
+ it "should implement saved?" do
42
+ resource = Scribd::Resource.new
43
+ resource.instance_variable_set(:@saved, true)
44
+ resource.should be_saved
45
+ end
46
+
47
+ it "should implement created?" do
48
+ resource = Scribd::Resource.new
49
+ resource.instance_variable_set(:@created, true)
50
+ resource.should be_created
51
+ end
52
+
53
+ describe "with attributes" do
54
+ before :each do
55
+ @resource = Scribd::Resource.new
56
+ @resource.instance_variable_set(:@attributes, { :access => 'private', :owner => 'me!', :warp => 9 })
57
+ end
58
+
59
+ describe "read_attribute method" do
60
+ it "should raise ArgumentError if the attribute name cannot be converted to a symbol" do
61
+ attr_name = mock('attr_name')
62
+ lambda { @resource.read_attribute attr_name }.should raise_error(ArgumentError)
63
+ end
64
+
65
+ it "should return the attribute value for valid attributes" do
66
+ @resource.read_attribute(:access).should eql('private')
67
+ end
68
+ end
69
+
70
+ describe "read_attributes method" do
71
+ it "should raise ArgumentError if a list is not provided" do
72
+ lambda { @resource.read_attributes nil }.should raise_error(ArgumentError)
73
+ end
74
+
75
+ it "should raise ArgumentError if any attribute name cannot be converted to a symbol" do
76
+ attr_name = mock('attr_name')
77
+ lambda { @resource.read_attributes [ attr_name, :test ] }.should raise_error(ArgumentError)
78
+ end
79
+
80
+ it "should return the values of the given attribute names" do
81
+ @resource.read_attributes([ :access, :owner ]).should == { :access => 'private', :owner => 'me!' }
82
+ end
83
+
84
+ it "should convert all keys to symbols" do
85
+ @resource.read_attributes([ 'access' ]).should == { :access => 'private' }
86
+ end
87
+ end
88
+
89
+ describe "write_attributes method" do
90
+ it "should raise ArgumentError if a hash is not provided" do
91
+ lambda { @resource.write_attributes nil }.should raise_error(ArgumentError)
92
+ end
93
+
94
+ it "should raise ArgumentError if any attribute name cannot be converted to a symbol" do
95
+ attr_name = mock('attr_name')
96
+ lambda { @resource.write_attributes attr_name => 1, :test => 2 }.should raise_error(ArgumentError)
97
+ end
98
+
99
+ it "should set the values of the given attribute names" do
100
+ @resource.write_attributes(:access => 'public', :owner => 'you')
101
+ @resource.access.should eql('public')
102
+ @resource.owner.should eql('you')
103
+ end
104
+
105
+ it "should convert all keys to symbols" do
106
+ @resource.write_attributes('access' => 'public')
107
+ @resource.access.should eql('public')
108
+ end
109
+
110
+ it "should not call save" do
111
+ @resource.should_not_receive(:save)
112
+ @resource.write_attributes 'access' => 'public'
113
+ end
114
+ end
115
+
116
+ it "should create getters for each attribute" do
117
+ lambda { @resource.warp }.should_not raise_error(NoMethodError)
118
+ end
119
+
120
+ it "should create setters for each attribute" do
121
+ lambda { @resource.warp = 5 }.should_not raise_error(NoMethodError)
122
+ end
123
+ end
124
+ end
125
+
126
+ Dir.chdir old_dir
@@ -0,0 +1,35 @@
1
+ old_dir = Dir.getwd
2
+ Dir.chdir(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rscribd'
4
+
5
+ describe Symbol do
6
+ it "should define a to_proc method" do
7
+ Symbol.instance_methods.map { |meth| meth.to_sym }.should include(:to_proc)
8
+ end
9
+
10
+ it "... that returns a Proc" do
11
+ :to_s.to_proc.should be_kind_of(Proc)
12
+ end
13
+ end
14
+
15
+ describe Hash do
16
+ it "should define a stringify_keys method" do
17
+ Hash.instance_methods.map(&:to_sym).should include(:stringify_keys)
18
+ end
19
+
20
+ it "... that converts hash keys into strings" do
21
+ { :a => :b, 1 => 3 }.stringify_keys.should == { 'a' => :b, '1' => 3 }
22
+ end
23
+ end
24
+
25
+ describe Array do
26
+ it "should define a to_hsh method" do
27
+ Array.instance_methods.map(&:to_sym).should include(:to_hsh)
28
+ end
29
+
30
+ it "... that converts nested arrays into a hash" do
31
+ [ [ 1, 2], [3, 4] ].to_hsh.should == { 1 => 2, 3 => 4 }
32
+ end
33
+ end
34
+
35
+ Dir.chdir old_dir
@@ -0,0 +1,195 @@
1
+ old_dir = Dir.getwd
2
+ Dir.chdir(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rscribd'
4
+
5
+ describe Scribd::User do
6
+ describe "initialized from attributes" do
7
+ before :each do
8
+ @user = Scribd::User.new(:username => 'sancho', :name => 'Sancho Sample')
9
+ end
10
+
11
+ it "should have its attributes set appropriately" do
12
+ @user.username.should eql('sancho')
13
+ @user.name.should eql('Sancho Sample')
14
+ end
15
+
16
+ it "should be unsaved" do
17
+ @user.should_not be_saved
18
+ end
19
+
20
+ it "should be uncreated" do
21
+ @user.should_not be_created
22
+ end
23
+ end
24
+
25
+ describe "initialized from XML" do
26
+ before :each do
27
+ @user = Scribd::User.new(:xml => REXML::Document.new("<rsp stat='ok'><username>sancho</username><name>Sancho Sample</name></rsp>").root)
28
+ end
29
+
30
+ it "should have its attributes set appropriately" do
31
+ @user.username.should eql('sancho')
32
+ @user.name.should eql('Sancho Sample')
33
+ end
34
+
35
+ it "should be saved" do
36
+ @user.should be_saved
37
+ end
38
+
39
+ it "should be created" do
40
+ @user.should be_created
41
+ end
42
+ end
43
+
44
+ describe "existing user" do
45
+ before :each do
46
+ @user = Scribd::User.new(:xml => REXML::Document.new("<rsp stat='ok'><user_id type='integer'>225</user_id><username>sancho</username><name>Sancho Sample</name><session_key>some key</session_key></rsp>").root)
47
+ end
48
+
49
+ it "should return the user_id for the id method" do
50
+ @user.id.should eql(225)
51
+ end
52
+
53
+ it "should return the username for the to_s method" do
54
+ @user.to_s.should eql(@user.username)
55
+ end
56
+
57
+ it "should not be saveable" do
58
+ lambda { @user.save }.should raise_error(NotImplementedError)
59
+ end
60
+
61
+ describe "documents method" do
62
+ before :each do
63
+ @xml = REXML::Document.new("<rsp stat='ok'><resultset><result><doc_id type='integer'>123</doc_id></result><result><doc_id type='integer'>234</doc_id></result></resultset></rsp>")
64
+ end
65
+
66
+ it "should docs.getList with the session key" do
67
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.getList', { :session_key => 'some key' }).and_return(@xml)
68
+ @user.documents
69
+ end
70
+
71
+ it "should docs.getList with an offset" do
72
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.getList', { :session_key => 'some key', :offset => 1 }).and_return(@xml)
73
+ @user.documents(:offset => 1)
74
+ end
75
+
76
+ it "should docs.getList with a limit" do
77
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.getList', { :session_key => 'some key', :limit => 1 }).and_return(@xml)
78
+ @user.documents(:limit => 1)
79
+ end
80
+
81
+ it "should return an array of received documents with the owner of each set to this user" do
82
+ Scribd::API.instance.stub!(:send_request).and_return(@xml)
83
+ docs = @user.documents
84
+ docs.should be_kind_of(Array)
85
+ docs.should have(2).items
86
+ docs.first.id.should eql(123)
87
+ docs.last.id.should eql(234)
88
+ docs.each do |doc|
89
+ doc.should be_kind_of(Scribd::Document)
90
+ doc.owner.should eql(@user)
91
+ end
92
+ end
93
+ end
94
+
95
+ describe "find_documents method" do
96
+ it "should call Document.find with an appropriate scope and session key" do
97
+ Scribd::Document.should_receive(:find).once.with(hash_including(:scope => 'user', :session_key => 'some key'))
98
+ @user.find_documents(:query => 'hi!')
99
+ end
100
+
101
+ it "should pass all options to the Document.find method" do
102
+ Scribd::Document.should_receive(:find).once.with(hash_including(:foo => 'bar'))
103
+ @user.find_documents(:foo => 'bar')
104
+ end
105
+ end
106
+
107
+ describe "find_document method" do
108
+ before :each do
109
+ @xml = REXML::Document.new("<rsp stat='ok'><doc_id type='integer'>123</doc_id></rsp>")
110
+ end
111
+
112
+ it "should call docs.getSettings with the appropriate doc_id and session key" do
113
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.getSettings', { :doc_id => 123, :session_key => 'some key' }).and_return(@xml)
114
+ @user.find_document(123)
115
+ end
116
+
117
+ it "should return an appropriate Document with the owner set" do
118
+ Scribd::API.instance.stub!(:send_request).and_return(@xml)
119
+ doc = @user.find_document(123)
120
+ doc.should be_kind_of(Scribd::Document)
121
+ doc.id.should eql(123)
122
+ doc.owner.should eql(@user)
123
+ end
124
+ end
125
+
126
+ it "should have an upload method that calls Document.create" do
127
+ Scribd::Document.should_receive(:create).once.with(:file => 'test', :owner => @user)
128
+ @user.upload(:file => 'test')
129
+ end
130
+ end
131
+
132
+ describe "new user" do
133
+ before :each do
134
+ @user = Scribd::User.new(:login => 'sancho', :name => 'Sancho Sample')
135
+ @xml = REXML::Document.new("<rsp stat='ok'><newattr>newval</newattr></rsp>")
136
+ end
137
+
138
+ describe "save method" do
139
+ it "should call user.signup with the user's attributes" do
140
+ Scribd::API.instance.should_receive(:send_request).once.with('user.signup', { :login => 'sancho', :name => 'Sancho Sample' }).and_return(@xml)
141
+ @user.save
142
+ end
143
+
144
+ it "should set any new attributes in the response" do
145
+ Scribd::API.instance.stub!(:send_request).and_return(@xml)
146
+ @user.save
147
+ @user.newattr.should eql('newval')
148
+ end
149
+
150
+ it "should set the API user to this user" do
151
+ Scribd::API.instance.stub!(:send_request).and_return(@xml)
152
+ @user.save
153
+ Scribd::API.instance.user.should eql(@user)
154
+ end
155
+ end
156
+
157
+ it "should return nil for find_documents" do
158
+ @user.find_documents(:query => 'test').should be_nil
159
+ end
160
+
161
+ it "should return nil for find_document" do
162
+ @user.find_document(123).should be_nil
163
+ end
164
+
165
+ it "should not allow calls to upload" do
166
+ lambda { @user.upload(:file => 'test') }.should raise_error(Scribd::NotReadyError)
167
+ end
168
+ end
169
+
170
+ describe ".username" do
171
+ before :each do
172
+ @xml = REXML::Document.new("<rsp stat='ok'><username>sancho</username><name>Sancho Sample</name></rsp>")
173
+ end
174
+
175
+ it "should call user.username with the username and password" do
176
+ Scribd::API.instance.should_receive(:send_request).once.with('user.login', { :username => 'user', :password => 'pass' }).and_return(@xml)
177
+ Scribd::User.login 'user', 'pass'
178
+ end
179
+
180
+ it "should create a new user from the resulting XML" do
181
+ Scribd::API.instance.stub!(:send_request).and_return(@xml)
182
+ user = Scribd::User.login('user', 'pass')
183
+ user.username.should eql('sancho')
184
+ user.name.should eql('Sancho Sample')
185
+ end
186
+
187
+ it "should set the API user" do
188
+ Scribd::API.instance.stub!(:send_request).and_return(@xml)
189
+ user = Scribd::User.login('user', 'pass')
190
+ Scribd::API.instance.user.should eql(user)
191
+ end
192
+ end
193
+ end
194
+
195
+ Dir.chdir old_dir
metadata CHANGED
@@ -1,15 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rscribd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
- - Jared Friedman, Tim Morgan
7
+ - Tim Morgan
8
+ - Jared Friedman
9
+ - Mike Watts
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
13
 
12
- date: 2009-07-13 00:00:00 -07:00
14
+ date: 2010-02-02 00:00:00 -08:00
13
15
  default_executable:
14
16
  dependencies:
15
17
  - !ruby/object:Gem::Dependency
@@ -18,58 +20,58 @@ dependencies:
18
20
  version_requirement:
19
21
  version_requirements: !ruby/object:Gem::Requirement
20
22
  requirements:
21
- - - ">"
23
+ - - ">="
22
24
  - !ruby/object:Gem::Version
23
- version: 0.0.0
25
+ version: "0"
24
26
  version:
25
27
  - !ruby/object:Gem::Dependency
26
- name: hoe
28
+ name: rspec
27
29
  type: :development
28
30
  version_requirement:
29
31
  version_requirements: !ruby/object:Gem::Requirement
30
32
  requirements:
31
33
  - - ">="
32
34
  - !ruby/object:Gem::Version
33
- version: 2.3.2
35
+ version: "0"
34
36
  version:
35
- description: |-
36
- This gem provides a simple and powerful library for the Scribd API, allowing you
37
- to write Ruby applications or Ruby on Rails websites that upload, convert,
38
- display, search, and control documents in many formats. For more information on
39
- the Scribd platform, visit http://www.scribd.com/publisher
37
+ description: The official Ruby gem for the Scribd API. Scribd is a document-sharing website allowing people to upload and view documents online.
40
38
  email: api@scribd.com
41
39
  executables: []
42
40
 
43
41
  extensions: []
44
42
 
45
43
  extra_rdoc_files:
46
- - History.txt
47
- - Manifest.txt
48
44
  - README.txt
49
- - sample/test.txt
50
45
  files:
46
+ - .gitignore
51
47
  - History.txt
52
48
  - Manifest.txt
53
49
  - README.txt
54
50
  - Rakefile
51
+ - VERSION
52
+ - lib/rscribd.rb
55
53
  - lib/scribdapi.rb
56
54
  - lib/scribddoc.rb
57
55
  - lib/scribderrors.rb
58
56
  - lib/scribdmultiparthack.rb
59
57
  - lib/scribdresource.rb
60
- - lib/rscribd.rb
61
58
  - lib/scribduser.rb
62
59
  - sample/01_upload.rb
63
60
  - sample/02_user.rb
64
61
  - sample/test.txt
62
+ - spec/api_spec.rb
63
+ - spec/document_spec.rb
64
+ - spec/error_spec.rb
65
+ - spec/resource_spec.rb
66
+ - spec/rscribd_spec.rb
67
+ - spec/user_spec.rb
65
68
  has_rdoc: true
66
- homepage:
69
+ homepage: http://www.scribd.com/developers
67
70
  licenses: []
68
71
 
69
72
  post_install_message:
70
73
  rdoc_options:
71
- - --main
72
- - README.txt
74
+ - --charset=UTF-8
73
75
  require_paths:
74
76
  - lib
75
77
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -86,10 +88,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
88
  version:
87
89
  requirements: []
88
90
 
89
- rubyforge_project: rscribd
90
- rubygems_version: 1.3.4
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.5
91
93
  signing_key:
92
94
  specification_version: 3
93
95
  summary: Ruby client library for the Scribd API
94
- test_files: []
95
-
96
+ test_files:
97
+ - spec/api_spec.rb
98
+ - spec/document_spec.rb
99
+ - spec/error_spec.rb
100
+ - spec/resource_spec.rb
101
+ - spec/rscribd_spec.rb
102
+ - spec/user_spec.rb