Class: Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rave_ruby/rave_objects/base/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rave_object = nil) ⇒ Base

method to initialize this class



12
13
14
15
16
17
# File 'lib/rave_ruby/rave_objects/base/base.rb', line 12

def initialize(rave_object=nil)
  unless !rave_object.nil?
    raise ArgumentError, "Rave Object is required!!!"
  end
  @rave_object = rave_object
end

Instance Attribute Details

#get_hashed_keyObject (readonly)

method to get the hashed secret key



21
22
23
# File 'lib/rave_ruby/rave_objects/base/base.rb', line 21

def get_hashed_key
  @get_hashed_key
end

#rave_objectObject (readonly)

Returns the value of attribute rave_object.



8
9
10
# File 'lib/rave_ruby/rave_objects/base/base.rb', line 8

def rave_object
  @rave_object
end

Instance Method Details

#check_passed_parameters(required_params, passed_params) ⇒ Object

method to check if the passed parameters is equal to the expected parameters



82
83
84
85
86
87
88
89
90
91
# File 'lib/rave_ruby/rave_objects/base/base.rb', line 82

def check_passed_parameters(required_params, passed_params)

  # This is used to check if the passed authorization parameters matches the required parameters
  required_params.each do |k, v|
    if !passed_params.key?(k)
      raise IncompleteParameterError, "Parameters Incomplete, Missing Parameter: #{k}, Please pass in the complete parameter."
    end
    # return true
  end
end

#get_request(endpoint, data = {}) ⇒ Object

method to make a get request



31
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
# File 'lib/rave_ruby/rave_objects/base/base.rb', line 31

def get_request(endpoint, data={})
  http_params = {}
  unless data.empty?
    http_params[:query] = data
  end

  begin
    response = HTTParty.get(endpoint, http_params)
    unless (response.code == 200 || response.code == 201)
      raise RaveServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
    end

    # response_body = response.body

    return response

    unless(response.code != 0 )
      raise RaveServerError.new(response), "Server Message: #{response.message}"
    end

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

    # rescue RaveServerError => e
    #   Util.serverErrorHandler(e)
    # end	

      return response
    end
end

#handle_list_bank(response) ⇒ Object

method to handle list bank response



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rave_ruby/rave_objects/base/base.rb', line 94

def handle_list_bank(response)
  list_bank = response

  if list_bank.code == 200
      response = {"error" => false, "data" => JSON.parse(list_bank.body)}
      return response
  else
      response = {"error" => true, "data" => JSON.parse(list_bank.body)}
      return response
      # raise InitiateTransferError, response
  end
end

#post_request(endpoint, data) ⇒ Object

method to make a post request



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rave_ruby/rave_objects/base/base.rb', line 63

def post_request(endpoint, data)
  begin
    response = HTTParty.post(endpoint, {
      body: data,
      headers: {
        'Content-Type' => 'application/json'
      }
    })

    unless (response.code == 200 || response.code == 201)
      raise RaveServerError.new(response), "HTTP Code #{response.code}: #{response.body}"
    end

    return response
  end

end