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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 149170b0b2ba322778fbdec9963b070bb8af71ed
4
- data.tar.gz: a52aa7534b87109a1417d6575a31486c09b99369
3
+ metadata.gz: 96a4c2886f29d057214ecfc3da0d93f0861c47f7
4
+ data.tar.gz: 1896ee276a2cb6a7ea8b478fbdee3711fa609113
5
5
  SHA512:
6
- metadata.gz: bf83597199e73298315263f66c0e23b1da525fd9dc7edb4d3155089284525837fc136a9e945b4f7846a12b1d45a1125ca7e90c4399ff577e73d4037e765eb657
7
- data.tar.gz: d789bb2dd126b19912ba5de504c8c9cc71eef468ca12da28b928cf1d93298daa0c84ef202f3ec4b22e0fd05d74ef3a58818b3d0eddc728c378abb42dd4691b58
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.0)
5
- json
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.1.1)
12
- i18n (~> 0.6, >= 0.6.9)
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.1)
15
+ thread_safe (~> 0.3, >= 0.3.4)
16
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)
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.6.1)
32
+ shoulda-matchers (2.8.0)
29
33
  activesupport (>= 3.0.0)
30
- thread_safe (0.3.3)
31
- tzinfo (1.1.0)
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 and 2.1.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/
@@ -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 = JSON.parse(open(comments_url).read)
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
- JSON.parse(open(url).read)
39
+ HTTParty.get(url).parsed_response
43
40
  end
44
41
 
45
42
  # Post CMS produces unix timestamps, but with extra zeroes
@@ -1,7 +1,3 @@
1
- require 'open-uri'
2
- require 'uri'
3
- require 'json'
4
-
5
1
  module PostHaste
6
2
  class Comment
7
3
  # Represents a comment on a Washington Post story
@@ -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
@@ -1,3 +1,3 @@
1
1
  module PostHaste
2
- VERSION = "1.1"
2
+ VERSION = "1.2"
3
3
  end
data/lib/post_haste.rb CHANGED
@@ -1,3 +1,5 @@
1
- %w(article.rb comment.rb).each do |f|
1
+ %w(article.rb comment.rb most_viewed.rb).each do |f|
2
2
  require File.join(File.dirname(__FILE__), 'post_haste/', f)
3
- end
3
+ end
4
+ require 'httparty'
5
+ require 'uri'
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 "json"
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
@@ -1,7 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require 'rubygems'
3
3
  require 'shoulda'
4
- require 'json'
5
4
 
6
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
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.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-07-30 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json
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: