Skip to content

Commit

Permalink
Added support for new Article Search fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Harris committed Dec 14, 2009
1 parent b6b95d9 commit 648b9b4
Show file tree
Hide file tree
Showing 41 changed files with 4,651 additions and 9 deletions.
3 changes: 3 additions & 0 deletions HISTORY
@@ -1,5 +1,8 @@
HISTORY

= 0.4.1
- Added support for comments, dbpedia_resource, dbpedia_resource_url, and terms_facet fields

= 0.4.0
- Changed facet format returned from search
- Changed default fields returned to all
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -12,6 +12,7 @@ begin
s.requirements << 'Unicode'
s.requirements << 'The htmlentities gem'
s.add_dependency('htmlentities')
s.add_development_dependency('fakeweb')
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
Expand Down
4 changes: 2 additions & 2 deletions VERSION.yml
@@ -1,5 +1,5 @@
---
:minor: 5
:patch: 0
:minor: 4
:patch: 1
:major: 0
:build:
17 changes: 16 additions & 1 deletion lib/nytimes_articles/article.rb
Expand Up @@ -10,7 +10,7 @@ class Article < Base
RAW_FIELDS = %w(url)
TEXT_FIELDS = %w(abstract author body byline lead_paragraph nytd_lead_paragraph nytd_title title)
NUMERIC_FIELDS = %w(word_count)
BOOLEAN_FIELDS = %w(fee small_image)
BOOLEAN_FIELDS = %w(fee small_image comments)
IMAGE_FIELDS = %w(small_image small_image_url small_image_height small_image_width)
MULTIMEDIA_FIELDS = %w(multimedia related_multimedia)

Expand Down Expand Up @@ -52,6 +52,10 @@ def initialize(params={})
def free?
not(fee?)
end

##
# An alias for comments
alias :has_comments? comments

##
# Creates a new Article from the a hash returned from the API. This is called on search results. You have no reason to call it.
Expand All @@ -62,6 +66,7 @@ def self.init_from_api(params)
:body => text_field(params['body']),
:byline => text_field(params['byline']),
:fee => boolean_field(params['fee']),
:comments => boolean_field(params['comments']),
:lead_paragraph => text_field(params['lead_paragraph']),
:nytd_title => text_field(params['nytd_title']),
:nytd_lead_paragraph => text_field(params['nytd_lead_paragraph']),
Expand All @@ -87,6 +92,8 @@ def self.init_from_api(params)
# FACETS THAT RETURN ARRAYS
:classifiers => facet_params(params, Facet::CLASSIFIERS),
:descriptions => facet_params(params, Facet::DESCRIPTION),
:dbpedia_resources => facet_params(params, Facet::DBPEDIA_RESOURCE),
:dbpedia_urls => facet_params(params, Facet::DBPEDIA_URL),
:geo => facet_params(params, Facet::GEO),
:material_types => facet_params(params, Facet::MATERIAL_TYPE),
:organizations => facet_params(params, Facet::ORGANIZATION),
Expand Down Expand Up @@ -143,8 +150,11 @@ def self.init_from_api(params)
# * <tt>Facet::COLUMN</tt> - A Times column title (if applicable), such as _Weddings_ or _Ideas & Trends_
# * <tt>Facet::DATE</tt> - The publication date in YYYYMMDD format
# * <tt>Facet::DAY_OF_WEEK</tt> - The day of the week (e.g., Monday, Tuesday) the article was published (compare <tt>PUB_DAY</tt>, which is the numeric date rather than the day of the week)
# * <tt>Facet::DBPEDIA_RESOURCE</tt> - DBpedia person names mapped to Times per_facet terms. This field is case sensitive: values must be Mixed Case.
# * <tt>Facet::DBPEDIA_URL</tt> - URLs to DBpedia person names that have been mapped to Times per_facet terms. This field is case sensitive: values must be Mixed Case.
# * <tt>Facet::DESCRIPTION</tt> - Descriptive subject terms assigned by Times indexers (must be in UPPERCASE)
# * <tt>Facet::DESK</tt> - The Times desk that produced the story (e.g., _Business/Financial Desk_)
# * <tt>Facet::FACET_TERM</tt> - Combines des_facet, geo_facet, org_facet and per_facet. Search facet_terms to find your query in any of those facets (essentially a combined OR search).
# * <tt>Facet::GEO</tt> - Standardized names of geographic locations, assigned by Times indexers (must be in UPPERCASE)
# * <tt>Facet::MATERIAL_TYPE</tt> - The general article type, such as Biography, Editorial or Review
# * <tt>Facet::ORGANIZATION</tt> - Standardized names of people, assigned by Times indexers (must be UPPERCASE)
Expand Down Expand Up @@ -179,6 +189,7 @@ def self.init_from_api(params)
# * <tt>:fee</tt> - if set to true, only returns articles that must be purchased. If false, returns only free articles. If not specified, returns all articles
# * <tt>:has_thumbnail</tt> - returns only articles that have thumbnail images associated. Note that to see the thumbnails, you must specify either <tt>:thumbnail</tt> or <tt>:all</tt> in the <tt>:fields</tt> argument).
# * <tt>:has_multimedia</tt> - to be implemented
# * <tt>:comments</tt> - set to true to return articles that have comments
#
# == FACET SUMMARIES
#
Expand Down Expand Up @@ -382,6 +393,10 @@ def self.add_boolean_params(out_params, in_params)
bool_params << "#{'-' unless in_params[:fee]}fee:Y"
end

