post_haste 0.9.2 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05490abd909ec30075a32d308a96e03fe2f66529
4
+ data.tar.gz: 432fd9eea944f66b1026582646a501a981b5d510
5
+ SHA512:
6
+ metadata.gz: 4f9911869cf547f279080a9aaf31aa664e476dfcfdbe0fb94a4f5a10193b042a4852e89b4f14bd0673dc040caa7069a3254e616fba1d1523f43b7693e761d6da
7
+ data.tar.gz: 589708016c6043afc6591b925d8478df3b6585e6e3a868cb418661b107a66ad6582eae9bf33a0ec570a05003ca91c5e52461d3428df7902f0e8a0c31c47bf732
data/Gemfile.lock CHANGED
@@ -1,33 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- post_haste (0.9.2)
4
+ post_haste (1.0)
5
5
  json
6
6
  nokogiri
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (3.2.13)
12
- i18n (= 0.6.1)
13
- multi_json (~> 1.0)
14
- i18n (0.6.1)
15
- json (1.8.0)
16
- multi_json (1.7.3)
17
- nokogiri (1.5.9)
18
- rake (0.8.7)
11
+ activesupport (4.1.1)
12
+ i18n (~> 0.6, >= 0.6.9)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
+ thread_safe (~> 0.1)
16
+ tzinfo (~> 1.1)
17
+ i18n (0.6.9)
18
+ json (1.8.1)
19
+ mini_portile (0.5.3)
20
+ minitest (5.3.3)
21
+ nokogiri (1.6.2)
22
+ mini_portile (~> 0.5.2)
23
+ rake (10.3.1)
19
24
  shoulda (3.5.0)
20
25
  shoulda-context (~> 1.0, >= 1.0.1)
21
26
  shoulda-matchers (>= 1.4.1, < 3.0)
22
- shoulda-context (1.1.2)
23
- shoulda-matchers (2.1.0)
27
+ shoulda-context (1.2.1)
28
+ shoulda-matchers (2.6.1)
24
29
  activesupport (>= 3.0.0)
30
+ thread_safe (0.3.3)
31
+ tzinfo (1.1.0)
32
+ thread_safe (~> 0.1)
25
33
 
26
34
  PLATFORMS
27
35
  ruby
28
36
 
29
37
  DEPENDENCIES
30
- bundler (>= 1.1.0)
38
+ bundler
39
+ minitest
31
40
  post_haste!
32
- rake
41
+ rake (~> 10.3.1)
33
42
  shoulda
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, which have slightly different output (but also includes comments).
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.
4
4
 
5
- Tested under Ruby 1.9.2 & 1.9.3.
5
+ Tested under Ruby 1.9.3, 2.0.0 and 2.1.0.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,9 +22,12 @@ 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
+ require 'post_haste'
26
+ include PostHaste
27
+
25
28
  url = "http://www.washingtonpost.com/blogs/the-fix/post/republicans-on-the-2012-gop-field-blah/2012/03/15/gIQAT7CSFS_blog.html"
26
29
 
27
- @article = Article.create_from_url(url, 25) # 25 represents number of comments to grab, default is 15.
30
+ @article = Article.create_from_url(url, 10) # 10 represents number of comments to grab, default is 25.
28
31
 
29
32
  @article.title
30
33
 
@@ -42,11 +45,18 @@ Post Haste currently can accept a URL of a Washington Post article or blog post,
42
45
 
43
46
  => "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"
44
47
 
45
-
48
+ See the full list of `Article` instance methods in article.rb.
49
+
46
50
  ## In the Wild
47
51
 
48
52
  See an example application at http://postcomments.herokuapp.com/
49
53
 
54
+ ### Tests
55
+
56
+ To run the test suite, do:
57
+
58
+ rake test
59
+
50
60
  ## Contributing
51
61
 
52
62
  1. Fork it
@@ -6,9 +6,8 @@ module PostHaste
6
6
  class Article
7
7
  # Represents a single Washington Post story or blog post.
8
8
 
