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

Parameters:


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

Returns:

  • (Fixnum)

    The 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

Returns:

  • (String)

    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.

Returns:

  • (String)

     The contents of this news


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

Returns:

  • (Time)

    The date this news 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

Returns:

  • (String)

    The name of the feed this news 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

Returns:

  • (String)

    The symbolic name of the feed this news 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

Returns:

  • (Fixnum)

    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

Returns:

  • (String)

    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.

Returns:

  • (String)

    The URL of the original news


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

Parameters:

  • app_id (Fixnum)

    The unique Steam Application ID of the game (e.g. 440 for Team Fortress 2). See http://developer.valvesoftware.com/wiki/Steam_Application_IDs for all application IDs.

  • count (Fixnum) (defaults to: 5)

    The maximum number of news to load. There's no reliable way to load all news. Use a really great number instead.

  • max_length (Fixnum) (defaults to: nil)

    The maximum content length of the news. If a maximum length is defined, the content of the news will only be at most max_length characters long plus an ellipsis.

Returns:

  • (Array<AppNews>)

    An array of news items for the specified game with the given options


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)

Returns:

  • (Boolean)

    true if this news item is from an external source


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.

Returns:

  • (String)

    A simple text representing this news


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

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