NYTimesAPI 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/NYTimesAPI.gemspec +25 -0
- data/README.md +47 -0
- data/Rakefile +12 -0
- data/keys.txt +17 -0
- data/lib/NYTimesAPI.rb +24 -0
- data/lib/NYTimesAPI/article_search.rb +8 -0
- data/lib/NYTimesAPI/best_sellers.rb +4 -0
- data/lib/NYTimesAPI/campaign_finance.rb +4 -0
- data/lib/NYTimesAPI/community.rb +4 -0
- data/lib/NYTimesAPI/congress.rb +4 -0
- data/lib/NYTimesAPI/districts.rb +4 -0
- data/lib/NYTimesAPI/event_listings.rb +4 -0
- data/lib/NYTimesAPI/geographic.rb +4 -0
- data/lib/NYTimesAPI/most_popular.rb +4 -0
- data/lib/NYTimesAPI/movie_reviews.rb +4 -0
- data/lib/NYTimesAPI/real_state.rb +139 -0
- data/lib/NYTimesAPI/semantic.rb +4 -0
- data/lib/NYTimesAPI/times_newswire.rb +4 -0
- data/lib/NYTimesAPI/timestags.rb +5 -0
- data/lib/NYTimesAPI/util.rb +13 -0
- data/lib/NYTimesAPI/version.rb +3 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 405f2fa0106b658c3eec12e0c443a403bb6ad4b7
|
4
|
+
data.tar.gz: 8fbd4a9935ce0f84c1b6efbad34e522c402eda37
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2667bd028d1fd86c9051f33971cdc43bed5d71c9828a1f572de38596175c797ab84e13e840a41895dfcd997383b80f2908dd0b79f42f5c697a7cb99f603b3b4c
|
7
|
+
data.tar.gz: 5458b8ad734977fdbec19512425e4c336e37f0b49ba6c792b7faff5430d8fb9163be17786a1ad726554bc375c43ecf3d4e98a55092c8dd755f4655a839e88694
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Rodrigo Alves
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/NYTimesAPI.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'NYTimesAPI/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "NYTimesAPI"
|
9
|
+
spec.version = NYTimesAPI::VERSION
|
10
|
+
spec.authors = ["Rodrigo Alves"]
|
11
|
+
spec.email = ["rodrigovieira1994@gmail.com"]
|
12
|
+
spec.summary = %q{The New York Times API}
|
13
|
+
spec.description = %q{The New York Times API wrapper}
|
14
|
+
spec.homepage = "https://github.com/rodrigoalvesvieira/NYTimesAPI"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = Dir["{lib/**/*,spec/*}"] + Dir.entries(".").select { |f| File.file?(f) }.reverse[0..6] - ["NYTimesAPI-0.0.1.gem"]
|
18
|
+
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# NYTimesAPI
|
2
|
+
|
3
|
+
Ruby wrapper for The New York Times API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'NYTimesAPI'
|
11
|
+
```
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
```shell
|
16
|
+
$ gem install NYTimesAPI
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Real State API
|
22
|
+
|
23
|
+
First initialize the object, using your api key:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
ny = NYTimesAPI::RealState.new "myawesomapikey"
|
27
|
+
```
|
28
|
+
|
29
|
+
###### Count
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
result = ny.counts "Manhattan", {date: "2007-07", bedrooms: 2, type: 3}
|
33
|
+
```
|
34
|
+
|
35
|
+
###### Percentiles
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
result = ny.percentiles "Manhattan", {date: "2007-07", bedrooms: 2, type: 3}
|
39
|
+
```
|
40
|
+
|
41
|
+
## Author
|
42
|
+
|
43
|
+
* Rodrigo Alves <rodrigovieira1994@gmail.com>
|
44
|
+
|
45
|
+
## Copyright
|
46
|
+
|
47
|
+
© 2014 Rodrigo Alves
|
data/Rakefile
ADDED
data/keys.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
keys
|
2
|
+
|
3
|
+
Article Search API key: 03c313e0c9d4f06be219c2208077a316:10:69806191
|
4
|
+
Real Estate API key: f17b219b0e058af6865859ca4d16c2a0:6:69806191
|
5
|
+
Movie Reviews API key: 4a81cec4dbc2aa11cbb40cd1f2658b7a:11:69806191
|
6
|
+
Most Popular API key: 3472b490fb7b58f6fd13bec0aa59f47e:9:69806191
|
7
|
+
Geo API key: adc2e189e41ec0e77b1e88e0330864d0:17:69806191
|
8
|
+
Event Listings API key: cab9ae8f0a7da535aa4eb87818a0a458:2:69806191
|
9
|
+
Districts API key: 241055ba40d37493ca89e9c7d5921743:8:69806191
|
10
|
+
Congress API key: c3f176bcf5d5c36095b4953c1aed75ec:19:69806191
|
11
|
+
Community API key: 450c852f37e40f3136ecb111fe12af82:18:69806191
|
12
|
+
Campaign Finance API key: 46bb03b7f99f49f4a74a871eaf25b123:13:69806191
|
13
|
+
Best Sellers API key: c3f93ac81cb1100af5af1c37aeafc817:17:69806191
|
14
|
+
Article Search API key: 03c313e0c9d4f06be219c2208077a316:10:69806191
|
15
|
+
Semantic API key: f4fc80edc884b5bb3a1a46e09623bea0:13:69806191
|
16
|
+
Times Newswire API key: ccc07679e9f238354059b44e2a682ed1:3:69806191
|
17
|
+
TimesTags API key: 73b55c2fac1c383dd2a2365e5b3c5350:11:69806191
|
data/lib/NYTimesAPI.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "net/http"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
require "NYTimesAPI/version"
|
6
|
+
|
7
|
+
module NYTimesAPI
|
8
|
+
autoload :Util, "NYTimesAPI/util"
|
9
|
+
|
10
|
+
autoload :ArticleSearch, "NYTimesAPI/article_search"
|
11
|
+
autoload :BestSellers, "NYTimesAPI/best_sellers"
|
12
|
+
autoload :CampaignFinance, "NYTimesAPI/campaign_finance"
|
13
|
+
autoload :Community, "NYTimesAPI/community"
|
14
|
+
autoload :Congress, "NYTimesAPI/congress"
|
15
|
+
autoload :Districts, "NYTimesAPI/districts"
|
16
|
+
autoload :EventListings, "NYTimesAPI/event_listings"
|
17
|
+
autoload :Geographic, "NYTimesAPI/geographic"
|
18
|
+
autoload :MostPopular, "NYTimesAPI/most_popular"
|
19
|
+
autoload :MovieReviews, "NYTimesAPI/movie_reviews"
|
20
|
+
autoload :RealState, "NYTimesAPI/real_state"
|
21
|
+
autoload :Semantic, "NYTimesAPI/semantic"
|
22
|
+
autoload :TimesNewswire, "NYTimesAPI/times_newswire"
|
23
|
+
autoload :Timestags, " NYTimesAPI/timestags"
|
24
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module NYTimesAPI
|
2
|
+
class RealState
|
3
|
+
API_VERSION = "v2"
|
4
|
+
BASE_URL = "http://api.nytimes.com/svc/real-estate/#{API_VERSION}/listings/percentile/50.json?geo-extent-level=borough&"
|
5
|
+
|
6
|
+
SUCCESS = "OK"
|
7
|
+
|
8
|
+
GEO_SUMMARY_LEVELS = %w(borough neighborhood zip)
|
9
|
+
|
10
|
+
BUILDING_TYPES = {
|
11
|
+
"Apartments" => 2
|
12
|
+
}
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def enable_url_for(resource_type, query_type)
|
16
|
+
return "http://api.nytimes.com/svc/real-estate/#{API_VERSION}/#{resource_type}/#{query_type}/50.json?geo-extent-level=borough&"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_accessor :api_key, :requests_count
|
21
|
+
|
22
|
+
def initialize(api_key)
|
23
|
+
@api_key = api_key
|
24
|
+
@requests_count = 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def counts(location, options)
|
28
|
+
base_url = RealState.enable_url_for("listings", "count")
|
29
|
+
|
30
|
+
geo_summary_level = options[:geo_summary_level] || GEO_SUMMARY_LEVELS.first
|
31
|
+
url = "#{base_url}geo-extent-value=#{location}&geo-summary-level=#{geo_summary_level}&date-range=#{options[:date]}&bedrooms=#{options[:bedrooms]}&building-type-id=#{options[:type]}&api-key=#{self.api_key}"
|
32
|
+
|
33
|
+
json = NYTimesAPI::Util.get_json(url)
|
34
|
+
self.requests_count += 1
|
35
|
+
|
36
|
+
results = []
|
37
|
+
|
38
|
+
if json["status"] == SUCCESS
|
39
|
+
json["results"].each do |res|
|
40
|
+
|
41
|
+
result_item = {
|
42
|
+
borough: res["borough"],
|
43
|
+
date_format: res["date_format"],
|
44
|
+
date: res["date"],
|
45
|
+
count: res["count"]
|
46
|
+
}
|
47
|
+
|
48
|
+
results.push result_item
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
return results
|
53
|
+
end
|
54
|
+
|
55
|
+
def percentiles(location, options={})
|
56
|
+
base_url = RealState.enable_url_for("listings", "percentile")
|
57
|
+
|
58
|
+
url = "#{base_url}geo-extent-value=#{location}&date-range=#{options[:date]}&bedrooms=#{options[:bedrooms]}&building-type-id=#{options[:type]}&api-key=#{self.api_key}"
|
59
|
+
json = NYTimesAPI::Util.get_json(url)
|
60
|
+
self.requests_count += 1
|
61
|
+
|
62
|
+
results = []
|
63
|
+
|
64
|
+
if json["status"] == SUCCESS
|
65
|
+
json["results"].each do |res|
|
66
|
+
|
67
|
+
result_item = {
|
68
|
+
borough: res["borough"],
|
69
|
+
date_format: res["date_format"],
|
70
|
+
date: res["date"],
|
71
|
+
percentile: res["percentile"],
|
72
|
+
listing_price: res["listing_price"]
|
73
|
+
}
|
74
|
+
|
75
|
+
results.push result_item
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
return results
|
80
|
+
end
|
81
|
+
|
82
|
+
def sales_percentiles(location, options={})
|
83
|
+
base_url = RealState.enable_url_for("sales", "percentile")
|
84
|
+
|
85
|
+
geo_summary_level = options[:geo_summary_level] || GEO_SUMMARY_LEVELS.first
|
86
|
+
url = "#{base_url}geo-extent-value=#{location}&geo-summary-level=#{geo_summary_level}&date-range=#{options[:date]}&bedrooms=#{options[:bedrooms]}&building-type-id=#{options[:type]}&api-key=#{self.api_key}"
|
87
|
+
|
88
|
+
json = NYTimesAPI::Util.get_json(url)
|
89
|
+
self.requests_count += 1
|
90
|
+
|
91
|
+
results = []
|
92
|
+
|
93
|
+
if json["status"] == SUCCESS
|
94
|
+
json["results"].each do |res|
|
95
|
+
|
96
|
+
result_item = {
|
97
|
+
zip: res["zip"],
|
98
|
+
date_format: res["date_format"],
|
99
|
+
date: res["date"],
|
100
|
+
percentile: res["percentile"],
|
101
|
+
sale_price: res["sale_price"]
|
102
|
+
}
|
103
|
+
|
104
|
+
results.push result_item
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
return results
|
109
|
+
end
|
110
|
+
|
111
|
+
def sales_counts(location, options={})
|
112
|
+
base_url = RealState.enable_url_for("sales", "count")
|
113
|
+
|
114
|
+
geo_summary_level = options[:geo_summary_level] || GEO_SUMMARY_LEVELS.first
|
115
|
+
url = "#{base_url}geo-extent-value=#{location}&geo-summary-level=#{geo_summary_level}&date-range=#{options[:date]}&bedrooms=#{options[:bedrooms]}&building-type-id=#{options[:type]}&api-key=#{self.api_key}"
|
116
|
+
|
117
|
+
json = NYTimesAPI::Util.get_json(url)
|
118
|
+
self.requests_count += 1
|
119
|
+
|
120
|
+
results = []
|
121
|
+
|
122
|
+
if json["status"] == SUCCESS
|
123
|
+
json["results"].each do |res|
|
124
|
+
|
125
|
+
result_item = {
|
126
|
+
neighborhood: res["neighborhood"],
|
127
|
+
date_format: res["date_format"],
|
128
|
+
date: res["date"],
|
129
|
+
count: res["count"]
|
130
|
+
}
|
131
|
+
|
132
|
+
results.push result_item
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
return results
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: NYTimesAPI
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodrigo Alves
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: The New York Times API wrapper
|
42
|
+
email:
|
43
|
+
- rodrigovieira1994@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE.txt
|
50
|
+
- NYTimesAPI.gemspec
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- keys.txt
|
54
|
+
- lib/NYTimesAPI.rb
|
55
|
+
- lib/NYTimesAPI/article_search.rb
|
56
|
+
- lib/NYTimesAPI/best_sellers.rb
|
57
|
+
- lib/NYTimesAPI/campaign_finance.rb
|
58
|
+
- lib/NYTimesAPI/community.rb
|
59
|
+
- lib/NYTimesAPI/congress.rb
|
60
|
+
- lib/NYTimesAPI/districts.rb
|
61
|
+
- lib/NYTimesAPI/event_listings.rb
|
62
|
+
- lib/NYTimesAPI/geographic.rb
|
63
|
+
- lib/NYTimesAPI/most_popular.rb
|
64
|
+
- lib/NYTimesAPI/movie_reviews.rb
|
65
|
+
- lib/NYTimesAPI/real_state.rb
|
66
|
+
- lib/NYTimesAPI/semantic.rb
|
67
|
+
- lib/NYTimesAPI/times_newswire.rb
|
68
|
+
- lib/NYTimesAPI/timestags.rb
|
69
|
+
- lib/NYTimesAPI/util.rb
|
70
|
+
- lib/NYTimesAPI/version.rb
|
71
|
+
homepage: https://github.com/rodrigoalvesvieira/NYTimesAPI
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.2.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: The New York Times API
|
95
|
+
test_files: []
|