9
- attr_reader :uuid, :type, :title, :blurb, :has_correction, :correction, :has_clarification, :clarification, :permalink, :short_url, :email_url,
10
- :comments_url, :graphic_url, :video_url, :byline, :organization, :credits, :created_datetime, :published_datetime, :display_datetime, :updated_datetime,
11
- :section, :tags, :comments
9
+ attr_reader :uuid, :type, :title, :summary, :mobile_headline, :web_headline, :permalink, :short_url, :keywords, :email, :bio_page,
10
+ :comments_url, :byline, :created_datetime, :published_datetime, :display_datetime, :updated_datetime, :section, :tags, :comments
12
11
 
13
12
  def initialize(params={})
14
13
  params.each_pair do |k,v|
@@ -28,22 +27,14 @@ module PostHaste
28
27
 
29
28
  # comment limit defaults to 15, but can be set higher or lower
30
29
  def self.create_from_url(url, comment_limit=15)
31
- json_url, source = get_json(url)
32
- result = parse_json(json_url)
33
- create_from_source(source, result, comment_limit)
30
+ result = parse_json(get_json(url))
31
+ create(result, comment_limit)
34
32
  end
35
33
 
36
34
  # Given a Washington Post story or blog url, can turn that url into a JSON API endpoint
37
- # returns the url and a source (cms or wordpress) used in Article creation
35
+ # returns the url and the source used in Article creation
38
36
  def self.get_json(url)
39
- if url.include?('/wp/') or url.include?('/sf/')
40
- url = url.split('?').first # strip out anything after a ?
41
- [url+'?json=1', 'wordpress']
42
- elsif url.include?("_story")
43
- [url.gsub('_story','_json'), 'cms']
44
- elsif url.include?("_blog")
45
- [url.gsub('_blog','_json'), 'cms']
46
- end
37
+ "http://apps-origin.washingtonpost.com/f/story-builder/api/url?url=#{url}"
47
38
  end
48
39
 
49
40
  # parses a Washington Post story or blog JSON response
@@ -57,71 +48,29 @@ module PostHaste
57
48
  Time.at(seconds.to_i).to_datetime
58
49
  end
59
50
 
60
- def self.create_from_source(source, result, comment_limit)
61
- if source == 'cms'
62
- create(result, comment_limit)
63
- elsif source == 'wordpress'
64
- create_from_wordpress(result, comment_limit)
65
- end
66
- end
67
-
68
51
  # creates an Article object from a JSON response
69
- # with 15 latest comments, can be configured.
70
- def self.create(params={}, limit=15)
71
- self.new :type => params['contentConfig']['type'],
72
- :uuid => params['contentConfig']['uuid'],
73
- :title => params['contentConfig']['title'],
74
- :blurb => params['contentConfig']['blurb'],
75
- :has_correction => params['contentConfig']['hasCorrection'],
76
- :correction => params['contentConfig']['correction'],
77
- :has_clarification => params['contentConfig']['hasClarification'],
78
- :clarification => params['contentConfig']['clarification'],
79
- :permalink => params['contentConfig']['permaLinkURL'],
80
- :short_url => params['contentConfig']['shortURL'],
81
- :email_url => params['contentConfig']['emailURL'],
82
- :comments_url => params['contentConfig']['commentsURL'],
83
- :graphic_url => params['contentConfig']['graphicURL'],
84
- :video_url => params['contentConfig']['videoURL'],
85
- :byline => params['contentConfig']['credits'].first['name'],
86
- :organization => params['contentConfig']['credits'].first['organization'],
87
- :credits => params['contentConfig']['credits'].first['credit'],
88
- :created_datetime => parse_datetime(params['contentConfig']['dateConfig']['dateCreated']),
89
- :published_datetime => parse_datetime(params['contentConfig']['dateConfig']['datePublished']),
90
- :display_datetime => parse_datetime(params['contentConfig']['dateConfig']['displayDate']),
91
- :updated_datetime => parse_datetime(params['contentConfig']['dateConfig']['dateUpdated']),
92
- :section => params['metaConfig']['section'],
93
- :tags => params['metaConfig']['tags'],
94
- :comments => parse_latest_comments(params['contentConfig']['permaLinkURL'], latest_comments_url(params['contentConfig']['permaLinkURL'], limit=limit))
52
+ # with 25 latest comments, can be configured.
53
+ def self.create(result={}, limit=25)
54
+ self.new type: result['type'],
55
+ uuid: result['uuid'],
56
+ title: result['title'],
57
+ mobile_headline: result['mobile_headline'],
58
+ web_headline: result['web_headline'],
59
+ summary: result['summary'],
60
+ permalink: result['_id'],
61
+ short_url: result['short_url'],
62
+ comments_url: latest_comments_url(result['_id'], limit),
63
+ keywords: result['clavis_keywords'],
64
+ byline: result['creator'].map{|c| c['name']},
65
+ email: result['creator'].map{|c| c['email']},
66
+ bio_page: result['creator'].map{|c| c['bio_page']},
67
+ created_datetime: Time.at(result['created_date'].to_i),
68
+ published_datetime: Time.at(result['published_date'].to_i),
69
+ display_datetime: Time.at(result['display_date'].to_i),
70
+ section: result['kicker']['name'],
71
+ tags: result['tags'],
72
+ comments: parse_latest_comments(result['_id'], latest_comments_url(result['_id'], limit=limit))
95
73
 
