class PaystackBaseObject

Attributes

paystack[R]

Public Class Methods

new(paystackObj) click to toggle source
# File lib/paystack/objects/base.rb, line 6
def initialize(paystackObj)
        unless !paystackObj.nil?
                raise ArgumentError, "Paystack object cannot be nil!!"
        end
        @paystack = paystackObj
end

Protected Class Methods

initDeleteRequest(paystackObj, url) click to toggle source
# File lib/paystack/objects/base.rb, line 83
def self.initDeleteRequest(paystackObj, url) 
        result = nil
        begin
                response =  RestClient.delete "#{API::BASE_URL}#{url}" ,  :Authorization  => "Bearer #{paystackObj.private_key}"
                unless (response.code == 200 || response.code == 201)
                                raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
                end
                result = JSON.parse(response.body)
                unless(result['status'] != 0 )
                        raise PaystackServerError.new(response), "Server Message: #{result['message']}"
                end

        rescue JSON::ParserError => jsonerr
                raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"

        rescue PaystackServerError => e
                Utils.serverErrorHandler(e)
        end   
        return result
end
initGetRequest(paystackObj, url) click to toggle source

>Static methods

# File lib/paystack/objects/base.rb, line 15
def self.initGetRequest(paystackObj, url) 
        result = nil
        begin
                response = RestClient.get "#{API::BASE_URL}#{url}" , :Authorization  => "Bearer #{paystackObj.private_key}", :content_type => :json, :accept => :json
                unless (response.code == 200 || response.code == 201)
                                raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
                end
                result = JSON.parse(response.body)
                unless(result['status'] != 0 )
                        raise PaystackServerError.new(response), "Server Message: #{result['message']}"
                end

        rescue JSON::ParserError => jsonerr
                raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"

        rescue PaystackServerError => e
                Utils.serverErrorHandler(e)
        end   
        return result
end
initPostRequest(paystackObj, url, data = {}, json=false ) click to toggle source
# File lib/paystack/objects/base.rb, line 36
    def self.initPostRequest(paystackObj, url, data = {}, json=false ) 
            result = nil
begin
                    if !json
                            response =  RestClient.post "#{API::BASE_URL}#{url}" , data,  :authorization  => "Bearer #{paystackObj.private_key}"
                    else
                            response =  RestClient.post "#{API::BASE_URL}#{url}" , data.to_json,  :authorization  => "Bearer #{paystackObj.private_key}", :content_type => :json, :accept => :json
            
                    end
                    unless (response.code == 200 || response.code == 201)
                                    raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
                    end
                    result = JSON.parse(response.body)
                    unless(result['status'] != 0 )
                            raise PaystackServerError.new(response), "Server Message: #{result['message']}"
                    end

            rescue JSON::ParserError => jsonerr
                    raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"

            rescue PaystackServerError => e
                    Utils.serverErrorHandler(e)
            end   
            return result
    end
initPutRequest(paystackObj, url, data = {} ) click to toggle source
# File lib/paystack/objects/base.rb, line 62
def self.initPutRequest(paystackObj, url, data = {} ) 
        result = nil
        begin
                response =  RestClient.put "#{API::BASE_URL}#{url}" , data,  :Authorization  => "Bearer #{paystackObj.private_key}"
                unless (response.code == 200 || response.code == 201)
                                raise PaystackServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
                end
                result = JSON.parse(response.body)
                unless(result['status'] != 0 )
                        raise PaystackServerError.new(response), "Server Message: #{result['message']}"
                end

        rescue JSON::ParserError => jsonerr
                raise PaystackServerError.new(response) , "Invalid result data. Could not parse JSON response body \n #{jsonerr.message}"

        rescue PaystackServerError => e
                Utils.serverErrorHandler(e)
        end   
        return result
end