post_haste 0.1 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +37 -0
- data/LICENSE +1 -1
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/post_haste/article.rb +48 -7
- data/lib/post_haste/version.rb +1 -1
- data/lib/post_haste.rb +1 -1
- data/test/post_haste/test_article.rb +19 -2
- data/test/test_helper.rb +3 -3
- metadata +36 -15
- data/lib/post_haste/feed.rb +0 -9
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
post_haste (0.5)
|
5
|
+
json
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (3.2.11)
|
11
|
+
i18n (~> 0.6)
|
12
|
+
multi_json (~> 1.0)
|
13
|
+
bourne (1.1.2)
|
14
|
+
mocha (= 0.10.5)
|
15
|
+
i18n (0.6.1)
|
16
|
+
json (1.7.6)
|
17
|
+
metaclass (0.0.1)
|
18
|
+
mocha (0.10.5)
|
19
|
+
metaclass (~> 0.0.1)
|
20
|
+
multi_json (1.5.0)
|
21
|
+
rake (0.8.7)
|
22
|
+
shoulda (3.3.2)
|
23
|
+
shoulda-context (~> 1.0.1)
|
24
|
+
shoulda-matchers (~> 1.4.1)
|
25
|
+
shoulda-context (1.0.2)
|
26
|
+
shoulda-matchers (1.4.2)
|
27
|
+
activesupport (>= 3.0.0)
|
28
|
+
bourne (~> 1.1.2)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (>= 1.1.0)
|
35
|
+
post_haste!
|
36
|
+
rake (= 0.8.7)
|
37
|
+
shoulda
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# PostHaste
|
2
2
|
|
3
|
-
A
|
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, as well as WordPress-powered blogs, which have slightly different output.
|
4
4
|
|
5
|
-
Tested under Ruby 1.9.2
|
5
|
+
Tested under Ruby 1.9.2 & 1.9.3.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
data/Rakefile
CHANGED
data/lib/post_haste/article.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'open-uri'
|
3
|
-
require 'date'
|
4
2
|
require 'json'
|
5
3
|
|
6
|
-
# Represents a single Washington Post story or blog post.
|
7
4
|
module PostHaste
|
8
5
|
class Article
|
6
|
+
# Represents a single Washington Post story or blog post.
|
9
7
|
|
10
8
|
attr_reader :uuid, :type, :title, :blurb, :has_correction, :correction, :has_clarification, :clarification, :permalink, :short_url, :email_url,
|
11
9
|
:comments_url, :graphic_url, :video_url, :byline, :organization, :credits, :created_datetime, :published_datetime, :display_datetime, :updated_datetime,
|
@@ -18,15 +16,21 @@ module PostHaste
|
|
18
16
|
end
|
19
17
|
|
20
18
|
def self.create_from_url(url)
|
21
|
-
json_url = get_json(url)
|
19
|
+
json_url, source = get_json(url)
|
22
20
|
result = parse_json(json_url)
|
23
|
-
|
21
|
+
create_from_source(source, result)
|
24
22
|
end
|
25
23
|
|
26
24
|
# Given a Washington Post story or blog url, can turn that url into a JSON API endpoint
|
25
|
+
# returns the url and a source (cms or wordpress) used in Article creation
|
27
26
|
def self.get_json(url)
|
28
|
-
|
29
|
-
|
27
|
+
if url.include?('/wp/')
|
28
|
+
[url+'?json=1', 'wordpress']
|
29
|
+
elsif url.include?("_story")
|
30
|
+
[url.gsub('_story','_json'), 'cms']
|
31
|
+
elsif url.include?("_blog")
|
32
|
+
[url.gsub('_blog','_json'), 'cms']
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
36
|
# parses a Washington Post story or blog JSON response
|
@@ -40,6 +44,14 @@ module PostHaste
|
|
40
44
|
Time.at(seconds.to_i).to_datetime
|
41
45
|
end
|
42
46
|
|
47
|
+
def self.create_from_source(source, result)
|
48
|
+
if source == 'cms'
|
49
|
+
create(result)
|
50
|
+
elsif source == 'wordpress'
|
51
|
+
create_from_wordpress(result)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
43
55
|
# creates an Article object from a JSON response
|
44
56
|
def self.create(params={})
|
45
57
|
self.new :type => params['contentConfig']['type'],
|
@@ -68,5 +80,34 @@ module PostHaste
|
|
68
80
|
|
69
81
|
|
70
82
|
end
|
83
|
+
|
84
|
+
# creates an Article object from a WordPress JSON response
|
85
|
+
def self.create_from_wordpress(params={})
|
86
|
+
self.new :type => params['post']['type'],
|
87
|
+
:uuid => params['post']['id'],
|
88
|
+
:title => params['post']['title'],
|
89
|
+
:blurb => params['post']['excerpt'],
|
90
|
+
:has_correction => nil,
|
91
|
+
:correction => nil,
|
92
|
+
:has_clarification => nil,
|
93
|
+
:clarification => nil,
|
94
|
+
:permalink => params['post']['url'],
|
95
|
+
:short_url => nil,
|
96
|
+
:email_url => nil,
|
97
|
+
:comments_url => params['post']['url'],
|
98
|
+
:graphic_url => nil,
|
99
|
+
:video_url => nil,
|
100
|
+
:byline => params['post']['author']['name'],
|
101
|
+
:organization => nil,
|
102
|
+
:credits => nil,
|
103
|
+
:created_datetime => parse_datetime(params['post']['date']),
|
104
|
+
:published_datetime => parse_datetime(params['post']['date']),
|
105
|
+
:display_datetime => parse_datetime(params['post']['modified']),
|
106
|
+
:updated_datetime => parse_datetime(params['post']['modified']),
|
107
|
+
:section => nil,
|
108
|
+
:tags => params['post']['tags']
|
109
|
+
|
110
|
+
end
|
111
|
+
|
71
112
|
end
|
72
113
|
end
|
data/lib/post_haste/version.rb
CHANGED
data/lib/post_haste.rb
CHANGED
@@ -6,7 +6,7 @@ class TestPostHaste::TestArticle < Test::Unit::TestCase
|
|
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"
|
9
|
-
json_url = Article.get_json(url)
|
9
|
+
json_url, source = Article.get_json(url)
|
10
10
|
@result = Article.parse_json(json_url)
|
11
11
|
@article = Article.create(@result)
|
12
12
|
end
|
@@ -26,7 +26,7 @@ class TestPostHaste::TestArticle < Test::Unit::TestCase
|
|
26
26
|
context "Article.create from blog post" do
|
27
27
|
setup do
|
28
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)
|
29
|
+
json_url, source = Article.get_json(url)
|
30
30
|
@result = Article.parse_json(json_url)
|
31
31
|
@article = Article.create(@result)
|
32
32
|
end
|
@@ -42,4 +42,21 @@ class TestPostHaste::TestArticle < Test::Unit::TestCase
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
context "Article.create from Wordpress blog post" do
|
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, source = Article.get_json(url)
|
50
|
+
@result = Article.parse_json(json_url)
|
51
|
+
@article = Article.create_from_wordpress(@result)
|
52
|
+
end
|
53
|
+
|
54
|
+
should "return an object of the Article type" do
|
55
|
+
assert_kind_of(Article, @article)
|
56
|
+
assert_equal(@article.type, 'post')
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
end
|
61
|
+
|
45
62
|
end
|
data/test/test_helper.rb
CHANGED
@@ -3,9 +3,9 @@ require 'rubygems'
|
|
3
3
|
require 'shoulda'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
require 'post_haste'
|
9
9
|
|
10
10
|
module TestPostHaste
|
11
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: post_haste
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2013-01-20 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: json
|
17
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,21 +21,31 @@ dependencies:
|
|
22
21
|
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
26
30
|
- !ruby/object:Gem::Dependency
|
27
31
|
name: rake
|
28
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
29
33
|
none: false
|
30
34
|
requirements:
|
31
|
-
- - =
|
35
|
+
- - '='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: 0.8.7
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.8.7
|
37
46
|
- !ruby/object:Gem::Dependency
|
38
47
|
name: bundler
|
39
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
40
49
|
none: false
|
41
50
|
requirements:
|
42
51
|
- - ! '>='
|
@@ -44,10 +53,15 @@ dependencies:
|
|
44
53
|
version: 1.1.0
|
45
54
|
type: :development
|
46
55
|
prerelease: false
|
47
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.1.0
|
48
62
|
- !ruby/object:Gem::Dependency
|
49
63
|
name: shoulda
|
50
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
51
65
|
none: false
|
52
66
|
requirements:
|
53
67
|
- - ! '>='
|
@@ -55,7 +69,12 @@ dependencies:
|
|
55
69
|
version: '0'
|
56
70
|
type: :development
|
57
71
|
prerelease: false
|
58
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
59
78
|
description: A Ruby gem for accessing Washington Post articles and blog posts.
|
60
79
|
email:
|
61
80
|
- dwillis@gmail.com
|
@@ -65,17 +84,16 @@ extra_rdoc_files: []
|
|
65
84
|
files:
|
66
85
|
- .gitignore
|
67
86
|
- Gemfile
|
87
|
+
- Gemfile.lock
|
68
88
|
- LICENSE
|
69
89
|
- README.md
|
70
90
|
- Rakefile
|
71
91
|
- lib/post_haste.rb
|
72
92
|
- lib/post_haste/article.rb
|
73
|
-
- lib/post_haste/feed.rb
|
74
93
|
- lib/post_haste/version.rb
|
75
94
|
- post_haste.gemspec
|
76
95
|
- test/post_haste/test_article.rb
|
77
96
|
- test/test_helper.rb
|
78
|
-
has_rdoc: true
|
79
97
|
homepage: ''
|
80
98
|
licenses: []
|
81
99
|
post_install_message:
|
@@ -88,6 +106,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
106
|
- - ! '>='
|
89
107
|
- !ruby/object:Gem::Version
|
90
108
|
version: '0'
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
hash: 1009723447470533045
|
91
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
113
|
none: false
|
93
114
|
requirements:
|
@@ -96,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
117
|
version: 1.3.6
|
97
118
|
requirements: []
|
98
119
|
rubyforge_project: post_haste
|
99
|
-
rubygems_version: 1.
|
120
|
+
rubygems_version: 1.8.24
|
100
121
|
signing_key:
|
101
122
|
specification_version: 3
|
102
123
|
summary: Because it was there.
|