times_wire 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -2
- data/lib/times_wire/base.rb +9 -0
- data/lib/times_wire/item.rb +11 -0
- data/lib/times_wire/version.rb +1 -1
- metadata +31 -53
data/README.rdoc
CHANGED
@@ -9,6 +9,7 @@ Times Wire is a Ruby gem for interacting with The New York Times Newswire API (h
|
|
9
9
|
|
10
10
|
== News
|
11
11
|
|
12
|
+
* May 3, 2013: Version 0.9.0 released, added Item.url method and tested under 1.9.3.
|
12
13
|
* Dec. 16, 2011: Version 0.8.0 released, Item returns DateTime objects instead of Dates.
|
13
14
|
* Dec. 15, 2011: Version 0.7.0 released, adding support for retrieving list of sections.
|
14
15
|
* Dec. 14, 2011: Version 0.6.0 released, with support for related URLs and blog name attributes.
|
@@ -22,15 +23,20 @@ Install Times Wire as a gem:
|
|
22
23
|
|
23
24
|
For use in a Rails 3 application, put the following in your Gemfile:
|
24
25
|
|
25
|
-
gem "times_wire", "~> 0.
|
26
|
+
gem "times_wire", "~> 0.9.0"
|
26
27
|
|
27
|
-
then issue the 'bundle install' command. Times Wire has been tested under Ruby 1.8.7.
|
28
|
+
then issue the 'bundle install' command. Times Wire has been tested under Ruby 1.8.7 and 1.9.3.
|
28
29
|
|
29
30
|
== Getting Started
|
30
31
|
|
31
32
|
You'll need an API Key from The New York Times Developer Network (http://developer.nytimes.com/). You can set your key as an environment variable (handy for running the test suite) or set it within a script or app:
|
32
33
|
|
33
34
|
TimesWire::Base.api_key = API_KEY
|
35
|
+
|
36
|
+
To retrieve details for a single URL, pass it in:
|
37
|
+
|
38
|
+
@item = Item.url("http://www.nytimes.com/2013/05/04/business/economy/us-adds-165000-jobs-in-april.html")
|
39
|
+
=> \#<TimesWire::Item:0x1014b2088 @blog_name=nil, @created_date=\#<DateTime: 212234344421/86400,-1/6,2299161>, @byline="By NELSON D. SCHWARTZ", @org_facets="", @section="Business Day", @kicker="", @updated_date=#<DateTime: 13264647209/5400,-1/6,2299161>, @related_urls=nil, @url="http://www.nytimes.com/2013/05/04/business/economy/us-adds-165000-jobs-in-april.html", @des_facets=["Labor and Jobs", "United States Economy"], @material_type_facet="News", @source="The New York Times", @geo_facets="", @abstract="The economy in April added 165,000 jobs, slightly more than expected, and the Labor Department sharply revised upward its estimates for job creation in the previous two months.", @multimedia=[{"height"=>75, "url"=>"http://graphics8.nytimes.com/images/2013/05/04/business/economy/04jobs/04jobs-thumbStandard.jpg", "subtype"=>"photo", "width"=>75, "format"=>"Standard Thumbnail", "copyright"=>"Spencer Platt/Getty Images", "caption"=>"Job candidates waited to meet with employers at a job and internship fair in New York last week.", "type"=>"image"}], @published_date=#<DateTime: 7369250/3,-1/6,2299161>, @per_facets="", @item_type="Article", @title="Jobs Data Ease Fears of Sharp Slowdown in U.S. Economy", @subheadline="">
|
34
40
|
|
35
41
|
Times Wire allows users to retrieve news items by source ('nyt', 'iht' or 'all'), by section (such as 'world', 'u.s.', 'sports') or by NYTimes.com blog names ("The Caucus", "FiveThirtyEight" or "At War", for example). Building a request is easy. To retrieve the latest items from The New York Times:
|
36
42
|
|
data/lib/times_wire/base.rb
CHANGED
@@ -13,6 +13,7 @@ module TimesWire
|
|
13
13
|
@@api_key = nil
|
14
14
|
@@debug = false
|
15
15
|
@@copyright = nil
|
16
|
+
@@semantic_api_key = nil
|
16
17
|
|
17
18
|
# The copyright footer to be placed at the bottom of any data from the New York Times. Note this is only set after an API call.
|
18
19
|
def copyright
|
@@ -29,6 +30,14 @@ module TimesWire
|
|
29
30
|
@@api_key
|
30
31
|
end
|
31
32
|
|
33
|
+
def self.semantic_api_key=(key)
|
34
|
+
@@semantic_api_key = key
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.api_key
|
38
|
+
@@semantic_api_key
|
39
|
+
end
|
40
|
+
|
32
41
|
def self.datetime_parser(datetime)
|
33
42
|
datetime ? DateTime.parse(datetime) : nil
|
34
43
|
end
|
data/lib/times_wire/item.rb
CHANGED
@@ -35,6 +35,12 @@ module TimesWire
|
|
35
35
|
:multimedia => params['multimedia']
|
36
36
|
end
|
37
37
|
|
38
|
+
def self.url(url)
|
39
|
+
reply = Base.invoke('', {'url' => url})
|
40
|
+
return nil unless reply['results'].first
|
41
|
+
Item.create_from_api(reply['results'].first)
|
42
|
+
end
|
43
|
+
|
38
44
|
def self.latest(source="nyt", limit=20)
|
39
45
|
reply = Base.invoke("#{source}/all", {"limit" => limit})
|
40
46
|
results = reply['results']
|
@@ -53,5 +59,10 @@ module TimesWire
|
|
53
59
|
results = reply['results'].select{|i| i['blog_name'] == blog}
|
54
60
|
@items = results.map {|r| Item.create_from_api(r)}
|
55
61
|
end
|
62
|
+
|
63
|
+
def semantic_terms
|
64
|
+
|
65
|
+
end
|
66
|
+
|
56
67
|
end
|
57
68
|
end
|
data/lib/times_wire/version.rb
CHANGED
metadata
CHANGED
@@ -1,47 +1,35 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: times_wire
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 8
|
9
|
-
- 0
|
10
|
-
version: 0.8.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Derek Willis
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-05-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: shoulda
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2152119880 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152119880
|
25
|
+
description: A Ruby library for parsing stories and blog posts from The New York Times
|
26
|
+
Newswire API
|
27
|
+
email:
|
37
28
|
- dwillis@gmail.com
|
38
29
|
executables: []
|
39
|
-
|
40
30
|
extensions: []
|
41
|
-
|
42
31
|
extra_rdoc_files: []
|
43
|
-
|
44
|
-
files:
|
32
|
+
files:
|
45
33
|
- .gitignore
|
46
34
|
- Gemfile
|
47
35
|
- LICENSE
|
@@ -56,41 +44,31 @@ files:
|
|
56
44
|
- test/times_wire/test_item.rb
|
57
45
|
- test/times_wire/test_section.rb
|
58
46
|
- times_wire.gemspec
|
59
|
-
has_rdoc: true
|
60
47
|
homepage: http://rubygems.org/gems/times_wire
|
61
48
|
licenses: []
|
62
|
-
|
63
49
|
post_install_message:
|
64
50
|
rdoc_options: []
|
65
|
-
|
66
|
-
require_paths:
|
51
|
+
require_paths:
|
67
52
|
- lib
|
68
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
54
|
none: false
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
|
75
|
-
- 0
|
76
|
-
version: "0"
|
77
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
60
|
none: false
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
segments:
|
84
|
-
- 0
|
85
|
-
version: "0"
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
86
65
|
requirements: []
|
87
|
-
|
88
66
|
rubyforge_project: times_wire
|
89
|
-
rubygems_version: 1.
|
67
|
+
rubygems_version: 1.8.17
|
90
68
|
signing_key:
|
91
69
|
specification_version: 3
|
92
70
|
summary: A thin client for The New York Times Newswire API
|
93
|
-
test_files:
|
71
|
+
test_files:
|
94
72
|
- test/test_helper.rb
|
95
73
|
- test/times_wire/test_item.rb
|
96
74
|
- test/times_wire/test_section.rb
|