unless in_params[:comments].nil?
bool_params << "#{'-' unless in_params[:comments]}comments:Y"
end

unless in_params[:has_multimedia].nil?
bool_params << "#{'-' unless in_params[:has_multimedia]}related_multimedia:Y"
end
Expand Down
15 changes: 12 additions & 3 deletions lib/nytimes_articles/facet.rb
Expand Up @@ -25,8 +25,11 @@ class Facet
COLUMN = 'column_facet'
DATE = 'date'
DAY_OF_WEEK = 'day_of_week_facet'
DBPEDIA_RESOURCE = 'dbpedia_resource'
DBPEDIA_URL = 'dbpedia_resource_url'
DESCRIPTION = 'des_facet'
DESK = 'desk_facet'
FACET_TERM = 'facet_terms'
GEO = 'geo_facet'
MATERIAL_TYPE = 'material_type_facet'
ORGANIZATION = 'org_facet'
Expand All @@ -51,9 +54,9 @@ class Facet
# The default 5 facets to return
DEFAULT_RETURN_FACETS = [DESCRIPTION, GEO, ORGANIZATION, PERSON, DESK]

ALL_FACETS = [CLASSIFIERS, COLUMN, DATE, DAY_OF_WEEK, DESCRIPTION, DESK, GEO, MATERIAL_TYPE, ORGANIZATION, PAGE, PERSON, PUB_DAY,
PUB_MONTH, PUB_YEAR, SECTION_PAGE, SOURCE, WORKS_MENTIONED, NYTD_BYLINE, NYTD_DESCRIPTION, NYTD_GEO,
NYTD_ORGANIZATION, NYTD_PERSON, NYTD_SECTION, NYTD_WORKS_MENTIONED]
ALL_FACETS = [CLASSIFIERS, COLUMN, DATE, DAY_OF_WEEK, DESCRIPTION, DBPEDIA_RESOURCE, DBPEDIA_URL, DESK, GEO, MATERIAL_TYPE, ORGANIZATION, PAGE, PERSON, PUB_DAY,
PUB_MONTH, PUB_YEAR, SECTION_PAGE, SOURCE, WORKS_MENTIONED, NYTD_BYLINE, NYTD_DESCRIPTION, NYTD_GEO,
NYTD_ORGANIZATION, NYTD_PERSON, NYTD_SECTION, NYTD_WORKS_MENTIONED]

