Sha256: 2451a89e5a56c73f5dc8b107b5e42e4f024246adfab20e2bd1b0a67b1ae5daaf

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

require 'json'

module PlaylyfeClient
  #grabbed from playlyfe-rub-sdk
  class Error < StandardError; end
  class ConnectionError < PlaylyfeClient::Error; end
  class GameError < PlaylyfeClient::Error; end
  class PlayerError < PlaylyfeClient::Error; end
  class LeaderboardError < PlaylyfeClient::Error; end
  class ActionError < PlaylyfeClient::Error; end
  class MetricError < PlaylyfeClient::Error; end
  class PlaylyfeClient::ActionRateLimitExceededError < PlaylyfeClient::ActionError; end
  class PlaylyfeClient::PlayerExistsError < PlaylyfeClient::PlayerError; end
  class PlaylyfeClient::CollectionFindOneIsNotSupportedError < PlaylyfeClient::Error; end
  class PlaylyfeClient::ApiCallsLimitExceededError < PlaylyfeClient::Error; end
  class PlaylyfeClient::ActionPlayedWithoutRequiredVariables < PlaylyfeClient::ActionError; end
  class PlaylyfeClient::ActionPlayedWithWrongVariables < PlaylyfeClient::ActionError; end

  class Error < StandardError
    attr_accessor :name, :message
    def initialize(res=nil,uri=nil)
      @raw = res
      unless res.nil? || res == ""
        res = JSON.parse(res)
        @name = res['error']
        @message = res['error_description']
        @message+=" [request: #{uri}]" unless uri.nil?
      end  
    end
    
    def self.build(res=nil,uri=nil)
      err_class= PlaylyfeClient::ConnectionError
      unless res.nil? || res == ""
        res_h = JSON.parse(res)
        if res_h['error'] == "rate_limit_exceeded"
          err_class= PlaylyfeClient::ActionRateLimitExceededError
        elsif res_h['error'] == "player_exists"
          err_class= PlaylyfeClient::PlayerExistsError
        elsif res_h['error'] == "plan_limit_exceeded"
          err_class= PlaylyfeClient::ApiCallsLimitExceededError
              
        end  
      end  
      err_class.new(res, uri)
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
playlyfe_client-1.1.6 lib/playlyfe_client/errors.rb
playlyfe_client-1.1.5 lib/playlyfe_client/errors.rb