slideshare_api 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12b16a7b8fd697bcf195e1f8d5909b3a46b41dc8
4
- data.tar.gz: 6005c7902fa67bd5bc58920f44c849f8ea34e912
3
+ metadata.gz: b51beff1edd1f7d82c4f023e91cd22714089ea4f
4
+ data.tar.gz: 5ffdd7a0aeb502c4b4ac764bafa77493c1455711
5
5
  SHA512:
6
- metadata.gz: d59ca225e637d18aeeaeb1f5bda7ff39cb6881731f6efd657d9b86c28d1033d99f29c5862d9ecde3fb28c602ef331e707cab603c705328cadddebb9b31345df4
7
- data.tar.gz: 546739411465c909ba600afd6cc17905ea57f571629cca33948b58cf0a8e913c18c9a5a95ca0c5b53c5320ae46200680194fbd0334a71d573cefdd4d13f1fc88
6
+ metadata.gz: 2871d54d5b029544b65f345325ce70be8cce55d0ab9bfc3559a4b9b7a4f690aaebac64f0fd0186b72a0536f0bd66e5480cf379a4c2940ee5c39fa5172b7543d4
7
+ data.tar.gz: 94d549cc830f334a7f32a5e6f76658cc0b49a9fc55574ff22dd9df4c9db1a8dda0646c93fd0293cdec35763a9b92ef1bb000fb031b223879e8e69c3737fdab2b
@@ -20,7 +20,9 @@ module SlideshareApi
20
20
  params.merge!({slideshow_url: cleaned_url(options[:slideshow_url])}) if options[:slideshow_url]
21
21
  params.merge!({slideshow_id: options[:slideshow_id]}) if options[:slideshow_id]
22
22
  params.merge!({detailed: 1}) if options[:detailed]
23
- SlideshareApi::Model::Slideshow.new Nokogiri::XML(@connection.get('get_slideshow', api_validation_params.merge(params)).body)
23
+ xml_response = Nokogiri::XML(@connection.get('get_slideshow', api_validation_params.merge(params)).body)
24
+ check_error xml_response
25
+ SlideshareApi::Model::Slideshow.new xml_response
24
26
  end
25
27
 
26
28
  private
@@ -29,6 +31,11 @@ module SlideshareApi
29
31
  url.split('?')[0]
30
32
  end
31
33
 
34
+ def check_error(xml_response)
35
+ error = xml_response.search('SlideShareServiceError')
36
+ raise SlideshareApi::Error, xml_response.search('Message').text unless error.empty?
37
+ end
38
+
32
39
  def build_connection
33
40
  @connection = Faraday.new(url: SLIDESHARE_API_URL) do |faraday|
34
41
  faraday.request :json
@@ -0,0 +1,4 @@
1
+ module SlideshareApi
2
+ class Error < Exception
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module SlideshareApi
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -18,41 +18,51 @@ describe SlideshareApi::Client do
18
18
  end
19
19
 
20
20
  describe '.slideshow' do
21
- let(:slideshow_raw_xml) { open('spec/fixtures/slideshow.xml').read }
21
+ context 'there is an error' do
22
+ let(:error_xml) { open('spec/fixtures/error.xml').read }
22
23
 
23
- before { expect(connection).to receive(:body).and_return(slideshow_raw_xml) }
24
+ before { expect(connection).to receive(:get).and_return(connection) }
25
+ before { expect(connection).to receive(:body).and_return(error_xml) }
24
26
 
25
- context 'get from slideshow url' do
26
- context 'url has params' do
27
- let(:slideshow_url_with_params) { 'http://fr.slideshare.net/jeremyvenezia/prerequis-pour-appliquer-le-lean-startup-en-entreprise?ref=http://fr.slideshare.net/?ss' }
28
- let(:slideshow_url) { 'http://fr.slideshare.net/jeremyvenezia/prerequis-pour-appliquer-le-lean-startup-en-entreprise' }
27
+ it { expect(-> { slideshare_client.slideshow }).to raise_error(SlideshareApi::Error) }
28
+ end
29
29
 
30
- before { expect(connection).to receive(:get).with('get_slideshow', api_validation_params.merge({slideshow_url: slideshow_url})).and_return(connection) }
30
+ context 'there is no error' do
31
+ let(:slideshow_raw_xml) { open('spec/fixtures/slideshow.xml').read }
32
+ before { expect(connection).to receive(:body).and_return(slideshow_raw_xml) }
31
33
 