##
# Initializes the facet. There is seldom a reason for you to call this.
Expand Down Expand Up @@ -90,6 +93,12 @@ def self.symbol_name(facet)
NYTD_ORGANIZATION
when :nytd_people
NYTD_PERSON
when :dbpedia, :dbpedia_res
DBPEDIA_RESOURCE
when :dbpedia_url, :dbpedia_resource_url
DBPEDIA_URL
when :term, :terms, :facet_terms, :facet_term
FACET_TERM
else
name = facet.to_s.upcase

Expand Down
11 changes: 9 additions & 2 deletions nytimes-articles.gemspec
@@ -1,12 +1,15 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{nytimes-articles}
s.version = "0.4.0"
s.version = "0.4.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jacob Harris"]
s.date = %q{2009-07-23}
s.date = %q{2009-12-13}
s.description = %q{A gem for accessing the New York Times Article Search API}
s.email = %q{jharris@nytimes.com}
s.extra_rdoc_files = [
Expand Down Expand Up @@ -64,10 +67,14 @@ Gem::Specification.new do |s|

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<htmlentities>, [">= 0"])
s.add_development_dependency(%q<fakeweb>, [">= 0"])
else
s.add_dependency(%q<htmlentities>, [">= 0"])
s.add_dependency(%q<fakeweb>, [">= 0"])
end
else
s.add_dependency(%q<htmlentities>, [">= 0"])
s.add_dependency(%q<fakeweb>, [">= 0"])
end
end

Binary file added pkg/nytimes-articles-0.2.0.gem
Binary file not shown.
Binary file added pkg/nytimes-articles-0.2.1.gem
Binary file not shown.
Binary file added pkg/nytimes-articles-0.4.0.gem
Binary file not shown.
Binary file added pkg/nytimes-articles-0.4.1.gem
Binary file not shown.
131 changes: 131 additions & 0 deletions rdoc/classes/Nytimes.html
@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Module: Nytimes</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
<script type="text/javascript">
// <![CDATA[

function popupCode( url ) {
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
}

function toggleCode( id ) {
if ( document.getElementById )
elem = document.getElementById( id );
else if ( document.all )
elem = eval( "document.all." + id );
else
return false;

elemStyle = elem.style;

if ( elemStyle.display != "block" ) {
elemStyle.display = "block"
} else {
elemStyle.display = "none"
}

return true;
}

// Make codeblocks hidden by default
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )

// ]]>
</script>

</head>
<body>



<div id="classHeader">
<table class="header-table">
<tr class="top-aligned-row">
<td><strong>Module</strong></td>
<td class="class-name-in-header">Nytimes</td>
</tr>
<tr class="top-aligned-row">
<td><strong>In:</strong></td>
<td>
<a href="../files/lib/nytimes_articles/article_rb.html">
lib/nytimes_articles/article.rb
</a>
<br />
<a href="../files/lib/nytimes_articles/base_rb.html">
lib/nytimes_articles/base.rb
</a>
<br />
<a href="../files/lib/nytimes_articles/exceptions_rb.html">
lib/nytimes_articles/exceptions.rb
</a>
<br />
<a href="../files/lib/nytimes_articles/facet_rb.html">
lib/nytimes_articles/facet.rb
</a>
<br />
<a href="../files/lib/nytimes_articles/result_set_rb.html">
lib/nytimes_articles/result_set.rb
</a>
<br />
<a href="../files/lib/nytimes_articles/thumbnail_rb.html">
lib/nytimes_articles/thumbnail.rb
</a>
<br />
</td>
</tr>

</table>
</div>
<!-- banner header -->

<div id="bodyContent">



<div id="contextContent">



</div>


</div>


<!-- if includes -->

<div id="section">

<div id="class-list">
<h3 class="section-bar">Classes and Modules</h3>

Module <a href="Nytimes/Articles.html" class="link">Nytimes::Articles</a><br />

</div>







<!-- if method_list -->


</div>


<div id="validator-badges">
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>

0 comments on commit 648b9b4

Please sign in to comment.