taylorbarstow-nytimes-articles 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/lib/nytimes_articles/base.rb +9 -3
- data/lib/nytimes_articles/query.rb +1 -1
- data/test/nytimes/articles/test_base.rb +28 -0
- metadata +4 -4
data/VERSION.yml
CHANGED
@@ -12,6 +12,7 @@ module Nytimes
|
|
12
12
|
|
13
13
|
@@api_key = nil
|
14
14
|
@@debug = false
|
15
|
+
@@decode_html_entities = true
|
15
16
|
|
16
17
|
##
|
17
18
|
# Set the API key used for operations. This needs to be called before any requests against the API. To obtain an API key, go to http://developer.nytimes.com/
|
@@ -22,6 +23,12 @@ module Nytimes
|
|
22
23
|
def self.debug=(flag)
|
23
24
|
@@debug = flag
|
24
25
|
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Set whether or not to decode HTML entities when returning text fields.
|
29
|
+
def self.decode_html_entities=(flag)
|
30
|
+
@@decode_html_entities = flag
|
31
|
+
end
|
25
32
|
|
26
33
|
##
|
27
34
|
# Returns the current value of the API Key
|
@@ -34,13 +41,12 @@ module Nytimes
|
|
34
41
|
def self.build_request_url(params)
|
35
42
|
URI::HTTP.build :host => API_SERVER,
|
36
43
|
:path => API_BASE,
|
37
|
-
:query => params.map {|k,v| "#{URI.escape(k)}=#{URI.escape(v)}"}.join('&')
|
44
|
+
:query => params.map {|k,v| "#{URI.escape(k)}=#{URI.escape(v.to_s)}"}.join('&')
|
38
45
|
end
|
39
46
|
|
40
47
|
def self.text_field(value)
|
41
48
|
return nil if value.nil?
|
42
|
-
|
43
|
-
coder.decode(value)
|
49
|
+
@@decode_html_entities ? HTMLEntities.new.decode(value) : value
|
44
50
|
end
|
45
51
|
|
46
52
|
def self.integer_field(value)
|
@@ -8,7 +8,7 @@ module Nytimes
|
|
8
8
|
#
|
9
9
|
class Query
|
10
10
|
FIELDS = [:only_facets, :except_facets, :begin_date, :end_date, :since,
|
11
|
-
:before, :fee, :has_thumbnail, :facets, :fields, :query, :offset] + Article::TEXT_FIELDS.map
|
11
|
+
:before, :fee, :has_thumbnail, :facets, :fields, :query, :offset] + Article::TEXT_FIELDS.map{|f| f.to_sym}
|
12
12
|
FIELDS.each {|f| attr_accessor f}
|
13
13
|
|
14
14
|
# Produce a hash which uniquely identifies this query
|
@@ -88,5 +88,33 @@ class TestNytimes::TestArticles::TestBase < Test::Unit::TestCase
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
context "when passing Integer for offset" do
|
93
|
+
# note Article.search requries integer for offset
|
94
|
+
setup do
|
95
|
+
FakeWeb.register_uri(api_url_for('offset' => '1'), :status => ['200', 'OK'], :string => '{}')
|
96
|
+
end
|
97
|
+
|
98
|
+
should "not raise NoMethodError" do
|
99
|
+
assert_nothing_raised(NoMethodError) { Base.invoke('offset' => 1) }
|
100
|
+
end
|
101
|
+
end
|
91
102
|
end
|
103
|
+
|
104
|
+
context "Base#text_field" do
|
105
|
+
context "when decode_html_entities == true" do
|
106
|
+
should "decode HTML entities in text fields" do
|
107
|
+
assert_equal "foó", Base.text_field("foó")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when decode_html_entities == false" do
|
112
|
+
setup { Base.decode_html_entities = false }
|
113
|
+
teardown { Base.decode_html_entities = true }
|
114
|
+
|
115
|
+
should "not decode HTML entities in text fields" do
|
116
|
+
assert_equal "foó", Base.text_field("foó")
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
92
120
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taylorbarstow-nytimes-articles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Harris
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-03 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -37,18 +37,18 @@ files:
|
|
37
37
|
- lib/nytimes_articles/base.rb
|
38
38
|
- lib/nytimes_articles/exceptions.rb
|
39
39
|
- lib/nytimes_articles/facet.rb
|
40
|
+
- lib/nytimes_articles/query.rb
|
40
41
|
- lib/nytimes_articles/result_set.rb
|
41
42
|
- lib/nytimes_articles/thumbnail.rb
|
42
|
-
- lib/nytimes_articles/query.rb
|
43
43
|
- lib/nytimes_articles.rb
|
44
44
|
- test/nytimes
|
45
45
|
- test/nytimes/articles
|
46
46
|
- test/nytimes/articles/test_article.rb
|
47
47
|
- test/nytimes/articles/test_base.rb
|
48
48
|
- test/nytimes/articles/test_facet.rb
|
49
|
+
- test/nytimes/articles/test_query.rb
|
49
50
|
- test/nytimes/articles/test_result_set.rb
|
50
51
|
- test/nytimes/articles/test_thumbnail.rb
|
51
|
-
- test/nytimes/articles/test_query.rb
|
52
52
|
- test/test_helper.rb
|
53
53
|
has_rdoc: true
|
54
54
|
homepage: http://github.com/harrisj/nytimes-articles
|