96
74
  end
97
-
98
- # creates an Article object from a WordPress JSON response
99
- def self.create_from_wordpress(params={}, limit=15)
100
- self.new :type => params['post']['type'],
101
- :uuid => params['post']['id'],
102
- :title => params['post']['title'],
103
- :blurb => params['post']['excerpt'],
104
- :has_correction => nil,
105
- :correction => nil,
106
- :has_clarification => nil,
107
- :clarification => nil,
108
- :permalink => params['post']['url'],
109
- :short_url => nil,
110
- :email_url => nil,
111
- :comments_url => params['post']['url'],
112
- :graphic_url => nil,
113
- :video_url => nil,
114
- :byline => params['post']['author']['name'],
115
- :organization => nil,
116
- :credits => nil,
117
- :created_datetime => parse_datetime(params['post']['date']),
118
- :published_datetime => parse_datetime(params['post']['date']),
119
- :display_datetime => parse_datetime(params['post']['modified']),
120
- :updated_datetime => parse_datetime(params['post']['modified']),
121
- :section => nil,
122
- :tags => params['post']['tags'],
123
- :comments => parse_latest_comments(params['post']['url'], latest_comments_url(params['post']['url'], limit))
124
- end
125
-
126
75
  end
127
76
  end
@@ -1,3 +1,3 @@
1
1
  module PostHaste
2
- VERSION = "0.9.2"
2
+ VERSION = "1.0"
3
3
  end
data/post_haste.gemspec CHANGED
@@ -20,8 +20,9 @@ Gem::Specification.new do |gem|
20
20
  gem.add_runtime_dependency "json"
21
21
  gem.add_runtime_dependency "nokogiri"
22
22
 
23
- gem.add_development_dependency "rake"
24
- gem.add_development_dependency "bundler", ">= 1.1.0"
23
+ gem.add_development_dependency "rake", '~> 10.3.1'
24
+ gem.add_development_dependency "bundler"
25
25
  gem.add_development_dependency "shoulda"
26
+ gem.add_development_dependency "minitest"
26
27
 
27
28
  end
@@ -1,61 +1,61 @@
1
1
  require 'test_helper'
2
2
 
3
- class TestPostHaste::TestArticle < Test::Unit::TestCase
4
- include PostHaste
5
-
6
- context "Article.create from article" do
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, source = Article.get_json(url)
10
- @result = Article.parse_json(json_url)
11
- @article = Article.create(@result)
12
- end
13
-
14
- should "return an object of the Article type" do
15
- assert_kind_of(Article, @article)
16
- assert_equal(@article.type, 'article')
17
- end
18
-
19
- %w(uuid type title blurb).each do |attr|
20
- should "assign the value of the @#{attr} attribute from the '#{attr}' key in the hash" do
21
- assert_equal(@result['contentConfig'][attr], @article.send(attr))
22
- end
23
- end
3
+ class TestPostHaste::TestArticle < Minitest::Test
4
+ include PostHaste
5
+
6
+ context "Article.create from article" do
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)
11
+ @article = Article.create(@result)
12
+ end
13
+
14
+ should "return an object of the Article type" do
15
+ assert_kind_of(Article, @article)
16
+ assert_equal(@article.type, 'article')
17
+ end
18
+
19
+ %w(uuid type title summary).each do |attr|
20
+ should "assign the value of the @#{attr} attribute from the '#{attr}' key in the hash" do
21
+ assert_equal(@result[attr], @article.send(attr))
22
+ end
23
+ end
24
24
  end
