post_haste 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +22 -15
- data/README.md +17 -6
- data/lib/post_haste/article.rb +3 -6
- data/lib/post_haste/comment.rb +0 -4
- data/lib/post_haste/most_viewed.rb +39 -0
- data/lib/post_haste/version.rb +1 -1
- data/lib/post_haste.rb +4 -2
- data/post_haste.gemspec +4 -4
- data/test/post_haste/test_article.rb +9 -9
- data/test/post_haste/test_most_viewed.rb +29 -0
- data/test/test_helper.rb +0 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96a4c2886f29d057214ecfc3da0d93f0861c47f7
|
4
|
+
data.tar.gz: 1896ee276a2cb6a7ea8b478fbdee3711fa609113
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d1b91668bf311423b2b17fa6e45ea31e79e5bbf2583a2f7cbb3c7dfab2eec019198af93449ab9fb36204be0e700aa91fc8871204378ac4288a567e0a6b2da82
|
7
|
+
data.tar.gz: a3fc91fb097dd0791ce2b7e7afff2a9f30ec6f99d44007fa247f8304cc2ef1df7715d3b8f73ca0e2aba367c2e5d43d88f56664c5d270862ef798e9b10deb1acd
|
data/Gemfile.lock
CHANGED
@@ -1,34 +1,38 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
post_haste (1.
|
5
|
-
|
4
|
+
post_haste (1.1)
|
5
|
+
httparty
|
6
6
|
nokogiri
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (4.
|
12
|
-
i18n (~> 0.
|
11
|
+
activesupport (4.2.4)
|
12
|
+
i18n (~> 0.7)
|
13
13
|
json (~> 1.7, >= 1.7.7)
|
14
14
|
minitest (~> 5.1)
|
15
|
-
thread_safe (~> 0.
|
15
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
16
16
|
tzinfo (~> 1.1)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
httparty (0.13.5)
|
18
|
+
json (~> 1.8)
|
19
|
+
multi_xml (>= 0.5.2)
|
20
|
+
i18n (0.7.0)
|
21
|
+
json (1.8.3)
|
22
|
+
mini_portile (0.6.2)
|
23
|
+
minitest (5.8.0)
|
24
|
+
multi_xml (0.5.5)
|
25
|
+
nokogiri (1.6.6.2)
|
26
|
+
mini_portile (~> 0.6.0)
|
27
|
+
rake (10.3.2)
|
24
28
|
shoulda (3.5.0)
|
25
29
|
shoulda-context (~> 1.0, >= 1.0.1)
|
26
30
|
shoulda-matchers (>= 1.4.1, < 3.0)
|
27
31
|
shoulda-context (1.2.1)
|
28
|
-
shoulda-matchers (2.
|
32
|
+
shoulda-matchers (2.8.0)
|
29
33
|
activesupport (>= 3.0.0)
|
30
|
-
thread_safe (0.3.
|
31
|
-
tzinfo (1.
|
34
|
+
thread_safe (0.3.5)
|
35
|
+
tzinfo (1.2.2)
|
32
36
|
thread_safe (~> 0.1)
|
33
37
|
|
34
38
|
PLATFORMS
|
@@ -40,3 +44,6 @@ DEPENDENCIES
|
|
40
44
|
post_haste!
|
41
45
|
rake (~> 10.3.1)
|
42
46
|
shoulda
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
1.10.5
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# PostHaste
|
2
2
|
|
3
|
-
A Ruby library that wraps the JSON endpoints provided for Washington Post articles and blog posts. Potentially suitable for building custom feeds of Washington Post content, in the event that you don't want to actually visit washingtonpost.com. It handles articles and blog posts from the Post's CMS (along with the most recent 15 comments), as well as The Post's WordPress-powered blogs.
|
3
|
+
A Ruby library that wraps the JSON endpoints provided for Washington Post articles and blog posts. Potentially suitable for building custom feeds of Washington Post content, in the event that you don't want to actually visit washingtonpost.com. It handles articles and blog posts from the Post's CMS (along with the most recent 15 comments), as well as The Post's WordPress-powered blogs. Post Haste also provides a wrapper to "Most Viewed" articles and blog posts.
|
4
4
|
|
5
|
-
Tested under Ruby 1.9.3, 2.0.0
|
5
|
+
Tested under Ruby 1.9.3, 2.0.0, 2.1.0 and 2.2.x.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -37,18 +37,29 @@ Post Haste currently can accept a URL of a Washington Post article or blog post,
|
|
37
37
|
@article.display_datetime.to_s
|
38
38
|
|
39
39
|
=> "2012-03-16T06:30:00-04:00"
|
40
|
-
|
40
|
+
|
41
41
|
@article.comments.first.author
|
42
42
|
|
43
43
|
=> "iseasygoing"
|
44
|
-
|
44
|
+
|
45
45
|
@article.comments.first.permalink(@article)
|
46
|
-
|
46
|
+
|
47
47
|
=> "http://www.washingtonpost.com/blogs/the-fix/post/republicans-on-the-2012-gop-field-blah/2012/03/15/gIQAT7CSFS_comment.html?commentID=washingtonpost.com/ECHO/item/1332046095-915-174"
|
48
48
|
```
|
49
|
-
|
49
|
+
|
50
50
|
See the full list of `Article` instance methods in article.rb.
|
51
51
|
|
52
|
+
For a listing of Most Viewed articles and blog posts at the time of the request:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require 'post_haste'
|
56
|
+
include PostHaste
|
57
|
+
|
58
|
+
mv = MostViewed.all
|
59
|
+
mv.first
|
60
|
+
=> <PostHaste::MostViewed:0x007fb4e5066138 @platform="web", @type="all", @datetime=#<DateTime: 2015-09-16T17:02:00-04:00 ((2457282j,75720s,0n),-14400s,2299161j)>, @title="Boehner and his allies prepare fall battle with conservative GOP critics", @byline="Paul Kane", @url="http://www.washingtonpost.com/politics/boehner-and-his-allies-prepare-fall-battle-with-conservative-gop-critics/2015/09/15/be7b23dc-5bab-11e5-8e9e-dce8a2a2a679_story.html?tid=pm_pop", @rank=1>
|
61
|
+
```
|
62
|
+
|
52
63
|
## In the Wild
|
53
64
|
|
54
65
|
See an example application at http://postcomments.herokuapp.com/
|
data/lib/post_haste/article.rb
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'uri'
|
3
|
-
require 'json'
|
4
|
-
|
5
1
|
module PostHaste
|
6
2
|
class Article
|
7
3
|
# Represents a single Washington Post story or blog post.
|
@@ -21,12 +17,13 @@ module PostHaste
|
|
21
17
|
end
|
22
18
|
|
23
19
|
def self.parse_latest_comments(article, comments_url)
|
24
|
-
results =
|
20
|
+
results = HTTParty.get(comments_url).parsed_response
|
25
21
|
Comment.create_comments_from_objects(article, results['entries'])
|
26
22
|
end
|
27
23
|
|
28
24
|
# comment limit defaults to 15, but can be set higher or lower
|
29
25
|
def self.create_from_url(url, comment_limit=15)
|
26
|
+
url.gsub('/blogs/','/news/') if url.include?('/blogs/')
|
30
27
|
result = parse_json(get_json(url))
|
31
28
|
create(result, comment_limit)
|
32
29
|
end
|
@@ -39,7 +36,7 @@ module PostHaste
|
|
39
36
|
|
40
37
|
# parses a Washington Post story or blog JSON response
|
41
38
|
def self.parse_json(url)
|
42
|
-
|
39
|
+
HTTParty.get(url).parsed_response
|
43
40
|
end
|
44
41
|
|
45
42
|
# Post CMS produces unix timestamps, but with extra zeroes
|
data/lib/post_haste/comment.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
module PostHaste
|
2
|
+
class MostViewed
|
3
|
+
|
4
|
+
attr_reader :platform, :datetime, :title, :byline, :url, :rank, :type
|
5
|
+
|
6
|
+
def initialize(params={})
|
7
|
+
params.each_pair do |k,v|
|
8
|
+
instance_variable_set("@#{k}", v)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all(platform='web', limit=25)
|
13
|
+
url = "http://js.washingtonpost.com/most-viewed/#{platform}/article,blog.feed-#{limit}.json"
|
14
|
+
create(HTTParty.get(url).parsed_response, platform, 'all')
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.articles(platform='web', limit=25)
|
18
|
+
url = "http://js.washingtonpost.com/most-viewed/#{platform}/article.feed-#{limit}.json"
|
19
|
+
create(HTTParty.get(url).parsed_response, platform, 'articles')
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.blogs(platform='web', limit=25)
|
23
|
+
url = "http://js.washingtonpost.com/most-viewed/#{platform}/blog.feed-#{limit}.json"
|
24
|
+
create(HTTParty.get(url).parsed_response, platform, 'blogs')
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.create(result={}, platform, type)
|
28
|
+
result['content'].map!.with_index {|r,i|
|
29
|
+
self.new platform: platform,
|
30
|
+
type: type,
|
31
|
+
datetime: DateTime.parse(result['updated']),
|
32
|
+
title: r['linkText'],
|
33
|
+
byline: r['byline'],
|
34
|
+
url: r['url'],
|
35
|
+
rank: i+1
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/post_haste/version.rb
CHANGED
data/lib/post_haste.rb
CHANGED
data/post_haste.gemspec
CHANGED
@@ -14,15 +14,15 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.name = "post_haste"
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = PostHaste::VERSION
|
17
|
-
|
17
|
+
|
18
18
|
gem.required_rubygems_version = ">= 1.3.6"
|
19
19
|
gem.rubyforge_project = "post_haste"
|
20
|
-
gem.add_runtime_dependency "
|
20
|
+
gem.add_runtime_dependency "httparty"
|
21
21
|
gem.add_runtime_dependency "nokogiri"
|
22
|
-
|
22
|
+
|
23
23
|
gem.add_development_dependency "rake", '~> 10.3.1'
|
24
24
|
gem.add_development_dependency "bundler"
|
25
25
|
gem.add_development_dependency "shoulda"
|
26
26
|
gem.add_development_dependency "minitest"
|
27
|
-
|
27
|
+
|
28
28
|
end
|
@@ -5,9 +5,9 @@ class TestPostHaste::TestArticle < Minitest::Test
|
|
5
5
|
|
6
6
|
context "Article.create from article" do
|
7
7
|
setup do
|
8
|
-
url = "http://www.washingtonpost.com/politics/joe-biden-digging-back-into-his-roots-to-move-obama-forward/2012/03/14/gIQARwYBDS_story.html"
|
9
|
-
json_url = Article.get_json(url)
|
10
|
-
@result = Article.parse_json(json_url)
|
8
|
+
@url = "http://www.washingtonpost.com/politics/joe-biden-digging-back-into-his-roots-to-move-obama-forward/2012/03/14/gIQARwYBDS_story.html"
|
9
|
+
@json_url = Article.get_json(@url)
|
10
|
+
@result = Article.parse_json(@json_url)
|
11
11
|
@article = Article.create(@result)
|
12
12
|
end
|
13
13
|
|
@@ -25,9 +25,9 @@ class TestPostHaste::TestArticle < Minitest::Test
|
|
25
25
|
|
26
26
|
context "Article.create from blog post" do
|
27
27
|
setup do
|
28
|
-
url = "http://www.washingtonpost.com/blogs/the-fix/post/republicans-on-the-2012-gop-field-blah/2012/03/15/gIQAT7CSFS_blog.html"
|
29
|
-
json_url = Article.get_json(url)
|
30
|
-
@result = Article.parse_json(json_url)
|
28
|
+
@url = "http://www.washingtonpost.com/blogs/the-fix/post/republicans-on-the-2012-gop-field-blah/2012/03/15/gIQAT7CSFS_blog.html"
|
29
|
+
@json_url = Article.get_json(@url)
|
30
|
+
@result = Article.parse_json(@json_url)
|
31
31
|
@article = Article.create(@result)
|
32
32
|
end
|
33
33
|
|
@@ -45,9 +45,9 @@ class TestPostHaste::TestArticle < Minitest::Test
|
|
45
45
|
|
46
46
|
context "Article.create from Wordpress blog post" do
|
47
47
|
setup do
|
48
|
-
url = "http://www.washingtonpost.com/blogs/wonkblog/wp/2013/01/18/breaking-inside-the-feds-2007-crisis-response
|
49
|
-
json_url = Article.get_json(url)
|
50
|
-
@result = Article.parse_json(json_url)
|
48
|
+
@url = "http://www.washingtonpost.com/blogs/wonkblog/wp/2013/01/18/breaking-inside-the-feds-2007-crisis-response"
|
49
|
+
@json_url = Article.get_json(@url)
|
50
|
+
@result = Article.parse_json(@json_url)
|
51
51
|
@article = Article.create(@result)
|
52
52
|
end
|
53
53
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestPostHaste::TestMostViewed < Minitest::Test
|
4
|
+
include PostHaste
|
5
|
+
|
6
|
+
context "MostViewed.create from articles on web" do
|
7
|
+
setup do
|
8
|
+
@mv = MostViewed.articles
|
9
|
+
end
|
10
|
+
|
11
|
+
should "return an object of the Article type" do
|
12
|
+
assert_equal(@mv.size, 25)
|
13
|
+
assert_kind_of(MostViewed, @mv.first)
|
14
|
+
assert_equal(@mv.first.platform, 'web')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "MostViewed.create from blogs on mobile" do
|
19
|
+
setup do
|
20
|
+
@mv = MostViewed.blogs('mobile', 5)
|
21
|
+
end
|
22
|
+
|
23
|
+
should "return an object of the Article type" do
|
24
|
+
assert_kind_of(MostViewed, @mv.first)
|
25
|
+
assert_equal(@mv.first.platform, 'mobile')
|
26
|
+
assert_equal(@mv.size, 5)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: post_haste
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Willis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -110,9 +110,11 @@ files:
|
|
110
110
|
- lib/post_haste.rb
|
111
111
|
- lib/post_haste/article.rb
|
112
112
|
- lib/post_haste/comment.rb
|
113
|
+
- lib/post_haste/most_viewed.rb
|
113
114
|
- lib/post_haste/version.rb
|
114
115
|
- post_haste.gemspec
|
115
116
|
- test/post_haste/test_article.rb
|
117
|
+
- test/post_haste/test_most_viewed.rb
|
116
118
|
- test/test_helper.rb
|
117
119
|
homepage: ''
|
118
120
|
licenses: []
|
@@ -139,4 +141,6 @@ specification_version: 4
|
|
139
141
|
summary: Because it was there.
|
140
142
|
test_files:
|
141
143
|
- test/post_haste/test_article.rb
|
144
|
+
- test/post_haste/test_most_viewed.rb
|
142
145
|
- test/test_helper.rb
|
146
|
+
has_rdoc:
|