Class: SlideShare::Slideshows

Inherits:
Object
  • Object
show all
Defined in:
lib/slide_share/slideshows.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Slideshows

This method should only be called internally from an instance of SlideShare::Base.



7
8
9
# File 'lib/slide_share/slideshows.rb', line 7

def initialize(base) # :nodoc:
  self.base = base
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



3
4
5
# File 'lib/slide_share/slideshows.rb', line 3

def base
  @base
end

Instance Method Details

#create(title, filename, username, password, options = {}) ⇒ Object

Returns id of newly created slideshow if successful or raises an appropriate exception if not. Takes the following options:

  • :slideshow_description - Description for the slideshow

  • :slideshow_tags - Tags for the slideshow. Multiple tags should be separated by spaces, using quotes to create individual multiple word tags.

  • :make_src_public - Set to true/false to allow users to download the slideshow

  • :make_slideshow_private - Set to true/false to change the privacy setting appropriately

The following options will only be used if :make_slideshow_private is set true:

  • :generate_secret_url - Set to true/false to generate a secret URL

  • :allow_embeds - Set to true/false to allow websites to embed the private slideshow

  • :share_with_contacts - Set to true/false to allow your contacts to view the private slideshow



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/slide_share/slideshows.rb', line 30

def create(title, filename, username, password, options = {})
  force_boolean_params_to_letters! options
  options.merge!(:username => username, :password => password,
    :slideshow_title => title)
  params = base.send(:add_required_params, options).map do |key, value|
    Curl::PostField.content(key.to_s, value)
  end
  params << Curl::PostField.file("slideshow_srcfile", File.expand_path(filename))

  curl = Curl::Easy.new("#{SlideShare::Base.base_uri}/upload_slideshow") do |c|
    c.multipart_form_post = true
  end
  curl.http_post(*params)

  body = Crack::XML.parse(curl.body_str)

  response = base.send(:catch_errors, body)
  # I'd presume the id returned was an integer
  response["SlideShowUploaded"]["SlideShowID"].to_i
end

#delete(id, username, password) ⇒ Object

Returns true if successful or raises an appropriate exception if not.



91
92
93
94
95
# File 'lib/slide_share/slideshows.rb', line 91

def delete(id, username, password)
  base.send :post, "/delete_slideshow", :slideshow_id => id,
    :username => username, :password => password
  true # This might be too naïve but should have already raised exception if unsuccessful
end

#find(id, options = {}) ⇒ Object

Returns hash of attributes for slideshow if successful or raises an appropriate exception if not. Takes the following options:

  • :username - SlideShare username of the user making the request

  • :password - SlideShare password of the user making the request

  • :detailed - Set to true to return additional, detailed information about the slideshow (see the official API documentation here for more information). Default is false.



59
60
61
62
63
# File 'lib/slide_share/slideshows.rb', line 59

def find(id, options = {})
  detailed = convert_to_number(options.delete(:detailed))
  options[:detailed] = detailed unless detailed.nil?
  base.send :get, "/get_slideshow", options.merge(:slideshow_id => id)
end

#update(id, username, password, options = {}) ⇒ Object

Returns true if successful or raises an appropriate exception if not. Takes the following options:

  • :slideshow_title - Title for the slideshow

  • :slideshow_description - Description for the slideshow

  • :slideshow_tags - Tags for the slideshow. Multiple tags should be separated by spaces, using quotes to create individual multiple word tags.

  • :make_slideshow_private - Set to true/false to change the privacy setting appropriately

The following options will only be used if :make_slideshow_private is set true:

  • :generate_secret_url - Set to true/false to generate a secret URL

  • :allow_embeds - Set to true/false to allow websites to embed the private slideshow

  • :share_with_contacts - Set to true/false to allow your contacts to view the private slideshow



83
84
85
86
87
88
# File 'lib/slide_share/slideshows.rb', line 83

def update(id, username, password, options = {})
  force_boolean_params_to_letters! options
  base.send(:post, "/edit_slideshow", options.merge(:slideshow_id => id,
    :username => username, :password => password))
  true # This might be too naïve but should have already raised exception if unsuccessful
end