lib/nytimes_articles/base.rb in taylorbarstow-nytimes-articles-0.2.1 vs lib/nytimes_articles/base.rb in taylorbarstow-nytimes-articles-0.3.0
- old
+ new
@@ -10,20 +10,27 @@
API_NAME = 'article'
API_BASE = "/svc/search/#{API_VERSION}/#{API_NAME}"
@@api_key = nil
@@debug = false
+ @@decode_html_entities = true
##
# 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/
def self.api_key=(key)
@@api_key = key
end
def self.debug=(flag)
@@debug = flag
end
+
+ ##
+ # Set whether or not to decode HTML entities when returning text fields.
+ def self.decode_html_entities=(flag)
+ @@decode_html_entities = flag
+ end
##
# Returns the current value of the API Key
def self.api_key
@@api_key
@@ -32,16 +39,15 @@
##
# Builds a request URI to call the API server
def self.build_request_url(params)
URI::HTTP.build :host => API_SERVER,
:path => API_BASE,
- :query => params.map {|k,v| "#{URI.escape(k)}=#{URI.escape(v)}"}.join('&')
+ :query => params.map {|k,v| "#{URI.escape(k)}=#{URI.escape(v.to_s)}"}.join('&')
end
def self.text_field(value)
return nil if value.nil?
- coder = HTMLEntities.new
- coder.decode(value)
+ @@decode_html_entities ? HTMLEntities.new.decode(value) : value
end
def self.integer_field(value)
return nil if value.nil?
value.to_i
\ No newline at end of file