readability_parser 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDkzYTkzOTU4Y2RmODhmYzVhMmE5YTA0MDc5MDU4OTMxZjIxMTczYQ==
4
+ ODE4OWYxN2E4NDdlNmM0ZWI0ZjlmYmM4MzRkOGE4OGQ5NjA5NTRiNg==
5
5
  data.tar.gz: !binary |-
6
- MmIxYTNhMWU2OTY3NzAyMmQ5NmE2ZWM2NDllYjA3OTVkNTdjZmRlNw==
6
+ YTA5OTIyZTU1MmRiZTdkMWQ0YjFiYmEwNWE1ZWIwZTk2ZmY3NjIzYQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDE1YzkwOTMxYzQ1N2QzZjE3YjhiNDE1YjQ4YzFjZWI3MTA4ZjQyY2FiODJi
10
- ZDQ2ZmM2YzE1MjRjMzIxMmM5Y2I1YjJkYzUzMjI3YmUzNjc3MzYwNDZiYTMw
11
- OTRiM2ZjMWI1YmRiOWI1ZWM0N2M5ZGU0NDQ4MGExOGYyZjc3YmY=
9
+ NDBlZDhjMWJhMDVjNGQzNmFjMzlkODExYzA2YTc3YjYyMzQzNjI2ZDFiMjBh
10
+ OTQ1MjllNGY4ZTJjMDg0MjYyOTMwYThmMGQ5M2VkZDRjYjM2NjMyMzRmMTkw
11
+ MDY0MDllOTdjMjY3ODcwYTVjMGQzN2UyOGZkNzE4NGRkMzNhNzg=
12
12
  data.tar.gz: !binary |-
13
- ZWYwYTNhYmQ0NWYzNzIwOTg1ZWMzMzJmMWNmNjFkYzdlZTM0OGFkYmY4ODlj
14
- MjFhYWMwYzVkNGVhMTI2OGMwZWM4ODE4MzIxYzZhMzRkNGRlNjU1NmVhZTg2
15
- ZTgyMDdiYmY1ZTFlZDZlNjNkYjcwMmU4MDFmMmE1ZjcxNDVmY2Q=
13
+ Y2U0ZDk2YzlhNWU5M2YxYzgzNDQ3OTkzNjMxNmMzN2M1NDUwMzBhYzMyOGUx
14
+ ZGQwZjczMGFkODQxZGI2N2U0M2I3MTZhZDM5ODE2ZDg5MDM3NmM2YTQ5M2Mx
15
+ OTEyZDU2Yjc2YzdmYTI0YTU3MmUyNzAzMzIyNDEwMGU1MDA2YmY=
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -14,7 +14,7 @@ module ReadabilityParser
14
14
  attr_accessor *VALID_CONFIG_KEYS
15
15
 
16
16
  def self.extended(base)
17
- base.reset
17
+ base.reset!
18
18
  end
19
19
 
20
20
  # Convenience method to allow configuration options to be set in a block
@@ -26,12 +26,14 @@ module ReadabilityParser
26
26
  Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
27
27
  end
28
28
 
29
- def reset
29
+ def reset!
30
30
  self.api_endpoint = DEFAULT_API_ENDPOINT
31
31
  self.user_agent = DEFAULT_USER_AGENT
32
32
 
33
33
  self.api_token = DEFAULT_API_TOKEN
34
34
  self.format = DEFAULT_FORMAT
35
+
36
+ return true
35
37
  end
36
38
  end # Configuration
37
39
  end
@@ -1,8 +1,15 @@
1
+ require 'multi_json'
2
+
1
3
  module ReadabilityParser
2
4
  class Error < StandardError
3
5
 
6
+ # Raised when Readability returns a 4xx or 500 HTTP status code
4
7
  class ClientError < Error
5
8
 
9
+ # Creates a new error from an HTTP environement
10
+ #
11
+ # @param response [Hash]
12
+ # @return [ReadabilityParser::Error::ClientError]
6
13
  def initialize(error=nil)
7
14
  parsed_error = parse_error(error)
8
15
  http_error = error.response[:status].to_i
@@ -14,13 +21,18 @@ module ReadabilityParser
14
21
  end
15
22
  end
16
23
 
17
- def parse_error(error)
18
- JSON.parse(error.response[:body], :symbolize_names => true)
19
- end
24
+ private
25
+
26
+ def parse_error(error)
27
+ MultiJson.load(error.response[:body], :symbolize_keys => true)
28
+ end
20
29
  end # ClientError
