slideshare 0.2.0

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,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "slideshare"
8
+ gem.summary = %Q{Ruby interface for SlideShare API}
9
+ gem.email = "pablo@saiku.es"
10
+ gem.homepage = "http://github.com/saiku/slideshare"
11
+ gem.authors = ["Saiku.es", "Russell Norris", "Andy Shen"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ gem.add_dependency('httparty', '>= 0.4.3')
14
+ gem.add_dependency('curb', '>= 0.1.4')
15
+ end
16
+
17
+ Jeweler::GemcutterTasks.new
18
+
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/*_test.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/*_test.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ if File.exist?('VERSION.yml')
49
+ config = YAML.load(File.read('VERSION.yml'))
50
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
51
+ else
52
+ version = ""
53
+ end
54
+
55
+ rdoc.rdoc_dir = 'rdoc'
56
+ rdoc.title = "slideshare #{version}"
57
+ rdoc.rdoc_files.include('README*')
58
+ rdoc.rdoc_files.include('lib/**/*.rb')
59
+ end
60
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
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,127 @@
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 = ToHashParser.from_xml(curl.body_str)
45
+ response = base.send(:catch_errors, body)
46
+ # I'd presume the id returned was an integer
47
+ response["SlideShowUploaded"]["SlideShowID"].to_i
48
+ end
49
+
50
+ # Returns hash of attributes for slideshow if successful or raises an appropriate
51
+ # exception if not. Takes the following options:
52
+ #
53
+ # * <tt>:username</tt> - SlideShare username of the user _making_ the request
54
+ # * <tt>:password</tt> - SlideShare password of the user _making_ the request
55
+ # * <tt>:detailed</tt> - Set to <tt>true</tt> to return additional, detailed information
56
+ # about the slideshow (see the official API documentation here[http://www.slideshare.net/developers/documentation]
57
+ # for more information). Default is <tt>false</tt>.
58
+ def find(id, options = {})
59
+ detailed = convert_to_number(options.delete(:detailed))
60
+ options[:detailed] = detailed unless detailed.nil?
61
+ base.send :get, "/get_slideshow", options.merge(:slideshow_id => id)
62
+ end
63
+
64
+ # Returns true if successful or raises an appropriate exception if not.
65
+ # Takes the following options:
66
+ #
67
+ # * <tt>:slideshow_title</tt> - Title for the slideshow
68
+ # * <tt>:slideshow_description</tt> - Description for the slideshow
69
+ # * <tt>:slideshow_tags</tt> - Tags for the slideshow. Multiple tags should be separated
70
+ # by spaces, using quotes to create individual multiple word tags.
71
+ # * <tt>:make_slideshow_private</tt> - Set to <tt>true/false</tt> to change the privacy
72
+ # setting appropriately
73
+ #
74
+ # The following options will only be used if <tt>:make_slideshow_private</tt> is set
75
+ # <tt>true</tt>:
76
+ #
77
+ # * <tt>:generate_secret_url</tt> - Set to <tt>true/false</tt> to generate a secret URL
78
+ # * <tt>:allow_embeds</tt> - Set to <tt>true/false</tt> to allow websites to embed
79
+ # the private slideshow
80
+ # * <tt>:share_with_contacts</tt> - Set to <tt>true/false</tt> to allow your contacts to
81
+ # view the private slideshow
82
+ def update(id, username, password, options = {})
83
+ force_boolean_params_to_letters! options
84
+ base.send(:post, "/edit_slideshow", options.merge(:slideshow_id => id,
85
+ :username => username, :password => password))
86
+ true # This might be too naïve but should have already raised exception if unsuccessful
87
+ end
88
+
89
+ # Returns true if successful or raises an appropriate exception if not.
90
+ def delete(id, username, password)
91
+ base.send :post, "/delete_slideshow", :slideshow_id => id,
92
+ :username => username, :password => password
93
+ true # This might be too naïve but should have already raised exception if unsuccessful
94
+ end
95
+
96
+ private
97
+ def force_boolean_params_to_letters!(hash)
98
+ [
99
+ :make_src_public, :make_slideshow_private, :generate_secret_url,
100
+ :allow_embeds, :share_with_contacts
101
+ ].each do |key|
102
+ value = hash.delete(key)
103
+ unless value.nil?
104
+ hash[key] = convert_to_letter(value, true)
105
+ end
106
+ end
107
+ end
108
+
109
+ def convert_to_letter(value, force = false)
110
+ case value
111
+ when false, "N", nil
112
+ force ? "N" : nil
113
+ when true, "Y"
114
+ "Y"
115
+ end
116
+ end
117
+
118
+ def convert_to_number(value, force = false)
119
+ case value
120
+ when false, 0, nil
121
+ force ? 0 : nil
122
+ when true, 1
123
+ 1
124
+ end
125
+ end
126
+ end
127
+ 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,74 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{slideshare}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Saiku.es", "Russell Norris", "Andy Shen"]
12
+ s.date = %q{2009-10-30}
13
+ s.email = %q{pablo@saiku.es}
14
+ s.extra_rdoc_files = [
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ ".document",
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "init.rb",
25
+ "lib/slide_share/base.rb",
26
+ "lib/slide_share/errors.rb",
27
+ "lib/slide_share/slideshows.rb",
28
+ "lib/slideshare.rb",
29
+ "slideshare.gemspec",
30
+ "spec/fixtures/config.yml",
31
+ "spec/fixtures/config_missing_api_key.yml",
32
+ "spec/fixtures/config_missing_shared_secret.yml",
33
+ "spec/fixtures/delete_slideshow.xml",
34
+ "spec/fixtures/edit_slideshow.xml",
35
+ "spec/fixtures/error_failed_auth.xml",
36
+ "spec/fixtures/error_not_found.xml",
37
+ "spec/fixtures/error_permissions.xml",
38
+ "spec/fixtures/get_slideshow.xml",
39
+ "spec/fixtures/get_slideshow_detailed.xml",
40
+ "spec/fixtures/sample.txt",
41
+ "spec/fixtures/upload_slideshow.xml",
42
+ "spec/slide_share/base_spec.rb",
43
+ "spec/slide_share/slideshows_spec.rb",
44
+ "spec/spec.opts",
45
+ "spec/spec_helper.rb"
46
+ ]
47
+ s.homepage = %q{http://github.com/saiku/slideshare}
48
+ s.rdoc_options = ["--charset=UTF-8"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.3.5}
51
+ s.summary = %q{Ruby interface for SlideShare API}
52
+ s.test_files = [
53
+ "spec/slide_share/base_spec.rb",
54
+ "spec/slide_share/slideshows_spec.rb",
55
+ "spec/spec_helper.rb"
56
+ ]
57
+
58
+ if s.respond_to? :specification_version then
59
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
60
+ s.specification_version = 3
61
+
62
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
63
+ s.add_runtime_dependency(%q<httparty>, [">= 0.4.3"])
64
+ s.add_runtime_dependency(%q<curb>, [">= 0.1.4"])
65
+ else
66
+ s.add_dependency(%q<httparty>, [">= 0.4.3"])
67
+ s.add_dependency(%q<curb>, [">= 0.1.4"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<httparty>, [">= 0.4.3"])
71
+ s.add_dependency(%q<curb>, [">= 0.1.4"])
72
+ end
73
+ end
74
+
@@ -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, '')
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
+ ToHashParser.from_xml(data)
49
+ when :json
50
+ JSON.parse(data)
51
+ else
52
+ data
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slideshare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Saiku.es
8
+ - Russell Norris
9
+ - Andy Shen
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-10-30 00:00:00 +11:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: httparty
19
+ type: :runtime
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.4.3
26
+ version:
27
+ - !ruby/object:Gem::Dependency
28
+ name: curb
29
+ type: :runtime
30
+ version_requirement:
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.1.4
36
+ version:
37
+ description:
38
+ email: pablo@saiku.es
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - README.rdoc
45
+ files:
46
+ - .document
47
+ - .gitignore
48
+ - MIT-LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ - VERSION
52
+ - init.rb
53
+ - lib/slide_share/base.rb
54
+ - lib/slide_share/errors.rb
55
+ - lib/slide_share/slideshows.rb
56
+ - lib/slideshare.rb
57
+ - slideshare.gemspec
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/saiku/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