Class: IGE_ISB_API::Game
- Inherits:
-
Object
- Object
- IGE_ISB_API::Game
- Defined in:
- lib/ige_isb_api/games.rb
Instance Attribute Summary collapse
-
#casino ⇒ Object
Returns the value of attribute casino.
-
#category ⇒ Object
Returns the value of attribute category.
-
#coin ⇒ Object
Returns the value of attribute coin.
-
#coin_max ⇒ Object
Returns the value of attribute coin_max.
-
#coin_min ⇒ Object
Returns the value of attribute coin_min.
-
#coin_values ⇒ Object
Returns the value of attribute coin_values.
-
#custom_backgrounds ⇒ Object
Returns the value of attribute custom_backgrounds.
-
#description ⇒ Object
Returns the value of attribute description.
-
#game_type ⇒ Object
Returns the value of attribute game_type.
-
#id ⇒ Object
Returns the value of attribute id.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#images ⇒ Object
Returns the value of attribute images.
-
#info ⇒ Object
Returns the value of attribute info.
-
#is_fun_active ⇒ Object
Returns the value of attribute is_fun_active.
-
#is_real_active ⇒ Object
Returns the value of attribute is_real_active.
-
#language ⇒ Object
Returns the value of attribute language.
-
#main_category ⇒ Object
Returns the value of attribute main_category.
-
#name ⇒ Object
Returns the value of attribute name.
-
#provider ⇒ Object
Returns the value of attribute provider.
-
#restricted_countries ⇒ Object
Returns the value of attribute restricted_countries.
-
#skin ⇒ Object
Returns the value of attribute skin.
-
#translated ⇒ Object
Returns the value of attribute translated.
-
#use_preloader ⇒ Object
Returns the value of attribute use_preloader.
-
#wmode ⇒ Object
Returns the value of attribute wmode.
Class Method Summary collapse
-
.embed_game_html(opts = {}) ⇒ Object
settingsXMLProvider - the location of the game’s settings xml file (/[main_cat]/xml/[language identifier]/[game identifier]settings[fun/real].xml).
-
.embed_swfobject(opts = {}) ⇒ Object
Flash: loginc: 54,playerID passc: requestID,token,hostID.
- .encode_login(player_login) ⇒ Object
-
.encode_password(idrequest) ⇒ Object
request_id must be unique for each request.
- .from_node(node, cat, lang) ⇒ Object
- .game_launcher_url(opts = {}) ⇒ Object
Instance Method Summary collapse
- #fun? ⇒ Boolean
- #game_html5_url(mode) ⇒ Object
- #game_info_url(mode) ⇒ Object
-
#game_swf_path(mode) ⇒ Object
must not start with a ‘/’ With custom loader, you load the custom loader swf, and the gameurl flash var has to be absolute url With preloader, you load the preloader swf, and the gameurl flash var has to be absolute url Without custom loader or preloader, you have to load the main game swf, and the gameurl remains relative url.
- #game_swf_url(mode) ⇒ Object
- #get_info(mode) ⇒ Object
- #has_info?(mode) ⇒ Boolean
-
#initialize ⇒ Game
constructor
‘tra’, ‘tfa’, and ‘ta’ are deprecated fields and should be ignored.
- #load_info(some_xml) ⇒ Object
-
#main_image ⇒ Object
Image Sizes simg – preview of the game, the size of the preview is 160px – 60px limg – preview of the game, the size of the preview is 197px - 88px html_img – preview of the game, the size of the preview is 120px -158px img_v2 – preview of the game, the size of the preview is 240px – 135px.
- #real? ⇒ Boolean
- #thumb_image ⇒ Object
- #translated? ⇒ Boolean
- #use_preloader? ⇒ Boolean
- #warnings ⇒ Object
Constructor Details
#initialize ⇒ Game
‘tra’, ‘tfa’, and ‘ta’ are deprecated fields and should be ignored.
75 76 77 |
# File 'lib/ige_isb_api/games.rb', line 75 def initialize() @info = {} end |
Instance Attribute Details
#casino ⇒ Object
Returns the value of attribute casino.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def casino @casino end |
#category ⇒ Object
Returns the value of attribute category.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def category @category end |
#coin ⇒ Object
Returns the value of attribute coin.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def coin @coin end |
#coin_max ⇒ Object
Returns the value of attribute coin_max.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def coin_max @coin_max end |
#coin_min ⇒ Object
Returns the value of attribute coin_min.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def coin_min @coin_min end |
#coin_values ⇒ Object
Returns the value of attribute coin_values.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def coin_values @coin_values end |
#custom_backgrounds ⇒ Object
Returns the value of attribute custom_backgrounds.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def custom_backgrounds @custom_backgrounds end |
#description ⇒ Object
Returns the value of attribute description.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def description @description end |
#game_type ⇒ Object
Returns the value of attribute game_type.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def game_type @game_type end |
#id ⇒ Object
Returns the value of attribute id.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def id @id end |
#identifier ⇒ Object
Returns the value of attribute identifier.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def identifier @identifier end |
#images ⇒ Object
Returns the value of attribute images.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def images @images end |
#info ⇒ Object
Returns the value of attribute info.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def info @info end |
#is_fun_active ⇒ Object
Returns the value of attribute is_fun_active.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def is_fun_active @is_fun_active end |
#is_real_active ⇒ Object
Returns the value of attribute is_real_active.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def is_real_active @is_real_active end |
#language ⇒ Object
Returns the value of attribute language.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def language @language end |
#main_category ⇒ Object
Returns the value of attribute main_category.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def main_category @main_category end |
#name ⇒ Object
Returns the value of attribute name.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def name @name end |
#provider ⇒ Object
Returns the value of attribute provider.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def provider @provider end |
#restricted_countries ⇒ Object
Returns the value of attribute restricted_countries.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def restricted_countries @restricted_countries end |
#skin ⇒ Object
Returns the value of attribute skin.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def skin @skin end |
#translated ⇒ Object
Returns the value of attribute translated.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def translated @translated end |
#use_preloader ⇒ Object
Returns the value of attribute use_preloader.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def use_preloader @use_preloader end |
#wmode ⇒ Object
Returns the value of attribute wmode.
67 68 69 |
# File 'lib/ige_isb_api/games.rb', line 67 def wmode @wmode end |
Class Method Details
.embed_game_html(opts = {}) ⇒ Object
settingsXMLProvider - the location of the game’s settings xml file (/[main_cat]/xml/[language identifier]/[game identifier]settings[fun/real].xml)
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/ige_isb_api/games.rb', line 313 def self.(opts = {}) = { width: '100%', height: '100%', currency: IGE_ISB_API::Constants::DEFAULT_CURRENCY_CODE, gm_api: 1 # see https://github.com/Interactive-Gaming-Entertainment/ISBAPI/issues/10 }.merge(opts) mode = [:fun] ? :fun : :real password = [:fun] ? 'fun' : Game.encode_password([:idrequest]) name = [:fun] ? 'fun' : Game.encode_login([:player_login]) flashvars = [ "gamename=#{[:name]}", "gameurl=#{[:game_swf_path]}", "gameid=#{[:identifier]}", "skin_id=#{[:skin]}", "hostname=#{[:host]}", "loginc=#{name}", "passc=#{password}", "cur=#{[:currency]}", "forfun=#{[:fun] ? 1 : 0}", "langue=#{IGE_ISB_API::Constants::LANGUAGES[[:language].to_sym]}", "casino=#{[:casino]}", "coinval=#{[:coin_min]}", "table=0", "tokenuse=0", "realc=#{[:fun] ? 60 : 0}", "gmAPI=#{[:gm_api]}", "settingsXMLProvider=#{IGE_ISB_API::Constants::SERVER[mode]}#{[:main_category]}/xml/#{[:language]}/#{[:identifier]}_settings_#{mode.to_s}.xml", "translationXMLProvider=#{IGE_ISB_API::Constants::SERVER[mode]}#{[:main_category]}/xml/#{[:language]}/#{[:identifier]}_translations.xml" ].join('&') result = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' width='#{[:width]}' height='#{[:height]}' id='#{[:identifier]}'>" result << "<object type='application/x-shockwave-flash' data='#{[:game_swf_url]}' width='#{[:width]}' height='#{[:height]}'>" result << "<param name='movie' value='#{[:game_swf_url]}' />" result << "<param name='flashvars' value='#{flashvars}' />" result << "<param name='align' value='middle' />" result << "<param name='allowFullScreen' value='true' />" result << "<param name='allowScriptAccess' value='always' />" result << "<param name='quality' value='high' />" result << "<param name='bgcolor' value='#{[:colour]}' />" result << "<param name='wmode' value='#{[:wmode]}' />" result << "<param name='base' value='.' />" result << "</object></object>" return result end |
.embed_swfobject(opts = {}) ⇒ Object
Flash: loginc: 54,playerID passc: requestID,token,hostID
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/ige_isb_api/games.rb', line 267 def self.(opts = {}) = { width: '100%', height: '100%', container: 'game', currency: IGE_ISB_API::Constants::DEFAULT_CURRENCY_CODE, gm_api: 1 # see https://github.com/Interactive-Gaming-Entertainment/ISBAPI/issues/10 }.merge(opts) mode = [:fun] ? :fun : :real password = [:fun] ? 'fun' : Game.encode_password([:idrequest]) name = [:fun] ? Game.encode_login("fun") : Game.encode_login([:player_login]) vars = [ "gamename: unescape('#{CGI.escape([:name])}')", # some game names contain "'" marks. "gameurl: '#{[:game_swf_path]}'", "gameid: '#{[:identifier]}'", "skin_id: '#{[:skin]}'", "hostname: '#{[:host]}'", "loginc: '#{name}'", "passc: '#{password}'", "cur: '#{[:currency]}'", "forfun: #{[:fun] ? 1 : 0}", "langue: #{IGE_ISB_API::Constants::LANGUAGES[[:language].to_sym]}", "casino: '#{[:casino]}'", "coinval: '#{[:coin_min]}'", "table: 0", "tokenuse: 0", "realc: #{[:fun] ? 60 : 0}", "gmAPI: #{[:gm_api]}", "settingsXMLProvider: '#{IGE_ISB_API::Constants::SERVER[mode]}#{[:main_category]}/xml/#{[:language]}/#{[:identifier]}_settings_#{mode.to_s}.xml'", "translationXMLProvider: '#{IGE_ISB_API::Constants::SERVER[mode]}#{[:main_category]}/xml/#{[:language]}/#{[:identifier]}_translations.xml'" ].join(', ') pars = [ "align: 'middle'", "allowScriptAccess: 'always'", "allowFullScreen: 'true'", "quality: 'high'", "bgcolor: '#{[:colour]}'", "wmode: '#{[:wmode]}'" ].join(', ') result = "<script>var vars = {#{vars}}, params = {#{pars}}, swfUrl = '#{[:game_swf_url]}'; " result << "swfobject.embedSWF(swfUrl, '#{[:container]}', '#{[:width]}', '#{[:height]}', '11.0.0', null, vars, params);</script>" return result end |
.encode_login(player_login) ⇒ Object
243 244 245 246 |
# File 'lib/ige_isb_api/games.rb', line 243 def self.encode_login(player_login) raise ArgumentError, "You must supply a valid :player_login" if player_login.nil? return "#{IGE_ISB_API::Constants::LICENSEE_ID},#{player_login}" end |
.encode_password(idrequest) ⇒ Object
request_id must be unique for each request
235 236 237 238 239 240 241 |
# File 'lib/ige_isb_api/games.rb', line 235 def self.encode_password(idrequest) raise ArgumentError, "You must supply a unique :idrequest" if idrequest.nil? # password: idrequest,token,hostID # token - SHA256 digest of our 'SECRETKEY' + 'idrequest' which we will use to authenticate the incoming info. token = (Digest::SHA256.new << "#{IGE_ISB_API::Constants::SECRET_KEY}#{idrequest}").to_s return "#{idrequest},#{token},#{IGE_ISB_API::Constants::CALLBACK_ID}" end |
.from_node(node, cat, lang) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/ige_isb_api/games.rb', line 210 def self.from_node(node, cat, lang) g = Game.new g.category = cat g.id = node['id'].to_i g.name = node['n'] g.images = { s: node['simg'], # preview of the game, the size of the preview is 160px – 60px. Sometimes missing. l: node['limg'], # preview of the game, the size of the preview is 197px - 88px. html: node['html_img'], # preview of the game, the size of the preview is 120px -158px. v2: node['img_v2'] # preview of the game, the size of the preview is 240px – 135px. This is typically nil } g.is_fun_active = (node['fa'] == '1') g.is_real_active = (node['ra'] == '1') g.use_preloader = (node['p'] == '1') g.coin_values = node['c'].split('; ').map {|s| s.to_f} g.restricted_countries = node['rc'].split(', ') g.provider = node['provider'] g.identifier = node['i'] g.description = node.xpath('d').first.text g.translated = (node['translated'] == '1') g.language = g.translated? ? lang : IGE_ISB_API::Constants::DEFAULT_LANGUAGE return g end |
.game_launcher_url(opts = {}) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/ige_isb_api/games.rb', line 248 def self.game_launcher_url(opts = {}) = { currency: IGE_ISB_API::Constants::DEFAULT_CURRENCY_CODE }.merge(opts) password = [:fun] ? 'fun' : Game.encode_password([:idrequest]) name = [:fun] ? 'fun' : Game.encode_login([:player_login]) vars = [ "name=#{name}", "password=#{password}", "lang=#{[:language]}", "currency=#{[:currency]}", "funmode=#{[:fun].to_s}" ].join('&') return "#{[:game_html5_url]}?#{vars}" end |
Instance Method Details
#fun? ⇒ Boolean
162 163 164 |
# File 'lib/ige_isb_api/games.rb', line 162 def fun? return @is_fun_active end |
#game_html5_url(mode) ⇒ Object
94 95 96 97 |
# File 'lib/ige_isb_api/games.rb', line 94 def game_html5_url(mode) the_info = self.get_info(mode) return "#{IGE_ISB_API::Constants::SERVER[mode]}html/#{self.main_category}/#{self.identifier}/#{self.identifier}_r#{the_info.swf_revision}/#{self.identifier}.html" end |
#game_info_url(mode) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/ige_isb_api/games.rb', line 129 def game_info_url(mode) check_mode!(mode) raise RuntimeError, "Game Indentifier Unknown" if self.identifier.nil? || self.identifier.empty? raise RuntimeError, "Game Server Unknown" if IGE_ISB_API::Constants::SERVER[mode].nil? || IGE_ISB_API::Constants::SERVER[mode].empty? return "#{IGE_ISB_API::Constants::SERVER[mode]}xml_game_info/#{self.identifier}_info.xml" end |
#game_swf_path(mode) ⇒ Object
must not start with a ‘/’ With custom loader, you load the custom loader swf, and the gameurl flash var has to be absolute url With preloader, you load the preloader swf, and the gameurl flash var has to be absolute url Without custom loader or preloader, you have to load the main game swf, and the gameurl remains relative url
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ige_isb_api/games.rb', line 117 def game_swf_path(mode) check_mode!(mode) raise RuntimeError, "Game Identifier Unknown" if self.identifier.nil? || self.identifier.empty? raise RuntimeError, "Game Server Unknown" if IGE_ISB_API::Constants::SERVER[mode].nil? || IGE_ISB_API::Constants::SERVER[mode].empty? the_info = self.get_info(mode) raise RuntimeError, "SWF Revision not specified" if the_info.swf_revision.nil? if the_info.use_custom_loader? || self.use_preloader? return "#{IGE_ISB_API::Constants::SERVER[mode]}#{self.main_category}/swf_files/#{self.identifier}_r#{the_info.swf_revision}.swf" end return "swf_files/#{self.identifier}_r#{the_info.swf_revision}.swf" end |
#game_swf_url(mode) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ige_isb_api/games.rb', line 99 def game_swf_url(mode) check_mode!(mode) the_info = self.get_info(mode) if the_info.use_custom_loader? raise RuntimeError, "Custom Loader not specified" if the_info.custom_loader.nil? || the_info.custom_loader.empty? return "#{IGE_ISB_API::Constants::SERVER[mode]}#{self.main_category}/#{the_info.custom_loader}" end if self.use_preloader? raise RuntimeError, "Preloader not specified" if the_info.preloader.nil? || the_info.preloader.empty? return "#{IGE_ISB_API::Constants::SERVER[mode]}#{self.main_category}/#{the_info.preloader}" end return "#{IGE_ISB_API::Constants::SERVER[mode]}#{self.main_category}/#{game_swf_path(mode)}" end |
#get_info(mode) ⇒ Object
83 84 85 86 87 |
# File 'lib/ige_isb_api/games.rb', line 83 def get_info(mode) the_info = self.info[mode] raise ArgumentError, "No Info associated with mode #{mode}" unless self.has_info?(mode) return the_info end |
#has_info?(mode) ⇒ Boolean
79 80 81 |
# File 'lib/ige_isb_api/games.rb', line 79 def has_info?(mode) return !self.info[mode].nil? end |
#load_info(some_xml) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/ige_isb_api/games.rb', line 136 def load_info(some_xml) doc = Nokogiri::XML(some_xml) gn = doc.xpath("//game").first @skin = gn.xpath('skin_id').first.text.to_i @coin = gn.xpath('coin').first.text.to_f @coin_min = gn.xpath('coin_min').first.text.to_f @coin_max = gn.xpath('coin_max').first.text.to_f @casino = gn.xpath('casino').first.text @game_type = gn.xpath('type').first.text @wmode = gn.xpath('wmode').first.text @main_category = gn.xpath('main_cat').first.text # mode specific info fun = gn.xpath('fun').first.text == '1' mode = fun ? :fun : :real the_info = self.has_info?(mode) ? self.get_info(mode) : GameInfo.new(mode) the_info.url = gn.xpath('url').first.text the_info.swf_revision = gn.xpath('swf_revision').first.text.to_i the_info.host = gn.xpath('host').first.text the_info.use_custom_loader = (gn.xpath('use_custom_loader').first.text == '1') the_info.custom_loader = gn.xpath('custom_loader').first.text the_info.preloader = gn.xpath('prelfile').first.text if self.use_preloader? self.info[mode] = the_info return [] unless ((self.fun? && self.has_info?(:fun)) && (self.real? && self.has_info?(:real))) return any_errors? end |
#main_image ⇒ Object
Image Sizes simg – preview of the game, the size of the preview is 160px – 60px limg – preview of the game, the size of the preview is 197px - 88px html_img – preview of the game, the size of the preview is 120px -158px img_v2 – preview of the game, the size of the preview is 240px – 135px
179 180 181 182 183 184 185 186 |
# File 'lib/ige_isb_api/games.rb', line 179 def main_image images = self.images image = '' image = images[:v2] unless images[:v2].nil? || images[:v2].empty? image = images[:l] if image.empty? && !(images[:l].nil? || images[:l].empty?) image = images[:html] if image.empty? && !(images[:html].nil? || images[:html].empty?) return image end |
#real? ⇒ Boolean
166 167 168 |
# File 'lib/ige_isb_api/games.rb', line 166 def real? return @is_real_active end |
#thumb_image ⇒ Object
188 189 190 191 192 193 194 |
# File 'lib/ige_isb_api/games.rb', line 188 def thumb_image images = self.images thumb = '' thumb = images[:s] unless images[:s].nil? || images[:s].empty? thumb = main_image if thumb.empty? return thumb end |
#translated? ⇒ Boolean
170 171 172 |
# File 'lib/ige_isb_api/games.rb', line 170 def translated? return @translated end |
#use_preloader? ⇒ Boolean
89 90 91 92 |
# File 'lib/ige_isb_api/games.rb', line 89 def use_preloader? return @use_preloader if (defined? @use_preloader && !@use_preloader.nil?) return false end |
#warnings ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/ige_isb_api/games.rb', line 196 def warnings warnings = [] warnings << {game: self, message: "Missing description, defaulting to ''."} if self.description.nil? || self.description.empty? images = self.images warnings << {game: self, message: "Missing ':l' image in #{images.inspect}"} if images[:l].nil? || images[:l].empty? warnings << {game: self, message: "Missing ':s' image in #{images.inspect}"} if images[:s].nil? || images[:s].empty? warnings << {game: self, message: "Missing ':html' image in #{images.inspect}"} if images[:html].nil? || images[:html].empty? # => almost all games are missing the :v2 image completely so only warn if empty, not nil. warnings << {game: self, message: "Missing :v2 image in #{images.inspect}"} if !images[:v2].nil? && images[:v2].empty? warnings << {game: self, message: "Unable to determine main image"} if self.main_image.empty? warnings << {game: self, message: "Unable to determine thumbnail image"} if self.thumb_image.empty? return warnings end |