rmm5t-slideshare 0.2.1.20091230

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ MIT-LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Saiku Desarrollos S.L.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,13 @@
1
+ = slideshare
2
+
3
+ A Ruby wrapper library for the SlideShare API
4
+
5
+ == Requirements
6
+
7
+ You will need to install HTTParty[http://github.com/jnunemaker/httparty/tree/master] and Curb[http://curb.rubyforge.org/] gems.
8
+
9
+ == Caveats
10
+
11
+ This gem is still in its infancy.
12
+
13
+ copyright (c) 2009 Saiku Desarrollos S.L., released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'spec/rake/spectask'
4
+
5
+ Spec::Rake::SpecTask.new(:spec)
6
+
7
+ begin
8
+ require 'jeweler'
9
+ Jeweler::Tasks.new do |gem|
10
+ gem.name = "rmm5t-slideshare"
11
+ gem.summary = %Q{Ruby interface for SlideShare API}
12
+ gem.email = "andy@shenie.info"
13
+ gem.homepage = "http://github.com/rmm5t/slideshare"
14
+ gem.authors = ["Saiku.es", "Russell Norris", "Andy Shen", "Ryan McGeary"]
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ gem.add_dependency('httparty', '>= 0.4.3')
17
+ gem.add_dependency('curb', '>= 0.1.4')
18
+ end
19
+
20
+ Jeweler::GemcutterTasks.new
21
+
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
24
+ end
25
+
26
+ require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'lib' << 'test'
29
+ test.pattern = 'test/**/*_test.rb'
30
+ test.verbose = true
31
+ end
32
+
33
+ begin
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/*_test.rb'
38
+ test.verbose = true
39
+ end
40
+ rescue LoadError
41
+ task :rcov do
42
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
43
+ end
44
+ end
45
+
46
+
47
+ task :default => :test
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ if File.exist?('VERSION.yml')
52
+ config = YAML.load(File.read('VERSION.yml'))
53
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
54
+ else
55
+ version = ""
56
+ end
57
+
58
+ rdoc.rdoc_dir = 'rdoc'
59
+ rdoc.title = "slideshare #{version}"
60
+ rdoc.rdoc_files.include('README*')
61
+ rdoc.rdoc_files.include('lib/**/*.rb')
62
+ end
63
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1.20091230
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "slide_share"
@@ -0,0 +1,79 @@
1
+ require "digest/sha1"
2
+
3
+ module SlideShare
4
+ class Base
5
+ include HTTParty
6
+ base_uri "http://www.slideshare.net/api/2"
7
+ format :xml
8
+
9
+ attr_accessor :api_key, :shared_secret
10
+
11
+ # Returns an instance of <tt>SlideShare::Base</tt>. Takes the following options:
12
+ #
13
+ # * <tt>:api_key</tt> - SlideShare API key
14
+ # * <tt>:shared_pass</tt> - SlideShared shared secret
15
+ #
16
+ # Alternatively, this method may take the path to a YAML file containing
17
+ # this data. Examples (of both):
18
+ #
19
+ # # Using the options hash
20
+ # @slideshare = SlideShare::Base.new(:api_key => "4815162342", :shared_secret => "dharma")
21
+ # # Using the YAML file
22
+ # @slideshare = SlideShare::Base.new("path/to/file.yml")
23
+ def initialize(hash_or_yaml)
24
+ config = hash_or_yaml.is_a?(Hash) ? hash_or_yaml :
25
+ YAML.load_file(hash_or_yaml)
26
+ self.api_key = config[:api_key]
27
+ self.shared_secret = config[:shared_secret]
28
+ unless api_key && shared_secret
29
+ raise ArgumentError, "Configuration must have values for :api_key and :shared_secret"
30
+ end
31
+ end
32
+
33
+ # OO abstraction for <tt>SlideShare::Slideshow</tt> namespace. Example usage:
34
+ #
35
+ # @slideshare = SlideShare::Base.new("path/to/file.yml")
36
+ # @slideshow = @slideshare.slideshows.find(815)
37
+ #
38
+ # This is recommended over initializing and accessing a <tt>SlideShare::Slideshow</tt>
39
+ # object directly.
40
+ def slideshows
41
+ @slideshow ||= Slideshows.new(self)
42
+ end
43
+
44
+ private
45
+ def get(*args)
46
+ catch_errors self.class.get(args.first,
47
+ {:query => add_required_params(args.extract_options!)})
48
+ end
49
+
50
+ def post(*args)
51
+ options = add_required_params(args.extract_options!)
52
+ catch_errors self.class.post(args.first,
53
+ {:query => options})
54
+ end
55
+
56
+ def add_required_params(options)
57
+ now = Time.now.to_i.to_s
58
+ hashed = Digest::SHA1.hexdigest("#{shared_secret}#{now}")
59
+ options.merge(:api_key => api_key, :ts => now, :hash => hashed)
60
+ end
61
+
62
+ def catch_errors(response)
63
+ if error = response.delete("SlideShareServiceError")
64
+ case error["Message"]
65
+ when /failed user authentication/i
66
+ raise FailedUserAuthentication
67
+ when /insufficient permission/i
68
+ raise InsufficientPermission
69
+ when /slideshow not found/i
70
+ raise SlideshowNotFound
71
+ else
72
+ raise ServiceError, error["Message"]
73
+ end
74
+ else
75
+ response
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,18 @@
1
+ module SlideShare
2
+ # Root error
3
+ # Raised when none of the other errors match
4
+ class ServiceError < StandardError; end
5
+
6
+ # Raised when API method requires username and password but none
7
+ # was provided
8
+ class InsufficientPermission < ServiceError; end
9
+
10
+ # Raised when API method was given incorrect username and/or password
11
+ class FailedUserAuthentication < ServiceError; end
12
+
13
+ # Raised when no slideshow matches the supplied slideshow_id
14
+ class SlideshowNotFound < ServiceError; end
15
+
16
+ # Raised when the application has made more than 1000 calls a day
17
+ class AccountExceededDailyLimit < ServiceError; end
18
+ end
@@ -0,0 +1,128 @@
1
+ module SlideShare
2
+ class Slideshows
3
+ attr_accessor :base
4
+
5
+ # This method should only be called internally from an instance of
6
+ # <tt>SlideShare::Base</tt>.
7
+ def initialize(base) # :nodoc:
8
+ self.base = base
9
+ end
10
+
11
+ # Returns id of newly created slideshow if successful or raises an appropriate
12
+ # exception if not. Takes the following options:
13
+ #
14
+ # * <tt>:slideshow_description</tt> - Description for the slideshow
15
+ # * <tt>:slideshow_tags</tt> - Tags for the slideshow. Multiple tags should be separated
16
+ # by spaces, using quotes to create individual multiple word tags.
17
+ # * <tt>:make_src_public</tt> - Set to <tt>true/false</tt> to allow users to download
18
+ # the slideshow
19
+ # * <tt>:make_slideshow_private</tt> - Set to <tt>true/false</tt> to change the privacy
20
+ # setting appropriately
21
+ #
22
+ # The following options will only be used if <tt>:make_slideshow_private</tt> is set
23
+ # <tt>true</tt>:
24
+ #
25
+ # * <tt>:generate_secret_url</tt> - Set to <tt>true/false</tt> to generate a secret URL
26
+ # * <tt>:allow_embeds</tt> - Set to <tt>true/false</tt> to allow websites to embed
27
+ # the private slideshow
28
+ # * <tt>:share_with_contacts</tt> - Set to <tt>true/false</tt> to allow your contacts to
29
+ # view the private slideshow
30
+ def create(title, filename, username, password, options = {})
31
+ force_boolean_params_to_letters! options
32
+ options.merge!(:username => username, :password => password,
33
+ :slideshow_title => title)
34
+ params = base.send(:add_required_params, options).map do |key, value|
35
+ Curl::PostField.content(key.to_s, value)
36
+ end
37
+ params << Curl::PostField.file("slideshow_srcfile", File.expand_path(filename))
38
+
39
+ curl = Curl::Easy.new("#{SlideShare::Base.base_uri}/upload_slideshow") do |c|
40
+ c.multipart_form_post = true
41
+ end
42
+ curl.http_post(*params)
43
+
44
+ body = Crack::XML.parse(curl.body_str)
45
+
46
+ response = base.send(:catch_errors, body)
47
+ # I'd presume the id returned was an integer
48
+ response["SlideShowUploaded"]["SlideShowID"].to_i
49
+ end
50
+
51
+ # Returns hash of attributes for slideshow if successful or raises an appropriate
52
+ # exception if not. Takes the following options:
53
+ #
54
+ # * <tt>:username</tt> - SlideShare username of the user _making_ the request
55
+ # * <tt>:password</tt> - SlideShare password of the user _making_ the request
56
+ # * <tt>:detailed</tt> - Set to <tt>true</tt> to return additional, detailed information
57
+ # about the slideshow (see the official API documentation here[http://www.slideshare.net/developers/documentation]
58
+ # for more information). Default is <tt>false</tt>.
59
+ def find(id, options = {})
60
+ detailed = convert_to_number(options.delete(:detailed))
61
+ options[:detailed] = detailed unless detailed.nil?
62
+ base.send :get, "/get_slideshow", options.merge(:slideshow_id => id)
63
+ end
64
+
65
+ # Returns true if successful or raises an appropriate exception if not.
66
+ # Takes the following options:
67
+ #
68
+ # * <tt>:slideshow_title</tt> - Title for the slideshow
69
+ # * <tt>:slideshow_description</tt> - Description for the slideshow
70
+ # * <tt>:slideshow_tags</tt> - Tags for the slideshow. Multiple tags should be separated
71
+ # by spaces, using quotes to create individual multiple word tags.
72
+ # * <tt>:make_slideshow_private</tt> - Set to <tt>true/false</tt> to change the privacy
73
+ # setting appropriately
74
+ #
75
+ # The following options will only be used if <tt>:make_slideshow_private</tt> is set
76
+ # <tt>true</tt>:
77
+ #
78
+ # * <tt>:generate_secret_url</tt> - Set to <tt>true/false</tt> to generate a secret URL
79
+ # * <tt>:allow_embeds</tt> - Set to <tt>true/false</tt> to allow websites to embed
80
+ # the private slideshow
81
+ # * <tt>:share_with_contacts</tt> - Set to <tt>true/false</tt> to allow your contacts to
82
+ # view the private slideshow
83
+ def update(id, username, password, options = {})
84
+ force_boolean_params_to_letters! options
85
+ base.send(:post, "/edit_slideshow", options.merge(:slideshow_id => id,
86
+ :username => username, :password => password))
87
+ true # This might be too naïve but should have already raised exception if unsuccessful
88
+ end
89
+
90
+ # Returns true if successful or raises an appropriate exception if not.
91
+ def delete(id, username, password)
92
+ base.send :post, "/delete_slideshow", :slideshow_id => id,
93
+ :username => username, :password => password
94
+ true # This might be too naïve but should have already raised exception if unsuccessful
95
+ end
96
+
97
+ private
98
+ def force_boolean_params_to_letters!(hash)
99
+ [
100
+ :make_src_public, :make_slideshow_private, :generate_secret_url,
101
+ :allow_embeds, :share_with_contacts
102
+ ].each do |key|
103
+ value = hash.delete(key)
104
+ unless value.nil?
105
+ hash[key] = convert_to_letter(value, true)
106
+ end
107
+ end
108
+ end
109
+
110
+ def convert_to_letter(value, force = false)
111
+ case value
112
+ when false, "N", nil
113
+ force ? "N" : nil
114
+ when true, "Y"
115
+ "Y"
116
+ end
117
+ end
118
+
119
+ def convert_to_number(value, force = false)
120
+ case value
121
+ when false, 0, nil
122
+ force ? 0 : nil
123
+ when true, 1
124
+ 1
125
+ end
126
+ end
127
+ end
128
+ end
data/lib/slideshare.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "rubygems"
2
+ require "httparty"
3
+ require "curb"
4
+
5
+ require "slide_share/errors"
6
+ require "slide_share/base"
7
+ require "slide_share/slideshows"
8
+
9
+ unless Array.new.respond_to?(:extract_options!)
10
+ # Via ActiveSupport
11
+ class Array
12
+ def extract_options!
13
+ last.is_a?(Hash) ? pop : {}
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ # Note: The keys here must be symbols [as shown below]
2
+ # to be correctly parsed in the API calls
3
+ :api_key: this is not a real api key
4
+ :shared_secret: this is not a real shared secret
@@ -0,0 +1,2 @@
1
+ # :api_key: this is not a real api key
2
+ :shared_secret: this is not a real shared secret
@@ -0,0 +1,2 @@
1
+ :api_key: this is not a real api key
2
+ # :shared_secret: this is not a real shared secret
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <SlideShowDeleted>
3
+ <SlideShowID>815</SlideShowID>
4
+ </SlideShowDeleted>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <SlideShowEdited>
3
+ <SlideShowID>815</SlideShowID>
4
+ </SlideShowEdited>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <SlideShareServiceError>
3
+ <Message>2:Failed User authentication</Message>
4
+ </SlideShareServiceError>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <SlideShareServiceError>
3
+ <Message>SlideShow Not Found</Message>
4
+ </SlideShareServiceError>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <SlideShareServiceError>
3
+ <Message>Insufficient Permissions</Message>
4
+ </SlideShareServiceError>
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Slideshow>
3
+ <ID>815</ID>
4
+ <Title>The Oceanic Six: A Conspiracy of Lies</Title>
5
+ <Description>The Oceanic Six: A Conspiracy of Lies is a short mocumentary which was an extra feature for the season 4 DVD and Blu-ray. It is intentionally edited in the style of amateur and independent conspiracy documentaries such as Loose Change.</Description>
6
+ <Status>2</Status>
7
+ <Username>anon</Username>
8
+ <URL>http://slideshare.net/path/to/slideshare</URL>
9
+ <ThumbnailURL>http://slideshare.net/path/to/thumbnail</ThumbnailURL>
10
+ <ThumbnailSmallURL>http://slideshare.net/path/to/small_thumbnail</ThumbnailSmallURL>
11
+ <Embed>HTML EMBED code</Embed>
12
+ <Created>Mon Sep 22 07:40:33 -0600 2008</Created>
13
+ <Language>en</Language>
14
+ <Format>ppt</Format>
15
+ <Download>1</Download>
16
+ </Slideshow>
@@ -0,0 +1,39 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Slideshow>
3
+ <ID>815</ID>
4
+ <Title>The Oceanic Six: A Conspiracy of Lies</Title>
5
+ <Description>The Oceanic Six: A Conspiracy of Lies is a short mocumentary which was an extra feature for the season 4 DVD and Blu-ray. It is intentionally edited in the style of amateur and independent conspiracy documentaries such as Loose Change.</Description>
6
+ <Status>2</Status>
7
+ <Username>anon</Username>
8
+ <URL>http://slideshare.net/path/to/slideshare</URL>
9
+ <ThumbnailURL>http://slideshare.net/path/to/thumbnail</ThumbnailURL>
10
+ <ThumbnailSmallURL>http://slideshare.net/path/to/small_thumbnail</ThumbnailSmallURL>
11
+ <Embed>HTML EMBED code</Embed>
12
+ <Created>Mon Sep 22 07:40:33 -0600 2008</Created>
13
+ <Language>en</Language>
14
+ <Format>ppt</Format>
15
+ <Download>1</Download>
16
+ <Tags>
17
+ </Tags>
18
+ <NumDownloads>0</NumDownloads>
19
+ <NumViews>0</NumViews>
20
+ <NumComments>0</NumComments>
21
+ <NumFavorites>0</NumFavorites>
22
+ <NumSlides>1</NumSlides>
23
+ <RelatedSlideshows>
24
+ <RelatedSlideshowID rank="10">10</RelatedSlideshowID>
25
+ <RelatedSlideshowID rank="9">9</RelatedSlideshowID>
26
+ <RelatedSlideshowID rank="8">8</RelatedSlideshowID>
27
+ <RelatedSlideshowID rank="7">7</RelatedSlideshowID>
28
+ <RelatedSlideshowID rank="6">6</RelatedSlideshowID>
29
+ <RelatedSlideshowID rank="5">5</RelatedSlideshowID>
30
+ <RelatedSlideshowID rank="4">4</RelatedSlideshowID>
31
+ <RelatedSlideshowID rank="3">3</RelatedSlideshowID>
32
+ <RelatedSlideshowID rank="2">2</RelatedSlideshowID>
33
+ <RelatedSlideshowID rank="1">1</RelatedSlideshowID>
34
+ </RelatedSlideshows>
35
+ <PrivacyLevel>0</PrivacyLevel>
36
+ <SecretURL>0</SecretURL>
37
+ <AllowEmbed>0</AllowEmbed>
38
+ <ShareWithContacts>0</ShareWithContacts>
39
+ </Slideshow>
@@ -0,0 +1,4 @@
1
+ Hmmm
2
+ This is something
3
+ test
4
+ another line
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <SlideShowUploaded>
3
+ <SlideShowID>815</SlideShowID>
4
+ </SlideShowUploaded>
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe SlideShare::Base do
4
+ describe "when initializing with an options hash" do
5
+ it "should require an api key" do
6
+ lambda {
7
+ SlideShare::Base.new(:api_key => "this is not a real api key")
8
+ }.should raise_error(ArgumentError)
9
+ end
10
+
11
+ it "should require an shared secret" do
12
+ lambda {
13
+ SlideShare::Base.new(:shared_secret => "this is not a real shared secret")
14
+ }.should raise_error(ArgumentError)
15
+ end
16
+
17
+ it "should raise no errors if provided api key and shared secret" do
18
+ lambda {
19
+ SlideShare::Base.new(
20
+ :api_key => "this is not a real api key",
21
+ :shared_secret => "this is not a real shared secret"
22
+ )
23
+ }.should_not raise_error
24
+ end
25
+ end
26
+
27
+ describe "when initializing with a YAML file" do
28
+ it "should require an api key" do
29
+ lambda {
30
+ SlideShare::Base.new(spec_fixture("config_missing_api_key.yml"))
31
+ }.should raise_error(ArgumentError)
32
+ end
33
+
34
+ it "should require an shared secret" do
35
+ lambda {
36
+ SlideShare::Base.new(spec_fixture("config_missing_shared_secret.yml"))
37
+ }.should raise_error(ArgumentError)
38
+ end
39
+
40
+ it "should raise no errors if provided api key and shared secret" do
41
+ lambda {
42
+ SlideShare::Base.new(spec_fixture("config.yml"))
43
+ }.should_not raise_error
44
+ end
45
+ end
46
+
47
+ describe "when accessing slideshow functionality" do
48
+ before(:each) do
49
+ @slideshare = SlideShare::Base.new(spec_fixture("config.yml"))
50
+ end
51
+
52
+ it "should abstract access to the SlideShare::Slideshows class through SlideShare#slideshows" do
53
+ @slideshow = mock("SlideShare::Slideshows")
54
+ SlideShare::Slideshows.stub!(:new).and_return(@slideshow)
55
+ @slideshare.slideshows.should == @slideshow
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,150 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe SlideShare::Slideshows do
4
+ before(:all) do
5
+ @slideshare = SlideShare::Base.new(spec_fixture("config.yml"))
6
+ @now = Time.now
7
+ Time.stub!(:now).and_return(@now)
8
+ end
9
+
10
+ describe "when creating a slideshow" do
11
+ before(:each) do
12
+ @upload = spec_fixture("sample.txt")
13
+ @curl = mock("Curl::Easy instance")
14
+ Curl::Easy.stub!(:new).and_return(@curl)
15
+ @curl.stub!(:http_post)
16
+ @curl.stub!(:body_str).and_return(File.read(spec_fixture("upload_slideshow.xml")))
17
+ end
18
+
19
+ # it "should generate the proper API call" do
20
+ # @slideshare.slideshows.create "A Title", @upload, "user", "pass"
21
+ # end
22
+
23
+ it "should return the uploaded slideshow's id when successful" do
24
+ @slideshare.slideshows.create("A Title", @upload, "user", "pass").should == 815
25
+ end
26
+
27
+ it "should raise SlideShare::FailedUserAuthentication if given bad credentials" do
28
+ @curl.stub!(:body_str).and_return(File.read(spec_fixture("error_failed_auth.xml")))
29
+ lambda {
30
+ @slideshare.slideshows.create "A Title", @upload, "wronguser", "wrongpass"
31
+ }.should raise_error(SlideShare::FailedUserAuthentication)
32
+ end
33
+ end
34
+
35
+ describe "when retrieving a slideshow" do
36
+ before(:each) do
37
+ @response = stub_http_response_with("get_slideshow.xml")
38
+ end
39
+
40
+ it "should generate the proper API call" do
41
+ SlideShare::Base.should_receive(:get).with("/get_slideshow",
42
+ :query => add_required_params(@slideshare, :slideshow_id => 815)).and_return(@response)
43
+ @slideshare.slideshows.find(815)
44
+ end
45
+
46
+ it "should convert boolean argument for detailed slideshow into numeric values" do
47
+ SlideShare::Base.should_receive(:get).with("/get_slideshow",
48
+ :query => add_required_params(@slideshare, :slideshow_id => 815, :detailed => 1)).and_return(@response)
49
+ @slideshare.slideshows.find(815, :detailed => true)
50
+ end
51
+
52
+ # I kinda think this sucks but I don't want to make it too brittle.
53
+ # Also, if this fails it's because of an outdated HTTParty gem.
54
+ it "should convert the response into a Hash when successful" do
55
+ @slideshare.slideshows.find(815).is_a?(Hash).should be_true
56
+ end
57
+
58
+ it "should raise SlideShare::SlideshowNotFound if no slideshow matches id" do
59
+ stub_http_response_with("error_not_found.xml")
60
+ lambda {
61
+ @slideshare.slideshows.find 4815162342
62
+ }.should raise_error(SlideShare::SlideshowNotFound)
63
+ end
64
+
65
+ it "should raise SlideShare::FailedUserAuthentication if given bad credentials" do
66
+ stub_http_response_with("error_failed_auth.xml")
67
+ lambda {
68
+ @slideshare.slideshows.find 815, :username => "wrong_user", :password => "wrong_pass"
69
+ }.should raise_error(SlideShare::FailedUserAuthentication)
70
+ end
71
+
72
+ it "should raise SlideShare::InsufficientPermission if username and password are needed but not supplied" do
73
+ stub_http_response_with("error_permissions.xml")
74
+ lambda {
75
+ @slideshare.slideshows.find 815
76
+ }.should raise_error(SlideShare::InsufficientPermission)
77
+ end
78
+ end
79
+
80
+ describe "when updating a slideshow" do
81
+ before(:each) do
82
+ @response = stub_http_response_with("edit_slideshow.xml")
83
+ end
84
+
85
+ it "should generate the proper API call" do
86
+ SlideShare::Base.should_receive(:post).with("/edit_slideshow",
87
+ :query => add_required_params(@slideshare, :slideshow_id => 815,
88
+ :username => "user", :password => "pass")).and_return(@response)
89
+ @slideshare.slideshows.update(815, "user", "pass")
90
+ end
91
+
92
+ it "should convert optional argument for :make_slideshow_private" do
93
+ SlideShare::Base.should_receive(:post).with("/edit_slideshow",
94
+ :query => add_required_params(@slideshare, :slideshow_id => 815,
95
+ :username => "user", :password => "pass",
96
+ :make_slideshow_private => "Y")).and_return(@response)
97
+ @slideshare.slideshows.update(815, "user", "pass", :make_slideshow_private => true)
98
+ end
99
+
100
+ it "should return true if successful" do
101
+ @slideshare.slideshows.update(815, "user", "pass",
102
+ :slideshow_title => "Something New").should be_true
103
+ end
104
+
105
+ it "should raise SlideShare::SlideshowNotFound if no slideshow matches id" do
106
+ stub_http_response_with("error_not_found.xml")
107
+ lambda {
108
+ @slideshare.slideshows.update 4815162342, "user", "pass"
109
+ }.should raise_error(SlideShare::SlideshowNotFound)
110
+ end
111
+
112
+ it "should raise SlideShare::FailedUserAuthentication if given bad credentials" do
113
+ stub_http_response_with("error_failed_auth.xml")
114
+ lambda {
115
+ @slideshare.slideshows.update 815, "wrong_user", "wrong_pass"
116
+ }.should raise_error(SlideShare::FailedUserAuthentication)
117
+ end
118
+ end
119
+
120
+ describe "when deleting a slideshow" do
121
+ before(:each) do
122
+ @response = stub_http_response_with("delete_slideshow.xml")
123
+ end
124
+
125
+ it "should generate the proper API call" do
126
+ SlideShare::Base.should_receive(:post).with("/delete_slideshow",
127
+ :query => add_required_params(@slideshare, :slideshow_id => 815,
128
+ :username => "user", :password => "pass")).and_return(@response)
129
+ @slideshare.slideshows.delete(815, "user", "pass")
130
+ end
131
+
132
+ it "should return true if successful" do
133
+ @slideshare.slideshows.delete(815, "user", "pass").should be_true
134
+ end
135
+
136
+ it "should raise SlideShare::SlideshowNotFound if no slideshow matches id" do
137
+ stub_http_response_with("error_not_found.xml")
138
+ lambda {
139
+ @slideshare.slideshows.delete 4815162342, "user", "pass"
140
+ }.should raise_error(SlideShare::SlideshowNotFound)
141
+ end
142
+
143
+ it "should raise SlideShare::FailedUserAuthentication if given bad credentials" do
144
+ stub_http_response_with("error_failed_auth.xml")
145
+ lambda {
146
+ @slideshare.slideshows.delete 815, "wrong_user", "wrong_pass"
147
+ }.should raise_error(SlideShare::FailedUserAuthentication)
148
+ end
149
+ end
150
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,54 @@
1
+ require "rubygems"
2
+ gem "rspec"
3
+ require "spec"
4
+
5
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
6
+ require "slideshare"
7
+
8
+ def spec_fixture(filename)
9
+ File.expand_path(File.join(File.dirname(__FILE__), "fixtures", filename))
10
+ end
11
+
12
+ def valid_configuration(options = {})
13
+ {
14
+ :api_key => "this is not a real api key",
15
+ :shared_secret => "this is not a real shared secret"
16
+ }.merge(options)
17
+ end
18
+
19
+ def stub_time_now
20
+ # Returning ;)
21
+ now = Time.now
22
+ Time.stub!(:now).and_return(now)
23
+ now
24
+ end
25
+
26
+ def add_required_params(base, hash)
27
+ base.send :add_required_params, hash
28
+ end
29
+
30
+ # Adapted from HTTParty specs
31
+ def stub_http_response_with(filename)
32
+ format = filename.split('.').last.intern
33
+ data = File.read(spec_fixture(filename))
34
+ http = Net::HTTP.new('localhost', 80)
35
+
36
+ response = Net::HTTPOK.new("1.1", 200, "Content for you")
37
+ response.stub!(:body).and_return(data)
38
+ http.stub!(:request).and_return(response)
39
+
40
+ http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://slideshare.net')
41
+ http_request.stub!(:get_response).and_return(response)
42
+ http_request.stub!(:format).and_return(format)
43
+
44
+ HTTParty::Request.stub!(:new).and_return(http_request)
45
+
46
+ case format
47
+ when :xml
48
+ Crack::XML.parse(data)
49
+ when :json
50
+ Crack::JSON.parse(data)
51
+ else
52
+ data
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rmm5t-slideshare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1.20091230
5
+ platform: ruby
6
+ authors:
7
+ - Saiku.es
8
+ - Russell Norris
9
+ - Andy Shen
10
+ - Ryan McGeary
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+
15
+ date: 2009-12-30 00:00:00 -05:00
16
+ default_executable:
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: httparty
20
+ type: :runtime
21
+ version_requirement:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.3
27
+ version:
28
+ - !ruby/object:Gem::Dependency
29
+ name: curb
30
+ type: :runtime
31
+ version_requirement:
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.1.4
37
+ version:
38
+ description:
39
+ email: andy@shenie.info
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - MIT-LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - init.rb
54
+ - lib/slide_share/base.rb
55
+ - lib/slide_share/errors.rb
56
+ - lib/slide_share/slideshows.rb
57
+ - lib/slideshare.rb
58
+ - spec/fixtures/config.yml
59
+ - spec/fixtures/config_missing_api_key.yml
60
+ - spec/fixtures/config_missing_shared_secret.yml
61
+ - spec/fixtures/delete_slideshow.xml
62
+ - spec/fixtures/edit_slideshow.xml
63
+ - spec/fixtures/error_failed_auth.xml
64
+ - spec/fixtures/error_not_found.xml
65
+ - spec/fixtures/error_permissions.xml
66
+ - spec/fixtures/get_slideshow.xml
67
+ - spec/fixtures/get_slideshow_detailed.xml
68
+ - spec/fixtures/sample.txt
69
+ - spec/fixtures/upload_slideshow.xml
70
+ - spec/slide_share/base_spec.rb
71
+ - spec/slide_share/slideshows_spec.rb
72
+ - spec/spec.opts
73
+ - spec/spec_helper.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/rmm5t/slideshare
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.5
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Ruby interface for SlideShare API
102
+ test_files:
103
+ - spec/slide_share/base_spec.rb
104
+ - spec/slide_share/slideshows_spec.rb
105
+ - spec/spec_helper.rb