super-mega-slideshare 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/faraday/multipart.rb +30 -0
- data/lib/faraday/parse_slideshare_xml.rb +54 -0
- data/lib/faraday/raise_http_4xx.rb +52 -0
- data/lib/faraday/raise_http_5xx.rb +31 -0
- data/lib/slideshare.rb +30 -0
- data/lib/slideshare/api.rb +256 -0
- data/lib/slideshare/authentication.rb +27 -0
- data/lib/slideshare/client.rb +26 -0
- data/lib/slideshare/configuration.rb +60 -0
- data/lib/slideshare/connection.rb +37 -0
- data/lib/slideshare/error.rb +31 -0
- data/lib/slideshare/request.rb +45 -0
- data/lib/slideshare/version.rb +4 -0
- data/slideshare.gemspec +32 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -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
|
data/slideshare.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
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 = "super-mega-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
|
+
|
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
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: super-mega-slideshare
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Edd Parris
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-14 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: faraday
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.5.4
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 0.3.2
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: nokogiri
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.4.4
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
description: Wrapper for the Slideshare API
|
50
|
+
email:
|
51
|
+
- eddy@nixonmcinnes.co.uk
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- Gemfile
|
61
|
+
- Rakefile
|
62
|
+
- lib/faraday/multipart.rb
|
63
|
+
- lib/faraday/parse_slideshare_xml.rb
|
64
|
+
- lib/faraday/raise_http_4xx.rb
|
65
|
+
- lib/faraday/raise_http_5xx.rb
|
66
|
+
- lib/slideshare.rb
|
67
|
+
- lib/slideshare/api.rb
|
68
|
+
- lib/slideshare/authentication.rb
|
69
|
+
- lib/slideshare/client.rb
|
70
|
+
- lib/slideshare/configuration.rb
|
71
|
+
- lib/slideshare/connection.rb
|
72
|
+
- lib/slideshare/error.rb
|
73
|
+
- lib/slideshare/request.rb
|
74
|
+
- lib/slideshare/version.rb
|
75
|
+
- slideshare.gemspec
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: ""
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message: "\n ****************************************************************\n Thank you for installing super-mega-slideshare!\n ****************************************************************\n "
|
81
|
+
rdoc_options: []
|
82
|
+
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project: super-mega-slideshare
|
100
|
+
rubygems_version: 1.6.1
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Wrapper for the Slideshare API
|
104
|
+
test_files: []
|
105
|
+
|