Sha256: 88dc9715258301f6c963db5d475aa83d4ba0259041c4da5f1c414224520398bc

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'cookie_jar/account'
require 'cookie_jar/transfer'
require 'cookie_jar/banker'

module CookieJar
  module Wallet
    class User < WalletBase
    include CookieJar::Wallet::Account
    include CookieJar::Wallet::Transfer

      def all_users
        self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/users"
        response = self.get

        #for successful response, self.get will return array. unless it will return error hash
        if response.is_a?(Hash)
          raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
        end

        response
      end

      def get_user(user_id=self.user_id)
        self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/users/#{user_id}"
        response = self.get

        raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource"  or response[:code] == 401

        response
      end

      def get_balance
        self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/users/#{user_id}/balance"
        response = self.get

        raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource"  or response[:code] == 401

        response
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cookie_jar-0.0.1 lib/cookie_jar/user.rb