Class: SteamCondenser::Community::AppNews

Inherits:
Object
  • Object
show all
Defined in:
lib/steam-condenser/community/app_news.rb

Overview

This class represents Steam news and can be used to load a list of current news about specific games

Author:

  • Sebastian Staudt

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id, news_data) ⇒ AppNews (private)

Creates a new instance of an AppNews news item with the given data


122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/steam-condenser/community/app_news.rb', line 122

def initialize(app_id, news_data)
  @app_id      = app_id
  @author      = news_data[:author]
  @contents    = news_data[:contents].strip
  @data        = Time.at(news_data[:date])
  @external    = news_data[:is_external_url]
  @feed_label  = news_data[:feedlabel]
  @feed_name   = news_data[:feedname]
  @gid         = news_data[:gid]
  @title       = news_data[:title]
  @url         = news_data[:url]
end

Instance Attribute Details

#app_idFixnum (readonly)

Returns the Steam Application ID of the game this news belongs to


21
22
23
# File 'lib/steam-condenser/community/app_news.rb', line 21

def app_id
  @app_id
end

#authorString (readonly)

Returns the name of the author of this news


26
27
28
# File 'lib/steam-condenser/community/app_news.rb', line 26

def author
  @author
end

#contentsString (readonly)

Note:

Depending on the setting for the maximum length of a news (see news_for_app), the contents might be truncated.

Returns the contents of this news

This might contain HTML code.


35
36
37
# File 'lib/steam-condenser/community/app_news.rb', line 35

def contents
  @contents
end

#dateTime (readonly)

Returns the date this news item has been published


40
41
42
# File 'lib/steam-condenser/community/app_news.rb', line 40

def date
  @date
end

#feed_labelString (readonly)

Returns the name of the feed this news item belongs to


45
46
47
# File 'lib/steam-condenser/community/app_news.rb', line 45

def feed_label
  @feed_label
end

#feed_nameString (readonly)

Returns the symbolic name of the feed this news item belongs to


50
51
52
# File 'lib/steam-condenser/community/app_news.rb', line 50

def feed_name
  @feed_name
end

#gidFixnum (readonly)

Returns a unique identifier for this news


55
56
57
# File 'lib/steam-condenser/community/app_news.rb', line 55

def gid
  @gid
end

#titleString (readonly)

Returns the title of this news


60
61
62
# File 'lib/steam-condenser/community/app_news.rb', line 60

def title
  @title
end

#urlString (readonly)

Returns the URL of the original news

This is a direct link to the news on the Steam website or a redirecting link to the external post.


68
69
70
# File 'lib/steam-condenser/community/app_news.rb', line 68

def url
  @url
end

Class Method Details

.news_for_app(app_id, count = 5, max_length = nil) ⇒ Array<AppNews>

Loads the news for the given game with the given restrictions


83
84
85
86
87
88
89
90
91
92
93
# File 'lib/steam-condenser/community/app_news.rb', line 83

def self.news_for_app(app_id, count = 5, max_length = nil)
  params = { :appid => app_id, :count => count, :maxlength => max_length }
  data = WebApi.json('ISteamNews', 'GetNewsForApp', 2, params)

  news_items = []
  data[:appnews][:newsitems].each do |news_data|
    news_items << AppNews.new(app_id, news_data)
  end

  news_items
end

Instance Method Details

#external?Boolean

Returns whether this news item originates from a source other than Steam itself (e.g. an external blog)


99
100
101
# File 'lib/steam-condenser/community/app_news.rb', line 99

def external?
  @external
end

#to_sString

Returns a simple textual representation of this news item

Will consist of the name of the feed this news belongs to and the title of the news.


109
110
111
# File 'lib/steam-condenser/community/app_news.rb', line 109

def to_s
  "#@feed_label: #@title"
end