21
30
 
22
31
  class ConfigurationError < ReadabilityParser::Error; end
23
32
 
33
+ # Raised when there's an error in Faraday
34
+ class RequestError < ReadabilityParser::Error; end
35
+
24
36
  # Raised when ReadabilityParser returns a 400 HTTP status code
25
37
  class BadRequest < ReadabilityParser::Error; end
26
38
 
@@ -29,7 +29,11 @@ module ReadabilityParser
29
29
  request.url(path, params)
30
30
  end
31
31
  rescue Faraday::Error::ClientError => error
32
- raise ReadabilityParser::Error::ClientError.new(error)
32
+ if error.is_a?(Faraday::Error::ClientError)
33
+ raise ReadabilityParser::Error::ClientError.new(error)
34
+ else
35
+ raise ReadabilityParser::Error::RequestError.new(error)
36
+ end
33
37
  end
34
38
 
35
39
  # When using xml format the response is wrapped in a <response> node
@@ -1,3 +1,3 @@
1
1
  module ReadabilityParser
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
26
26
  gem.add_dependency "faraday_middleware", "~> 0.9.0"
27
27
  gem.add_dependency "hashie", "~> 1.2.0"
28
28
  gem.add_dependency "multi_xml", "~> 0.5.2"
29
+ gem.add_dependency "multi_json", "~> 1.7.2"
29
30
 
30
31
  gem.add_development_dependency "rspec"
31
32
  end
data/spec/helper.rb CHANGED
@@ -1,2 +1,2 @@
1
- require 'readability'
1
+ require 'readability_parser'
2
2
  require 'rspec'
@@ -1,23 +1,4 @@
1
1
  require 'helper'
2
2
 
3
- describe Readability::API::Content do
4
-
5
- before do
6
- @client = Readability::Client.new(:api_token => '12345678910')
7
- end
8
-
9
- after do
10
- Readability.reset
11
- end
12
-
13
- describe ".parse" do
14
- it "fetches the content of a given uri" do
15
- pending
16
- end
17
-
18
- it "returns a Readability::Article" do
19
- pending
20
- end
21
- end
22
-
3
+ describe ReadabilityParser::API::Content do
23
4
  end
@@ -1,5 +1,4 @@
1
1
  require 'helper'
2
2
 
3
- describe Readability::Article do
4
- pending
3
+ describe ReadabilityParser::Article do
5
4
  end
@@ -1,32 +1,63 @@
1
1
  require 'helper'
2
2
 
3
- describe Readability::Client do
3
+ describe ReadabilityParser::Client do
4
4
 
5
5
  after do
6
- Readability.reset
6
+ ReadabilityParser.reset!
7
7
  end
8
8
 
9
- context "when creating a client" do
10
- describe "with no options" do
11
- it "should assign client with default values" do
12
- pending
9
+ context "with module configuration" do
10
+ before do
11
+ ReadabilityParser.configure do |config|
12
+ ReadabilityParser::Configuration::VALID_CONFIG_KEYS.each do |key|
13
+ config.send("#{key}=", key)
14
+ end
13
15
  end
14
16
  end
15
17
 
16
- describe "with options" do
18
+ it "inherits the module configuration" do
19
+ ReadabilityParser::Configuration::VALID_CONFIG_KEYS.each do |key|
20
+ expect(ReadabilityParser.send(:"#{key}")).to eq(key)
21
+ end
22
+ end
23
+ end
17
24
 
18
- it "should accept configuration options" do
19
- pending
25
+ context "with class configuration" do
26
+ before do
27
+ @configuration = {
28
+ api_token: '1234',
29
+ format: :sriracha
30
+ }
31
+ end
32
+
33
+ it "overrides the module configuration after initialization" do
34
+ ReadabilityParser.configure do |config|
35
+ @configuration.each do |key, value|
36
+ config.send("#{key}=", value)
37
+ end
20
38
  end
21
39
 
22
- it "should assign the client with overiden default values" do
23
- pending
40
+ ReadabilityParser::Configuration::VALID_OPTIONS_KEYS.each do |key|
41
+ expect(ReadabilityParser.send(:"#{key}")).to eq(@configuration[key])
24
42
  end
25
43
  end
26
44
  end
27
45
 
