Class: PostHaste::MostViewed

Inherits:
Object
  • Object
show all
Defined in:
lib/post_haste/most_viewed.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#bylineObject (readonly)

Returns the value of attribute byline.



4
5
6
# File 'lib/post_haste/most_viewed.rb', line 4

def 
  @byline
end

#datetimeObject (readonly)

Returns the value of attribute datetime.



4
5
6
# File 'lib/post_haste/most_viewed.rb', line 4

def datetime
  @datetime
end

#platformObject (readonly)

Returns the value of attribute platform.



4
5
6
# File 'lib/post_haste/most_viewed.rb', line 4

def platform
  @platform
end

#rankObject (readonly)

Returns the value of attribute rank.



4
5
6
# File 'lib/post_haste/most_viewed.rb', line 4

def rank
  @rank
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/post_haste/most_viewed.rb', line 4

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/post_haste/most_viewed.rb', line 4

def type
  @type
end

#urlObject (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