Sha256: f7df2625d3316d00217ea3e4040aa045dc6944a748ac19bd2c6f0944d8d02259

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

module Gameball
  module Utils
    extend self

    def hashBody(playerUniqueId:, transactionTime: "", amount: "") # Helper method that hashes the attributes that are sent using SHA1 algorithm
      # Check if transaction Key is provided else raise Error
      if !Gameball.transaction_key
        raise Gameball::GameballError.new("Please provide transaction_key, try Gameball::transaction_key='your_key'") # Raise exception
      else
        if transactionTime == ""
          formatted_time = ""
        else
          formatted_time = transactionTime.strftime("%y%m%d%H%M%S")
        end
      end

      str = playerUniqueId + ":" + formatted_time + ":" + amount.to_s + ":" + Gameball.transaction_key
      return Digest::SHA1.hexdigest (str)
    end

    def extractAttributesToHash(body) # Helper method that extracts the attributes from the body and pass it to hashing function
      playerUniqueId = body[:playerUniqueId]
      amount = body[:amount]
      transactionTime = body[:transactionTime]
      begin
        body[:transactionTime] = transactionTime.iso8601
      rescue NoMethodError => exception
        raise Gameball::GameballError.new("Invalid Date Formate, Please use Date and Time objects")
      end

      body["hash"] = Gameball::Utils::hashBody(playerUniqueId: playerUniqueId, amount: (amount || ""), transactionTime: (transactionTime || ""))
      body
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
gameball-1.0.1 lib/gameball/utils/helper.rb
gameball-1.0.0 lib/gameball/utils/helper.rb
alphaSDK-0.2.8 lib/gameball/utils/helper.rb
alphaSDK-0.2.7 lib/gameball/utils/helper.rb