ruby-slideshare 0.1.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a2374eeca9167e6c1e12d398211f5438bd01c021
4
+ data.tar.gz: abc1ea2abd83f92b209d171de9e2ddc20295eec0
5
+ SHA512:
6
+ metadata.gz: 43983c420ddb40f3d2c5e74b0b5ced5e22acbbf24e960c9cad7774d443d0408038618ee37f217df3ea8833ba8e4677e24fa102b8e3c9f1d223d3b1fa24f27ced
7
+ data.tar.gz: bd1d5f4e9ec1446a16dec7f595764d8c90c06e2009d7e2f7a6c25fa1aa0a68664bc517e85256012c2eb8e2e715474afef232bf0c1e5aeb87dea85f25f55f1846
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in slideshare.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/Readme.markdown ADDED
@@ -0,0 +1,28 @@
1
+ # Super Mega Slideshare
2
+
3
+ A ruby wrapper for Slideshare.
4
+
5
+ ## Example
6
+
7
+ require 'rubygems'
8
+ require 'slideshare'
9
+ Slideshare.configure do |config|
10
+ config.api_key = "XYZ123"
11
+ config.api_secret = "123XYZ"
12
+ end
13
+
14
+ begin
15
+ Slideshare.get_slideshow(:slideshow_url => "http://www.slideshare.net/lolcats/lolcatz-2-minute-break-1", :detailed => 1)
16
+ rescue Slideshare::SlideshareError => e
17
+ puts e
18
+ end
19
+
20
+ begin
21
+ Slideshare.get_slideshows_by_tag(:tag => "lolcats")
22
+ rescue Slideshare::SlideshareError => e
23
+ puts e
24
+ end
25
+
26
+ ## Contributors
27
+
28
+ Written by Edd Parris for NixonMcInnes, large parts copied with great thanks from the Twitter gem (https://github.com/jnunemaker/twitter)
@@ -0,0 +1,30 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module Faraday
5
+ # @private
6
+ class Request::Multipart < Faraday::Middleware
7
+ def call(env)
8
+ if env[:body].is_a?(Hash)
9
+ env[:body].each do |key, value|
10
+ if value.is_a?(File)
11
+ env[:body][key] = Faraday::UploadIO.new(value, mime_type(value), value.path)
12
+ end
13
+ end
14
+ end
15
+
16
+ @app.call(env)
17
+ end
18
+
19
+ private
20
+
21
+ def mime_type(file)
22
+ case file.path
23
+ when /\.jpe?g/i then 'image/jpeg'
24
+ when /\.gif$/i then 'image/gif'
25
+ when /\.png$/i then 'image/png'
26
+ else 'application/octet-stream'
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,54 @@
1
+ require 'faraday'
2
+ require 'nokogiri'
3
+
4
+ # @private
5
+ module Faraday
6
+ # @private
7
+ class Response::ParseSlideshareXml < Response::Middleware
8
+ begin
9
+ require 'multi_xml'
10
+ rescue LoadError, NameError => error
11
+ self.load_error = error
12
+ end
13
+
14
+ def self.register_on_complete(env)
15
+ # parse and raise either proper error or just return the response
16
+ env[:response].on_complete do |response|
17
+ response[:body] = begin
18
+ error_id = nil
19
+ doc = Nokogiri::XML(response[:body])
20
+ doc.search('Message').each do |node|
21
+ raise Slideshare::SlideshareError, error_message(response, node['ID'].to_s + " " + node.text)
22
+ end
23
+ ::MultiXml.parse(response[:body])
24
+ end
25
+ end
26
+ end
27
+
28
+ def initialize(app)
29
+ super
30
+ @parser = nil
31
+ end
32
+
33
+ private
34
+
35
+ def self.error_message(response, message)
36
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]} #{message}"
37
+ end
38
+
39
+ def self.error_body(body)
40
+ if body.nil?
41
+ nil
42
+ elsif body['error']
43
+ ": #{body['error']}"
44
+ elsif body['errors']
45
+ first = body['errors'].to_a.first
46
+ if first.kind_of? Hash
47
+ ": #{first['message'].chomp}"
48
+ else
49
+ ": #{first.chomp}"
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,52 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module Faraday
5
+ # @private
6
+ class Response::RaiseHttp4xx < Response::Middleware
7
+ def self.register_on_complete(env)
8
+ env[:response].on_complete do |response|
9
+ case response[:status].to_i
10
+ when 400
11
+ raise Slideshare::BadRequest, error_message(response)
12
+ when 401
13
+ raise Slideshare::Unauthorized, error_message(response)
14
+ when 403
15
+ raise Slideshare::Forbidden, error_message(response)
16
+ when 404
17
+ raise Slideshare::NotFound, error_message(response)
18
+ when 406
19
+ raise Slideshare::NotAcceptable, error_message(response)
20
+ when 420
21
+ raise Slideshare::EnhanceYourCalm.new error_message(response), response[:response_headers]
22
+ end
23
+ end
24
+ end
25
+
26
+ def initialize(app)
27
+ super
28
+ @parser = nil
29
+ end
30
+
31
+ private
32
+
33
+ def self.error_message(response)
34
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
35
+ end
36
+
37
+ def self.error_body(body)
38
+ if body.nil?
39
+ nil
40
+ elsif body['error']
41
+ ": #{body['error']}"
42
+ elsif body['errors']
43
+ first = body['errors'].to_a.first
44
+ if first.kind_of? Hash
45
+ ": #{first['message'].chomp}"
46
+ else
47
+ ": #{first.chomp}"
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,31 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module Faraday
5
+ # @private
6
+ class Response::RaiseHttp5xx < Response::Middleware
7
+ def self.register_on_complete(env)
8
+ env[:response].on_complete do |response|
9
+ case response[:status].to_i
10
+ when 500
11
+ raise Slideshare::InternalServerError, error_message(response, "Something is technically wrong.")
12
+ when 502
13
+ raise Slideshare::BadGateway, error_message(response, "Slideshare is down or being upgraded.")
14
+ when 503
15
+ raise Slideshare::ServiceUnavailable, error_message(response, "(__-){ Slideshare is over capacity.")
16
+ end
17
+ end
18
+ end
19
+
20
+ def initialize(app)
21
+ super
22
+ @parser = nil
23
+ end
24
+
25
+ private
26
+
27
+ def self.error_message(response, body=nil)
28
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')} Check http://status.twitter.com/ for updates on the status of the Twitter service."
29
+ end
30
+ end
31
+ end
data/lib/slideshare.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'slideshare/error'
2
+ require 'slideshare/configuration'
3
+ require 'slideshare/client'
4
+ require 'slideshare/api'
5
+
6
+
7
+ module Slideshare
8
+ extend Configuration
9
+
10
+ # Alias for Slideshare::Client.new
11
+ #
12
+ # @return [Slideshare::Client]
13
+ def self.client(options={})
14
+ Slideshare::Client.new(options)
15
+ end
16
+
17
+ # Delegate to Slideshare::Client
18
+ def self.method_missing(method, *args, &block)
19
+ return super unless client.respond_to?(method)
20
+ client.send(method, *args, &block)
21
+ end
22
+
23
+ # Delegate to Slideshare::Client
24
+ def self.respond_to?(method)
25
+ return client.respond_to?(method) || super
26
+ end
27
+
28
+ end
29
+
30
+
@@ -0,0 +1,256 @@
1
+ module Slideshare
2
+ module Api
3
+
4
+
5
+ # Authorization: Optional
6
+ # URL: http://www.slideshare.net/api/2/get_slideshow
7
+ # Required parameters:
8
+ # * slideshow_id: ID of the slideshow to be fetched.
9
+ # * slideshow_url: URL of the slideshow to be fetched. This is required if slideshow_id is not set. If both are set, slideshow_id takes precedence.
10
+ # Optional parameters
11
+ # * username: Username of the requesting user
12
+ # * password: Password of the requesting user
13
+ # * exclude_tags: Exclude tags from the detailed information. 1 to exclude.
14
+ # * detailed: Whether or not to include optional information. 1 to include, 0 (default) for basic information.
15
+ def get_slideshow(options={})
16
+ response = get("get_slideshow/", options)
17
+ end
18
+
19
+
20
+ # Authorization: None
21
+ # URL: http://www.slideshare.net/api/2/get_slideshows_by_tag
22
+ # Required parameters:
23
+ # * tag: Tag name
24
+ # Optional: parameters
25
+ # * limit: Specify number of items to return
26
+ # * offset: Specify offset
27
+ # * detailed: Whether or not to include optional information. 1 to include, 0 (default) for basic information.
28
+ def get_slideshows_by_tag(options={})
29
+ response = get("get_slideshows_by_tag/", options)
30
+ end
31
+
32
+ # Authorization: None
33
+ # URL http://www.slideshare.net/api/2/get_slideshows_by_group
34
+ # Required parameters
35
+ # * group_name: Group name (as returned in QueryName element in get_user_groups method)
36
+ # Optional parameters
37
+ # * limit: Specify number of items to return
38
+ # * offset: Specify offset
39
+ # * detailed: Whether or not to include optional information. 1 to include, 0 (default) for basic information.
40
+ def get_slideshows_by_group(options={})
41
+ response = get("get_slideshows_by_group/", options)
42
+ end
43
+
44
+ # Authorization: None
45
+ # URL: http://www.slideshare.net/api/2/get_slideshows_by_user
46
+ # Required parameters:
47
+ # * username_for username of owner of slideshows
48
+ # Optional parameters:
49
+ # * username username of the requesting user
50
+ # * password password of the requesting user
51
+ # * limit specify number of items to return
52
+ # * offset specify offset
53
+ # * detailed Whether or not to include optional information. 1 to include, 0 (default) for basic information.
54
+ # * get_unconverted Whether or not to include unconverted slideshows. 1 to include them, 0 (default) otherwise.
55
+ def get_slideshows_by_user(options={})
56
+ response = get("get_slideshows_by_user/", options)
57
+ end
58
+
59
+ # Authorization: None
60
+ # URL: http://www.slideshare.net/api/2/search_slideshows
61
+ # Required parameters:
62
+ # * q: the query string
63
+ # Optional parameters:
64
+ # * page: The page number of the results (works in conjunction with items_per_page), default is 1
65
+ # * items_per_page: Number of results to return per page, default is 12
66
+ # * lang: Language of slideshows (default is English, 'en') ('**':All,'es':Spanish,'pt':Portuguese,'fr':French,'it':Italian,'nl':Dutch, 'de':German,'zh':Chinese,'ja':Japanese,'ko':Korean,'ro':Romanian, '!!':Other)
67
+ # * sort: Sort order (default is 'relevance') ('mostviewed','mostdownloaded','latest')
68
+ # * upload_date: The time period you want to restrict your search to. 'week' would restrict to the last week. (default is 'any') ('week', 'month', 'year')
69
+ # * what: What type of search. If not set, text search is used. 'tag' is the other option.
70
+ # * download: Slideshows that are available to download; Set to '0' to do this, otherwise default is all slideshows.
71
+ # * fileformat: File format to search for. Default is "all". ('pdf':PDF,'ppt':PowerPoint,'odp':Open Office,'pps':PowerPoint Slideshow,'pot':PowerPoint template)
72
+ # * file_type: File type to search for. Default is "all". ('presentations', 'documents', 'webinars','videos')
73
+ # * cc: Set to '1' to retrieve results under the Creative Commons license. Default is '0'
74
+ # * cc_adapt: Set to '1' for results under Creative Commons that allow adaption, modification. Default is '0'
75
+ # * cc_commercial: Set to '1' to retrieve results with the commercial Creative Commons license. Default is '0'
76
+ # * detailed: Whether or not to include optional information. 1 to include, 0 (default) for basic information.
77
+ def search_slideshows(options={})
78
+ response = get("search_slideshows/", options)
79
+ end
80
+
81
+ # Authorization: Optional
82
+ # URL: http://www.slideshare.net/api/2/get_user_groups
83
+ # Required parameters:
84
+ # * username_for: Username of user whose groups are being requested
85
+ # Optional parameters:
86
+ # * username: Username of the requesting user
87
+ # * password: Password of the requesting user
88
+ def get_user_groups(options={})
89
+ response = get("get_user_groups/", options)
90
+ end
91
+
92
+ # Authorization: Optional
93
+ # URL: http://www.slideshare.net/api/2/get_user_contacts
94
+ # Required parameters:
95
+ # * username_for: username of user whose Contacts are being requested
96
+ # Optional parameters:
97
+ # * limit: Specify number of items to return
98
+ # * offset: Specify offset
99
+ def get_user_contacts(options={})
100
+ response = get("get_user_contacts/", options)
101
+ end
102
+
103
+ # Authorization: Required
104
+ # URL: http://www.slideshare.net/api/2/get_user_tags
105
+ # Required parameters:
106
+ # username: Username of the requesting user
107
+ # password: Password of the requesting user
108
+ def get_user_tags(options={})
109
+ response = get("get_user_tags/", options)
110
+ end
111
+
112
+ # Authorization: Required
113
+ # URL: http://www.slideshare.net/api/2/edit_slideshow
114
+ # Required parameters:
115
+ # * username: Username of the requesting user
116
+ # * password: Password of the requesting user
117
+ # * slideshow_id: Slideshow ID
118
+ # Optional parameters:
119
+ # * slideshow_title: Text
120
+ # * slideshow_description: Text
121
+ # * slideshow_tags: Text
122
+ # * make_slideshow_private: Should be Y if you want to make the slideshow private. If this is not set, following tags will not be considered
123
+ # * generate_secret_url: Generate a secret URL for the slideshow. Requires make_slideshow_private to be Y
124
+ # * allow_embeds: Sets if other websites should be allowed to embed the slideshow. Requires make_slideshow_private to be Y
125
+ # * share_with_contacts: Sets if your contacts on SlideShare can view the slideshow. Requires make_slideshow_private to be Y
126
+ def edit_slideshow(options={})
127
+ response = get("edit_slideshow/", options)
128
+ end
129
+
130
+ # Authorization: Required
131
+ # URL: http://www.slideshare.net/api/2/delete_slideshow
132
+ # Required parameters:
133
+ # * username: username of the requesting user
134
+ # * password: password of the requesting user
135
+ # * slideshow_id: slideshow ID
136
+ def delete_slideshow(options={})
137
+ response = get("delete_slideshow/", options)
138
+ end
139
+
140
+ # Not quite working yet, need to figure out best way to handle uploads.
141
+ # Get versions with upload_url set should work ok though
142
+ # Authorization: Required
143
+ # URL: http://www.slideshare.net/api/2/upload_slideshow
144
+ # Required parameters:
145
+ # * username: Username of the requesting user
146
+ # * password: Password of the requesting user
147
+ # * slideshow_title: Slideshow's title
148
+ # * slideshow_srcfile: Slideshow file (requires HTTP POST)
149
+ # -OR-
150
+ # * upload_url: string containing an url pointing to the power point file: ex: http://domain.tld/directory/my_power_point.ppt
151
+ # The following urls are also acceptable
152
+ # http://www.domain.tld/directory/file.ppt
153
+ # http://www.domain.tld/directory/file.cgi?filename=file.ppt
154
+ #
155
+ # Note, that this will not accept entries that cannot be identified by their extension. If you sent
156
+ # http://www.domain.tld/directory/file.cgi?id=2342
157
+ # We will not be able to identify the type of the file!
158
+ # Optional parameters
159
+ # * slideshow_description: description
160
+ # * slideshow_tags: tags should be comma separated
161
+ # * make_src_public: Y if you want users to be able to download the ppt file, N otherwise. Default is Y
162
+ # Privacy settings (optional):
163
+ # * make_slideshow_private: Should be Y if you want to make the slideshow private. If this is not set, following tags will not be considered
164
+ # * generate_secret_url: Generate a secret URL for the slideshow. Requires make_slideshow_private to be Y
165
+ # * allow_embeds: Sets if other websites should be allowed to embed the slideshow. Requires make_slideshow_private to be Y
166
+ # * share_with_contacts: Sets if your contacts on SlideShare can view the slideshow. Requires make_slideshow_private to be Y
167
+ #
168
+ # The document will upload into the account of the user specified by (username / password). The user associated with the API key need not be the
169
+ # same as the user into who's account the slideshow gets uploaded. So, for example, a bulk uploader would include the api_key (and hash) associated
170
+ # with the API account, and the username and password associated with the account being uploaded to.
171
+ def upload_slideshow(options={})
172
+ response = get("upload_slideshow/", options)
173
+ end
174
+
175
+ # Authorization: Required
176
+ # URL: http://www.slideshare.net/api/2/add_favorite
177
+ # Required parameters:
178
+ # * username: Username of the requesting user
179
+ # * password: Password of the requesting user
180
+ # * slideshow_id: the slideshow to be favorited
181
+ def add_favorite(options={})
182
+ response = get("add_favorite/", options)
183
+ end
184
+
185
+ # Authorization: Required
186
+ # URL: http://www.slideshare.net/api/2/check_favorite
187
+ # Required parameters:
188
+ # * username: username of the requesting user
189
+ # * password: password of the requesting user
190
+ # * slideshow_id: Slideshow which would be favorited
191
+ def check_favorite(options={})
192
+ response = get("check_favorite/", options)
193
+ end
194
+
195
+ # Authorization: Mandatory
196
+ # URL: http://www.slideshare.net/api/2/get_user_campaigns
197
+ # Required parameters:
198
+ # * username: username of the requesting user
199
+ # * password: password of the requesting user
200
+ def get_user_campaigns(options={})
201
+ response = get("get_user_campaigns/", options)
202
+ end
203
+
204
+ # Authorization: Mandatory
205
+ # URL: http://www.slideshare.net/api/2/get_user_leads
206
+ # Required parameters:
207
+ # * username: username of the requesting user
208
+ # * password: password of the requesting user
209
+ # Optional parameters
210
+ # * begin: only get leads collected after this UTC date: YYYYMMDDHHMM
211
+ # * end: only get leads collected before this UTC date: YYYYMMDDHHMM
212
+ # Note: January 18th, 2010.
213
+ # We have changed the field to ,
214
+ # For ruby/C people this is: strftime("%Y%m%d%H%M")
215
+ # We realize that we asking for input dates in UTC, but give out information in MNT
216
+ # time is funny, but we will fix this in the next revision
217
+ def get_user_leads(options={})
218
+ response = get("get_user_leads/", options)
219
+ end
220
+
221
+ # Authorization: Mandatory
222
+ # URL: http://www.slideshare.net/api/2/get_user_campaign_leads
223
+ # Required parameters:
224
+ # * username: username of the requesting user
225
+ # * password: password of the requesting user
226
+ # * campaign_id: campaign_id to select the leads from
227
+ # Optional parameters:
228
+ # * begin: only get leads collected after this UTC date: YYYYMMDDHHMM
229
+ # * end: only get leads collected before this UTC date: YYYYMMDDHHMM
230
+ # Note: January 18th, 2010.
231
+ # We have changed the field to ,
232
+ # For ruby/C people this is: strftime("%Y%m%d%H%M")
233
+ # We realize that we asking for input dates in UTC, but give out information in MNT
234
+ # time is funny, but we will fix this in the next revision.
235
+ def get_user_campaign_leads(options={})
236
+ response = get("get_user_campaign_leads/", options)
237
+ end
238
+
239
+ def get_slideshow(options={})
240
+ response = get("get_slideshow/", options)
241
+ end
242
+
243
+ def get_slideshow(options={})
244
+ response = get("get_slideshow/", options)
245
+ end
246
+
247
+ def get_slideshow(options={})
248
+ response = get("get_slideshow/", options)
249
+ end
250
+
251
+ def get_slideshow(options={})
252
+ response = get("get_slideshow/", options)
253
+ end
254
+
255
+ end
256
+ end
@@ -0,0 +1,27 @@
1
+ require 'digest/sha1'
2
+
3
+ module Slideshare
4
+ # @private
5
+ module Authentication
6
+ private
7
+
8
+ # Authentication hash
9
+ #
10
+ # @return [Hash]
11
+ def authentication
12
+ timestamp = Time.now.to_i.to_s
13
+ {
14
+ :api_key => api_key,
15
+ :ts => timestamp,
16
+ :hash => Digest::SHA1.hexdigest(api_secret + timestamp)
17
+ }
18
+ end
19
+
20
+ # Check whether user is authenticated
21
+ #
22
+ # @return [Boolean]
23
+ def authenticated?
24
+ authentication.values.all?
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ require 'slideshare/connection'
2
+ require 'slideshare/request'
3
+ require 'slideshare/api'
4
+ require 'slideshare/authentication'
5
+
6
+ module Slideshare
7
+ class Client
8
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
9
+
10
+ # Creates a new API
11
+ def initialize(options={})
12
+ options = Slideshare.options.merge(options)
13
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
14
+ send("#{key}=", options[key])
15
+ end
16
+ end
17
+
18
+ include Connection
19
+ include Request
20
+ include Authentication
21
+ include Api
22
+
23
+
24
+
25
+ end
26
+ end
@@ -0,0 +1,60 @@
1
+ require 'faraday'
2
+ require 'slideshare/version'
3
+
4
+ module Slideshare
5
+ module Configuration
6
+ VALID_OPTIONS_KEYS = [
7
+ :adapter,
8
+ :version,
9
+ :api_key,
10
+ :api_secret,
11
+ :api_endpoint,
12
+ :http_endpoint,
13
+ :https_endpoint,
14
+ :format,
15
+ :user_agent
16
+ ].freeze
17
+
18
+ VALID_FROMATS = [:xml].freeze
19
+
20
+ DEFAULT_ADAPTER = Faraday.default_adapter
21
+ DEFAULT_VERSION = "2".freeze
22
+ DEFAULT_API_KEY = nil
23
+ DEFAULT_API_SECRET = nil
24
+ DEFAULT_API_ENDPOINT = "https://www.slideshare.net/api/2/".freeze
25
+ DEFAULT_FORMAT = :xml
26
+ DEFAULT_USER_AGENT = "Slideshare Rub Gem #{Slideshare::VERSION}".freeze
27
+
28
+
29
+ # @private
30
+ attr_accessor *VALID_OPTIONS_KEYS
31
+
32
+ # When this module is extended, set all configuration options to their default values
33
+ def self.extended(base)
34
+ base.reset
35
+ end
36
+
37
+ # Convenience method to allow configuration options to be set in a block
38
+ def configure
39
+ yield self
40
+ end
41
+
42
+ # Create a hash of options and their values
43
+ def options
44
+ Hash[VALID_OPTIONS_KEYS.map {|key| [key, send(key)] }]
45
+ end
46
+
47
+ # Reset all configuration options to defaults
48
+ def reset
49
+ self.adapter = DEFAULT_ADAPTER
50
+ self.version = DEFAULT_VERSION
51
+ self.api_key = DEFAULT_API_KEY
52
+ self.api_secret = DEFAULT_API_SECRET
53
+ self.api_endpoint = DEFAULT_API_ENDPOINT
54
+ self.format = DEFAULT_FORMAT
55
+ self.user_agent = DEFAULT_USER_AGENT
56
+ self
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,37 @@
1
+ require 'faraday_middleware'
2
+ require 'faraday/multipart'
3
+ require 'faraday/raise_http_4xx'
4
+ require 'faraday/raise_http_5xx'
5
+ require 'faraday/parse_slideshare_xml'
6
+
7
+ module Slideshare
8
+ # @private
9
+ module Connection
10
+ private
11
+
12
+ def connection(raw=false)
13
+
14
+ options = {
15
+ :headers => {'Accept' => "application/#{format}", 'User-Agent' => user_agent},
16
+ :ssl => {:verify => false},
17
+ :url => api_endpoint,
18
+ }
19
+
20
+ Faraday::Connection.new(options) do |connection|
21
+ connection.use Faraday::Request::Multipart #, authentication
22
+ #connection.use Faraday::Request::OAuth, authentication if authenticated?
23
+ connection.adapter(adapter)
24
+ connection.use Faraday::Response::RaiseHttp5xx
25
+ unless raw
26
+ case format.to_s.downcase
27
+ when 'json' then connection.use Faraday::Response::ParseJson # one can hope
28
+ when 'xml' then connection.use Faraday::Response::ParseSlideshareXml
29
+ end
30
+ end
31
+ connection.use Faraday::Response::RaiseHttp4xx
32
+ connection.use Faraday::Response::Mashify unless raw
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ module Slideshare
2
+ # Custom error class for rescuing from all SlideShare errors
3
+ class Error < StandardError; end
4
+
5
+ # Raised when SlideShare returns the HTTP status code 400
6
+ class BadRequest < Error; end
7
+
8
+ # Raised when SlideShare returns the HTTP status code 401
9
+ class Unauthorized < Error; end
10
+
11
+ # Raised when SlideShare returns the HTTP status code 403
12
+ class Forbidden < Error; end
13
+
14
+ # Raised when SlideShare returns the HTTP status code 404
15
+ class NotFound < Error; end
16
+
17
+ # Raised when SlideShare returns the HTTP status code 406
18
+ class NotAcceptable < Error; end
19
+
20
+ # Raised when SlideShare returns the HTTP status code 500
21
+ class InternalServerError < Error; end
22
+
23
+ # Raised when SlideShare returns the HTTP status code 502
24
+ class BadGateway < Error; end
25
+
26
+ # Raised when SlideShare returns the HTTP status code 503
27
+ class ServiceUnavailable < Error; end
28
+
29
+ # Raised when SlideShare returns any other error from its API
30
+ class SlideshareError < Error; end
31
+ end
@@ -0,0 +1,45 @@
1
+ module Slideshare
2
+ # Defines HTTP request methods
3
+ module Request
4
+ # Perform an HTTP GET request
5
+ def get(path, options={}, raw=false)
6
+ request(:get, path, options, raw)
7
+ end
8
+
9
+ # Perform an HTTP POST request
10
+ def post(path, options={}, raw=false)
11
+ request(:post, path, options, raw)
12
+ end
13
+
14
+ # Perform an HTTP PUT request
15
+ def put(path, options={}, raw=false)
16
+ request(:put, path, options, raw)
17
+ end
18
+
19
+ # Perform an HTTP DELETE request
20
+ def delete(path, options={}, raw=false)
21
+ request(:delete, path, options, raw)
22
+ end
23
+
24
+ private
25
+
26
+ # Perform an HTTP request
27
+ def request(method, path, options, raw=false)
28
+ options.merge!(authentication)
29
+ response = connection(raw).send(method) do |request|
30
+ case method
31
+ when :get, :delete
32
+ request.url(path, options)
33
+ when :post, :put
34
+ request.path = path
35
+ request.body = options unless options.empty?
36
+ end
37
+ end
38
+ raw ? response : response.body
39
+ end
40
+
41
+ def formatted_path(path)
42
+ [path, format].compact.join('.')
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ module Slideshare
2
+ # The version of the gem
3
+ VERSION = '0.1.2' #.freeze unless defined?(::Slideshare::VERSION)
4
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "slideshare/version"
4
+ #require File.expand_path('../lib/slideshare/version', __FILE__)
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "ruby-slideshare"
8
+ s.version = Slideshare::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Edd Parris"]
11
+ s.email = ["eddy@nixonmcinnes.co.uk"]
12
+ s.homepage = ""
13
+ s.summary = %q{Wrapper for the Slideshare API}
14
+ s.description = %q{Wrapper for the Slideshare API}
15
+
16
+ s.rubyforge_project = s.name
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.post_install_message = "
24
+ ****************************************************************
25
+ Thank you for installing #{s.name}!
26
+ ****************************************************************
27
+ "
28
+ s.add_runtime_dependency('hashie', '~> 1.0.0')
29
+ s.add_runtime_dependency('faraday', '~> 0.5.4')
30
+ s.add_runtime_dependency('faraday_middleware', '~> 0.3.2')
31
+ s.add_runtime_dependency('nokogiri', '~> 1.4.4')
32
+ s.add_runtime_dependency('multi_xml', '~> 0.2')
33
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-slideshare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Edd Parris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.5.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.4.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.4.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: multi_xml
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.2'
83
+ description: Wrapper for the Slideshare API
84
+ email:
85
+ - eddy@nixonmcinnes.co.uk
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - Rakefile
93
+ - Readme.markdown
94
+ - lib/faraday/multipart.rb
95
+ - lib/faraday/parse_slideshare_xml.rb
96
+ - lib/faraday/raise_http_4xx.rb
97
+ - lib/faraday/raise_http_5xx.rb
98
+ - lib/slideshare.rb
99
+ - lib/slideshare/api.rb
100
+ - lib/slideshare/authentication.rb
101
+ - lib/slideshare/client.rb
102
+ - lib/slideshare/configuration.rb
103
+ - lib/slideshare/connection.rb
104
+ - lib/slideshare/error.rb
105
+ - lib/slideshare/request.rb
106
+ - lib/slideshare/version.rb
107
+ - slideshare.gemspec
108
+ homepage: ''
109
+ licenses: []
110
+ metadata: {}
111
+ post_install_message: "\n ****************************************************************\n
112
+ \ Thank you for installing ruby-slideshare!\n ****************************************************************\n
113
+ \ "
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project: ruby-slideshare
129
+ rubygems_version: 2.2.2
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Wrapper for the Slideshare API
133
+ test_files: []