post_haste 1.0 → 1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/post_haste/article.rb +13 -13
- data/lib/post_haste/comment.rb +7 -7
- data/lib/post_haste/version.rb +1 -1
- data/test/post_haste/test_article.rb +11 -11
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 149170b0b2ba322778fbdec9963b070bb8af71ed
|
|
4
|
+
data.tar.gz: a52aa7534b87109a1417d6575a31486c09b99369
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf83597199e73298315263f66c0e23b1da525fd9dc7edb4d3155089284525837fc136a9e945b4f7846a12b1d45a1125ca7e90c4399ff577e73d4037e765eb657
|
|
7
|
+
data.tar.gz: d789bb2dd126b19912ba5de504c8c9cc71eef468ca12da28b928cf1d93298daa0c84ef202f3ec4b22e0fd05d74ef3a58818b3d0eddc728c378abb42dd4691b58
|
data/README.md
CHANGED
|
@@ -22,6 +22,7 @@ Or install it yourself as:
|
|
|
22
22
|
|
|
23
23
|
Post Haste currently can accept a URL of a Washington Post article or blog post, and converts that URL into a Ruby object with a number of methods that describe it, including its title, byline, published and updated datetimes, and more:
|
|
24
24
|
|
|
25
|
+
```ruby
|
|
25
26
|
require 'post_haste'
|
|
26
27
|
include PostHaste
|
|
27
28
|
|
|
@@ -44,6 +45,7 @@ Post Haste currently can accept a URL of a Washington Post article or blog post,
|
|
|
44
45
|
@article.comments.first.permalink(@article)
|
|
45
46
|
|
|
46
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
|
+
```
|
|
47
49
|
|
|
48
50
|
See the full list of `Article` instance methods in article.rb.
|
|
49
51
|
|
data/lib/post_haste/article.rb
CHANGED
|
@@ -5,49 +5,49 @@ require 'json'
|
|
|
5
5
|
module PostHaste
|
|
6
6
|
class Article
|
|
7
7
|
# Represents a single Washington Post story or blog post.
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
attr_reader :uuid, :type, :title, :summary, :mobile_headline, :web_headline, :permalink, :short_url, :keywords, :email, :bio_page,
|
|
10
10
|
:comments_url, :byline, :created_datetime, :published_datetime, :display_datetime, :updated_datetime, :section, :tags, :comments
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
def initialize(params={})
|
|
13
13
|
params.each_pair do |k,v|
|
|
14
14
|
instance_variable_set("@#{k}", v)
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
def self.latest_comments_url(url, limit)
|
|
19
19
|
escaped_uri = URI.escape(url)
|
|
20
|
-
"
|
|
20
|
+
"https://comments-api.ext.nile.works/v1/search?q=((childrenof%3A+#{escaped_uri}+source%3Awashpost.com+(((state%3AUntouched++AND+user.state%3AModeratorApproved)+OR+(state%3ACommunityFlagged%2CModeratorApproved%2CModeratorDeleted+AND+-user.state%3AModeratorBanned%2CModeratorDeleted)+)++AND+(+-markers%3Aignore+)+)+++))+itemsPerPage%3A+15+sortOrder%3AreverseChronological+safeHTML%3Aaggressive+children%3A+2+childrenSortOrder%3Achronological+childrenItemsPerPage%3A3++(((state%3AUntouched++AND+user.state%3AModeratorApproved)+OR+(state%3ACommunityFlagged%2CModeratorApproved+AND+-user.state%3AModeratorBanned%2CModeratorDeleted)+)++AND+(+-markers%3Aignore+)+)+&appkey=prod.washpost.com"
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
def self.parse_latest_comments(article, comments_url)
|
|
24
24
|
results = JSON.parse(open(comments_url).read)
|
|
25
25
|
Comment.create_comments_from_objects(article, results['entries'])
|
|
26
26
|
end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
# comment limit defaults to 15, but can be set higher or lower
|
|
29
29
|
def self.create_from_url(url, comment_limit=15)
|
|
30
30
|
result = parse_json(get_json(url))
|
|
31
31
|
create(result, comment_limit)
|
|
32
32
|
end
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
# Given a Washington Post story or blog url, can turn that url into a JSON API endpoint
|
|
35
35
|
# returns the url and the source used in Article creation
|
|
36
36
|
def self.get_json(url)
|
|
37
|
-
"http://apps-origin.washingtonpost.com/f/story-builder/api/url
|
|
37
|
+
"http://apps-origin.washingtonpost.com/f/story-builder/api/url/?url=#{url}"
|
|
38
38
|
end
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
# parses a Washington Post story or blog JSON response
|
|
41
41
|
def self.parse_json(url)
|
|
42
42
|
JSON.parse(open(url).read)
|
|
43
43
|
end
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
# Post CMS produces unix timestamps, but with extra zeroes
|
|
46
46
|
def self.parse_datetime(seconds)
|
|
47
47
|
seconds = seconds.to_s[0..9]
|
|
48
48
|
Time.at(seconds.to_i).to_datetime
|
|
49
49
|
end
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
# creates an Article object from a JSON response
|
|
52
52
|
# with 25 latest comments, can be configured.
|
|
53
53
|
def self.create(result={}, limit=25)
|
|
@@ -70,7 +70,7 @@ module PostHaste
|
|
|
70
70
|
section: result['kicker']['name'],
|
|
71
71
|
tags: result['tags'],
|
|
72
72
|
comments: parse_latest_comments(result['_id'], latest_comments_url(result['_id'], limit=limit))
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
|
-
end
|
|
76
|
+
end
|
data/lib/post_haste/comment.rb
CHANGED
|
@@ -5,24 +5,24 @@ require 'json'
|
|
|
5
5
|
module PostHaste
|
|
6
6
|
class Comment
|
|
7
7
|
# Represents a comment on a Washington Post story
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
attr_reader :id, :article_url, :author, :content, :status, :published , :permalink
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
def initialize(params={})
|
|
12
12
|
params.each_pair do |k,v|
|
|
13
13
|
instance_variable_set("@#{k}", v)
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
def self.create_comments_from_objects(article_url, comments)
|
|
18
18
|
results = []
|
|
19
19
|
comments.each do |comment|
|
|
20
|
-
c = Comment.new({:id => comment['object']['id']
|
|
20
|
+
c = Comment.new({:id => comment['object']['id'], :article_url => article_url, :author => comment['actor']['title'], :content => comment['object']['content'], :status => comment['object']['status'], :published => DateTime.parse(comment['object']['published'])})
|
|
21
21
|
results << c
|
|
22
22
|
end
|
|
23
23
|
results
|
|
24
24
|
end
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
def permalink(article)
|
|
27
27
|
if article.type == 'BlogStory'
|
|
28
28
|
article_url.gsub('_blog','_comment')+'?commentID='+id
|
|
@@ -32,6 +32,6 @@ module PostHaste
|
|
|
32
32
|
article_url+'?commentID='+id
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
end
|
|
37
|
-
end
|
|
37
|
+
end
|
data/lib/post_haste/version.rb
CHANGED
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
|
2
2
|
|
|
3
3
|
class TestPostHaste::TestArticle < Minitest::Test
|
|
4
4
|
include PostHaste
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
context "Article.create from article" do
|
|
7
7
|
setup do
|
|
8
8
|
url = "http://www.washingtonpost.com/politics/joe-biden-digging-back-into-his-roots-to-move-obama-forward/2012/03/14/gIQARwYBDS_story.html"
|
|
@@ -10,12 +10,12 @@ class TestPostHaste::TestArticle < Minitest::Test
|
|
|
10
10
|
@result = Article.parse_json(json_url)
|
|
11
11
|
@article = Article.create(@result)
|
|
12
12
|
end
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
should "return an object of the Article type" do
|
|
15
15
|
assert_kind_of(Article, @article)
|
|
16
16
|
assert_equal(@article.type, 'article')
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
%w(uuid type title summary).each do |attr|
|
|
20
20
|
should "assign the value of the @#{attr} attribute from the '#{attr}' key in the hash" do
|
|
21
21
|
assert_equal(@result[attr], @article.send(attr))
|
|
@@ -30,19 +30,19 @@ class TestPostHaste::TestArticle < Minitest::Test
|
|
|
30
30
|
@result = Article.parse_json(json_url)
|
|
31
31
|
@article = Article.create(@result)
|
|
32
32
|
end
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
should "return an object of the Article type" do
|
|
35
35
|
assert_kind_of(Article, @article)
|
|
36
|
-
assert_equal(@article.type, '
|
|
36
|
+
assert_equal(@article.type, 'BlogStory')
|
|
37
37
|
end
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
%w(uuid type title summary).each do |attr|
|
|
40
40
|
should "assign the value of the @#{attr} attribute from the '#{attr}' key in the hash" do
|
|
41
41
|
assert_equal(@result[attr], @article.send(attr))
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
context "Article.create from Wordpress blog post" do
|
|
47
47
|
setup do
|
|
48
48
|
url = "http://www.washingtonpost.com/blogs/wonkblog/wp/2013/01/18/breaking-inside-the-feds-2007-crisis-response/"
|
|
@@ -50,13 +50,13 @@ class TestPostHaste::TestArticle < Minitest::Test
|
|
|
50
50
|
@result = Article.parse_json(json_url)
|
|
51
51
|
@article = Article.create(@result)
|
|
52
52
|
end
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
should "return an object of the Article type" do
|
|
55
55
|
assert_kind_of(Article, @article)
|
|
56
56
|
assert_equal(@article.type, 'blog')
|
|
57
57
|
end
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
|
|
60
60
|
end
|
|
61
|
-
|
|
62
|
-
end
|
|
61
|
+
|
|
62
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: post_haste
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.1'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Derek Willis
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2015-07-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
133
133
|
version: 1.3.6
|
|
134
134
|
requirements: []
|
|
135
135
|
rubyforge_project: post_haste
|
|
136
|
-
rubygems_version: 2.
|
|
136
|
+
rubygems_version: 2.4.5
|
|
137
137
|
signing_key:
|
|
138
138
|
specification_version: 4
|
|
139
139
|
summary: Because it was there.
|