28
- context "when using a client" do
29
- pending
46
+ describe "#connection" do
47
+ it "looks like Faraday connection" do
48
+ expect(subject.send(:connection)).to respond_to(:run_request)
49
+ end
30
50
  end
31
51
 
52
+ describe "#request" do
53
+ before { ReadabilityParser.api_token = '1234' }
54
+
55
+ it "catches Faraday connection errors" do
56
+ pending
57
+ end
58
+
59
+ it "catches Readability Parser API errors" do
60
+ pending
61
+ end
62
+ end
32
63
  end
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
- describe Readability::Error do
4
- describe Readability::Error::ClientError do
3
+ describe ReadabilityParser::Error do
4
+ it "raises the correct error based on api HTTP response code" do
5
5
  pending
6
6
  end
7
7
  end
@@ -1,22 +1,14 @@
1
1
  require 'helper'
2
2
 
3
- describe Readability do
3
+ describe ReadabilityParser do
4
4
 
5
5
  after do
6
- Readability.reset
6
+ ReadabilityParser.reset!
7
7
  end
8
8
 
9
- describe ".new" do
10
- it "is a Readability::Client" do
11
- (Readability.new).should be_a_kind_of(Readability::Client)
9
+ describe "#new" do
10
+ it "is a ReadabilityParser::Client" do
11
+ (ReadabilityParser.new).should be_a_kind_of(ReadabilityParser::Client)
12
12
  end
13
13
  end
14
-
15
- describe ".method_missing?" do
16
- pending
17
- end
18
-
19
- describe ".respond_to?" do
20
- pending
21
- end
22
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readability_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philippe Dionne
@@ -38,7 +38,7 @@ cert_chain:
38
38
  aW9OckllMC8xNWRIcERvSUVESUxhNnpVNDZCClhEdHAxWXhkZVZHSUJ1Tm9Q
39
39
  MXZqRFN2TktZajBwTWpSQUVQcnFLMzlqS0U9Ci0tLS0tRU5EIENFUlRJRklD
40
40
  QVRFLS0tLS0K
41
- date: 2013-03-09 00:00:00.000000000 Z
41
+ date: 2013-04-01 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -96,6 +96,20 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: 0.5.2
98
98
  name: multi_xml
99
+ - !ruby/object:Gem::Dependency
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: 1.7.2
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: 1.7.2
112
+ name: multi_json
99
113
  - !ruby/object:Gem::Dependency
100
114
  requirement: !ruby/object:Gem::Requirement
101
115
  requirements:
@@ -138,10 +152,7 @@ files:
138
152
  - spec/readability/api/content_spec.rb
139
153
  - spec/readability/article_spec.rb
140
154
  - spec/readability/client_spec.rb
141
- - spec/readability/configuration_spec.rb
142
- - spec/readability/connection_spec.rb
143
155
  - spec/readability/error_spec.rb
144
- - spec/readability/request_spec.rb
145
156
  - spec/readability_spec.rb
146
157
  homepage: https://github.com/phildionne/readability_parser
147
158
  licenses:
@@ -173,9 +184,6 @@ test_files:
173
184
  - spec/readability/api/content_spec.rb
174
185
  - spec/readability/article_spec.rb
175
186
  - spec/readability/client_spec.rb
176
- - spec/readability/configuration_spec.rb
177
- - spec/readability/connection_spec.rb
178
187
  - spec/readability/error_spec.rb
179
- - spec/readability/request_spec.rb
180
188
  - spec/readability_spec.rb
181
189
  has_rdoc:
metadata.gz.sig CHANGED
Binary file
@@ -1,17 +0,0 @@
1
- require 'helper'
2
-
3
- describe Readability::Configuration do
4
-
5
- after do
6
- Readability.reset
7
- end
8
-
9
- Readability::Configuration::VALID_CONFIG_KEYS.each do |key|
10
- describe ":#{key}" do
11
- it "should return the default value" do
12
- Readability.send(key).should be(Readability::Configuration.const_get("DEFAULT_#{key.upcase}"))
13
- end
14
- end
15
- end
16
-
17
- end
@@ -1,5 +0,0 @@
1
- require 'helper'
2
-
3
- describe Readability::Connection do
4
- pending
5
- end
@@ -1,5 +0,0 @@
1
- require 'helper'
2
-
3
- describe Readability::Request do
4
- pending
5
- end