Class: PostHaste::MostViewed
- Inherits:
-
Object
- Object
- PostHaste::MostViewed
- Defined in:
- lib/post_haste/most_viewed.rb
Instance Attribute Summary collapse
-
#byline ⇒ Object
readonly
Returns the value of attribute byline.
-
#datetime ⇒ Object
readonly
Returns the value of attribute datetime.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
- .all(platform = 'web', limit = 25) ⇒ Object
- .articles(platform = 'web', limit = 25) ⇒ Object
- .blogs(platform = 'web', limit = 25) ⇒ Object
- .create(result = {}, platform, type) ⇒ Object
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ MostViewed
constructor
A new instance of MostViewed.
Constructor Details
#initialize(params = {}) ⇒ MostViewed
Returns a new instance of MostViewed.
6 7 8 9 10 |
# File 'lib/post_haste/most_viewed.rb', line 6 def initialize(params={}) params.each_pair do |k,v| instance_variable_set("@#{k}", v) end end |
Instance Attribute Details
#byline ⇒ Object (readonly)
Returns the value of attribute byline.
4 5 6 |
# File 'lib/post_haste/most_viewed.rb', line 4 def @byline end |
#datetime ⇒ Object (readonly)
Returns the value of attribute datetime.
4 5 6 |
# File 'lib/post_haste/most_viewed.rb', line 4 def datetime @datetime end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
4 5 6 |
# File 'lib/post_haste/most_viewed.rb', line 4 def platform @platform end |
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
4 5 6 |
# File 'lib/post_haste/most_viewed.rb', line 4 def rank @rank end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
4 5 6 |
# File 'lib/post_haste/most_viewed.rb', line 4 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/post_haste/most_viewed.rb', line 4 def type @type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/post_haste/most_viewed.rb', line 4 def url @url end |
Class Method Details
.all(platform = 'web', limit = 25) ⇒ Object
12 13 14 15 |
# File 'lib/post_haste/most_viewed.rb', line 12 def self.all(platform='web', limit=25) url = "https://js.washingtonpost.com/most-viewed/#{platform}/article,blog.feed-#{limit}.json" create(HTTParty.get(url).parsed_response, platform, 'all') end |
.articles(platform = 'web', limit = 25) ⇒ Object
17 18 19 20 |
# File 'lib/post_haste/most_viewed.rb', line 17 def self.articles(platform='web', limit=25) url = "https://js.washingtonpost.com/most-viewed/#{platform}/article.feed-#{limit}.json" create(HTTParty.get(url).parsed_response, platform, 'articles') end |
.blogs(platform = 'web', limit = 25) ⇒ Object
22 23 24 25 |
# File 'lib/post_haste/most_viewed.rb', line 22 def self.blogs(platform='web', limit=25) url = "https://js.washingtonpost.com/most-viewed/#{platform}/blog.feed-#{limit}.json" create(HTTParty.get(url).parsed_response, platform, 'blogs') end |
.create(result = {}, platform, type) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/post_haste/most_viewed.rb', line 27 def self.create(result={}, platform, type) result['content'].map!.with_index {|r,i| self.new platform: platform, type: type, datetime: DateTime.parse(result['updated']), title: r['linkText'], byline: r['byline'], url: r['url'], rank: i+1 } end |