Class: AppNews

Inherits:
Object
  • Object
show all
Defined in:
lib/steam/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

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



19
20
21
# File 'lib/steam/community/app_news.rb', line 19

def app_id
  @app_id
end

#authorString (readonly)

Returns the name of the author of this news

Returns:

  • (String)

    The author of this news



24
25
26
# File 'lib/steam/community/app_news.rb', line 24

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



33
34
35
# File 'lib/steam/community/app_news.rb', line 33

def contents
  @contents
end

#dateTime (readonly)

Returns the date this news item has been published

Returns:

  • (Time)

    The date this news has been published



38
39
40
# File 'lib/steam/community/app_news.rb', line 38

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



43
44
45
# File 'lib/steam/community/app_news.rb', line 43

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



48
49
50
# File 'lib/steam/community/app_news.rb', line 48

def feed_name
  @feed_name
end

#gidFixnum (readonly)

Returns a unique identifier for this news

Returns:

  • (Fixnum)

    A unique identifier for this news



53
54
55
# File 'lib/steam/community/app_news.rb', line 53

def gid
  @gid
end

#titleString (readonly)

Returns the title of this news

Returns:

  • (String)

    The title of this news



58
59
60
# File 'lib/steam/community/app_news.rb', line 58

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



66
67
68
# File 'lib/steam/community/app_news.rb', line 66

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 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



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/steam/community/app_news.rb', line 81

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 = []
  MultiJson.load(data, { :symbolize_keys => true })[: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



97
98
99
# File 'lib/steam/community/app_news.rb', line 97

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



107
108
109
# File 'lib/steam/community/app_news.rb', line 107

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