Class: ZipMoney::Query

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/zipMoney/api/query.rb

Instance Attribute Summary collapse

Attributes included from Request

#errors

Instance Method Summary collapse

Methods included from Request

#validate_item_details

Constructor Details

#initializeQuery

Initializes a ZipMoney::Query object

Returns ZipMoney::Query object



13
14
15
16
17
18
# File 'lib/zipMoney/api/query.rb', line 13

def initialize 
  @params      = Struct::QueryParams.new      
  @params.orders   = Array.new
  @params. = Struct::Metadata.new
  @params.version  = Struct::Version.new
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/zipMoney/api/query.rb', line 5

def params
  @params
end

Instance Method Details

#doObject

Performs the Query api call on zipMoney endpoint

Returns ZipMoney::Query object



23
24
25
26
# File 'lib/zipMoney/api/query.rb', line 23

def do  
  validate
  ZipMoney.api.query(@params)
end

#validateObject

Performs the parameters validation

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/zipMoney/api/query.rb', line 29

def validate
  raise ArgumentError, "Params emtpy" if @params.nil? 
  @errors = []
  @errors << 'at least one order must be provided' unless @params.orders.length > 0

  @params.orders.each_with_index do |item,index|
    @errors << "order.detail[#{index}].id must be provided" if item.id.nil? 
  end 

  raise ZipMoney::RequestError.new("Following error(s) occurred while making request, please resolve them to make the request: #{@errors}") if @errors.any?
end