32
- subject { slideshare_client.slideshow slideshow_url: slideshow_url_with_params }
34
+ context 'get from slideshow url' do
35
+ context 'url has params' do
36
+ let(:slideshow_url_with_params) { 'http://fr.slideshare.net/jeremyvenezia/prerequis-pour-appliquer-le-lean-startup-en-entreprise?ref=http://fr.slideshare.net/?ss' }
37
+ let(:slideshow_url) { 'http://fr.slideshare.net/jeremyvenezia/prerequis-pour-appliquer-le-lean-startup-en-entreprise' }
33
38
 
34
- it { should eql? SlideshareApi::Model::Slideshow.new(Nokogiri::XML(slideshow_raw_xml)) }
35
- end
39
+ before { expect(connection).to receive(:get).with('get_slideshow', api_validation_params.merge({slideshow_url: slideshow_url})).and_return(connection) }
36
40
 
37
- context 'url has no params' do
38
- let(:slideshow_url) { 'http://fr.slideshare.net/jeremyvenezia/prerequis-pour-appliquer-le-lean-startup-en-entreprise' }
41
+ subject { slideshare_client.slideshow slideshow_url: slideshow_url_with_params }
39
42
 
40
- before { expect(connection).to receive(:get).with('get_slideshow', api_validation_params.merge({slideshow_url: slideshow_url})).and_return(connection) }
43
+ it { should eql? SlideshareApi::Model::Slideshow.new(Nokogiri::XML(slideshow_raw_xml)) }
44
+ end
41
45
 
42
- subject { slideshare_client.slideshow slideshow_url: slideshow_url }
46
+ context 'url has no params' do
47
+ let(:slideshow_url) { 'http://fr.slideshare.net/jeremyvenezia/prerequis-pour-appliquer-le-lean-startup-en-entreprise' }
43
48
 
44
- it { should eql? SlideshareApi::Model::Slideshow.new(Nokogiri::XML(slideshow_raw_xml)) }
49
+ before { expect(connection).to receive(:get).with('get_slideshow', api_validation_params.merge({slideshow_url: slideshow_url})).and_return(connection) }
50
+
51
+ subject { slideshare_client.slideshow slideshow_url: slideshow_url }
52
+
53
+ it { should eql? SlideshareApi::Model::Slideshow.new(Nokogiri::XML(slideshow_raw_xml)) }
54
+ end
45
55
  end
46
- end
47
56
 
48
- context 'get from slideshow id' do
49
- let(:slideshow_id) { '1234' }
57
+ context 'get from slideshow id' do
58
+ let(:slideshow_id) { '1234' }
50
59
 
51
- before { expect(connection).to receive(:get).with('get_slideshow', api_validation_params.merge({slideshow_id: slideshow_id})).and_return(connection) }
60
+ before { expect(connection).to receive(:get).with('get_slideshow', api_validation_params.merge({slideshow_id: slideshow_id})).and_return(connection) }
52
61
 
53
- subject { slideshare_client.slideshow slideshow_id: slideshow_id }
62
+ subject { slideshare_client.slideshow slideshow_id: slideshow_id }
54
63
 
55
- it { should eql? SlideshareApi::Model::Slideshow.new(Nokogiri::XML(slideshow_raw_xml)) }
64
+ it { should eql? SlideshareApi::Model::Slideshow.new(Nokogiri::XML(slideshow_raw_xml)) }
65
+ end
56
66
  end
57
67
  end
58
68
  end
@@ -0,0 +1,5 @@
1
+ <SlideShareServiceError>
2
+ <Message id="0">
3
+ No API Key Provided
4
+ </Message>
5
+ </SlideShareServiceError>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slideshare_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Venezia
@@ -123,10 +123,12 @@ files:
123
123
  - Rakefile
124
124
  - lib/slideshare_api.rb
125
125
  - lib/slideshare_api/client.rb
126
+ - lib/slideshare_api/error.rb
126
127
  - lib/slideshare_api/model/slideshow.rb
127
128
  - lib/slideshare_api/version.rb
128
129
  - slideshare_api.gemspec
129
130
  - spec/client_spec.rb
131
+ - spec/fixtures/error.xml
130
132
  - spec/fixtures/slideshow.xml
131
133
  - spec/fixtures/slideshow_detailed.xml
132
134
  - spec/model/slideshow_spec.rb
@@ -157,6 +159,7 @@ specification_version: 4
157
159
  summary: Ruby wrapper for the Slideshare API.
158
160
  test_files:
159
161
  - spec/client_spec.rb
162
+ - spec/fixtures/error.xml
160
163
  - spec/fixtures/slideshow.xml
161
164
  - spec/fixtures/slideshow_detailed.xml
162
165
  - spec/model/slideshow_spec.rb