Class: IGE_ISB_API::Callback::GameplaySession
- Inherits:
-
Object
- Object
- IGE_ISB_API::Callback::GameplaySession
- Defined in:
- lib/ige_isb_api/callback.rb
Class Method Summary collapse
-
.parse(raw_data) ⇒ Object
{ “player”: String # player login as originally passed to ISB at .registration, “requestid”:Integer, # same as we provided in the IDREQUEST field “token”: String - # a SHA2 digest of our ‘SECRETKEY’ + ‘IDREQUEST’ which we will use to authenticate the incoming info., “sesson-start”:“2013/10/25.10:54:18”, “sesson-end”:“2013/10/25.12:32:51”, “skin_ID”: 2019 “currency”:“USD”, “hostID”:1, “actions”:[ { “bet”:{ “amount”: 1.00 }, “bet”:{ “amount”: 50.00 }, “win”:{ “amount”: 80.00 } } ] }.
Class Method Details
.parse(raw_data) ⇒ Object
{
"player": String # player login as originally passed to ISB at .registration,
"requestid":Integer, # same as we provided in the IDREQUEST field
"token": String - # a SHA2 digest of our 'SECRETKEY' + 'IDREQUEST' which we will use to authenticate the incoming info.,
"sesson-start":"2013/10/25.10:54:18",
"sesson-end":"2013/10/25.12:32:51",
"skin_ID": 2019
"currency":"USD",
"hostID":1,
"actions":[
{
"bet":{
"amount": 1.00
},
"bet":{
"amount": 50.00
},
"win":{
"amount": 80.00
}
}
]
}
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ige_isb_api/callback.rb', line 32 def self.parse(raw_data) raise ValidationException, "No data to parse" if raw_data.nil? || raw_data.empty? begin data = JSON.parse(raw_data) player = data['player'] IGE_ISB_API::Validation.test('player', player, 'username') requestid = data['requestid'].to_i IGE_ISB_API::Validation.test('requestid', requestid, 'int') token = data['token'] expected = (Digest::SHA2.new << "#{IGE_ISB_API::Constants::SECRET_KEY}#{requestid}").to_s raise ValidationException, "Invalid Token" unless token == expected session_start = DateTime.strptime(data['session-start'], "%Y/%m/%d.%H:%M:%S").to_time.utc session_end = DateTime.strptime(data['session-end'], "%Y/%m/%d.%H:%M:%S").to_time.utc raise ValidationException, "session-end must be after session-start" unless session_start < session_end skinid = data['skin_ID'].to_i IGE_ISB_API::Validation.test('skin_ID', skinid, 'int') currency = data['currency'] IGE_ISB_API::Validation.test('currency', currency, 'currency_code') hostid = data['hostID'].to_i actions = data['actions'].map do |act| if act['bet'] { action: :bet, amount: act['bet']['amount'].to_f } elsif act['win'] { action: :win, amount: act['win']['amount'].to_f } else raise ValidationException, "Invalid Action" end end return { player: player, requestid: requestid, session_start: session_start, session_end: session_end, skinid: skinid, currency: currency, hostid: hostid, actions: actions } rescue ArgumentError => ae raise ValidationException, ae. rescue JSON::ParserError => jpe raise ValidationException, "Invalid JSON format in supplied data: #{jpe.}" end end |