25
25
 
26
26
  context "Article.create from blog post" do
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, source = Article.get_json(url)
30
- @result = Article.parse_json(json_url)
31
- @article = Article.create(@result)
32
- end
33
-
34
- should "return an object of the Article type" do
35
- assert_kind_of(Article, @article)
36
- assert_equal(@article.type, 'BlogStory')
37
- end
38
-
39
- %w(uuid type title blurb).each do |attr|
40
- should "assign the value of the @#{attr} attribute from the '#{attr}' key in the hash" do
41
- assert_equal(@result['contentConfig'][attr], @article.send(attr))
42
- end
43
- end
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)
31
+ @article = Article.create(@result)
32
+ end
33
+
34
+ should "return an object of the Article type" do
35
+ assert_kind_of(Article, @article)
36
+ assert_equal(@article.type, 'article')
37
+ end
38
+
39
+ %w(uuid type title summary).each do |attr|
40
+ should "assign the value of the @#{attr} attribute from the '#{attr}' key in the hash" do
41
+ assert_equal(@result[attr], @article.send(attr))
42
+ end
43
+ end
44
44
  end
45
45
 
46
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
-
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)
51
+ @article = Article.create(@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, 'blog')
57
+ end
58
+
59
59
 
60
60
  end
61
61
 
data/test/test_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'test/unit'
1
+ require "minitest/autorun"
2
2
  require 'rubygems'
3
3
  require 'shoulda'
4
4
  require 'json'
metadata CHANGED
@@ -1,94 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: post_haste
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
5
- prerelease:
4
+ version: '1.0'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Derek Willis
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-12 00:00:00.000000000 Z
11
+ date: 2014-05-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: nokogiri
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '0'
47
+ version: 10.3.1
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
- version: '0'
54
+ version: 10.3.1
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: bundler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
- version: 1.1.0
61
+ version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
- version: 1.1.0
68
+ version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: shoulda
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
84
88
  - !ruby/object:Gem::Version
85
89
  version: '0'
86
90
  type: :development
87
91
  prerelease: false
88
92
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
93
  requirements:
91
- - - ! '>='
94
+ - - ">="
92
95
  - !ruby/object:Gem::Version
93
96
  version: '0'
94
97
  description: A Ruby gem for accessing Washington Post articles and blog posts.
@@ -98,7 +101,7 @@ executables: []
98
101
  extensions: []
99
102
  extra_rdoc_files: []
100
103
  files:
101
- - .gitignore
104
+ - ".gitignore"
102
105
  - Gemfile
103
106
  - Gemfile.lock
104
107
  - LICENSE
@@ -113,30 +116,26 @@ files:
113
116
  - test/test_helper.rb
114
117
  homepage: ''
115
118
  licenses: []
119
+ metadata: {}
116
120
  post_install_message:
117
121
  rdoc_options: []
118
122
  require_paths:
119
123
  - lib
120
124
  required_ruby_version: !ruby/object:Gem::Requirement
121
- none: false
122
125
  requirements:
123
- - - ! '>='
126
+ - - ">="
124
127
  - !ruby/object:Gem::Version
125
128
  version: '0'
126
- segments:
127
- - 0
128
- hash: 3728910405888285188
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
- none: false
131
130
  requirements:
132
- - - ! '>='
131
+ - - ">="
133
132
  - !ruby/object:Gem::Version
134
133
  version: 1.3.6
135
134
  requirements: []
136
135
  rubyforge_project: post_haste
137
- rubygems_version: 1.8.25
136
+ rubygems_version: 2.2.1
138
137
  signing_key:
139
- specification_version: 3
138
+ specification_version: 4
140
139
  summary: Because it was there.
141
140
  test_files:
142
141
  - test/post_haste/test_article.rb