Class: Musoni::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/musoni_ruby/endpoints/_endpoint.rb

Direct Known Subclasses

Client, Datatable, Loan, RunReport, SavingsAccount, Transaction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: nil, **keyword_args) ⇒ Endpoint

Musoni::Model.new(options={})



7
8
9
10
11
12
13
14
15
16
# File 'lib/musoni_ruby/endpoints/_endpoint.rb', line 7

def initialize(config:nil,**keyword_args)
  @attributes = Hashie::Mash.new(keyword_args)
  keyword_args.each do |k,v|
    self.send("#{k.to_s}=",v) rescue nil
  end
  @config = set_config(config)
   # @is_new ||= true
   @pagination  ||= {}
   after_initialize
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object (protected)



109
110
111
112
113
114
115
# File 'lib/musoni_ruby/endpoints/_endpoint.rb', line 109

def method_missing(m, *args, &block)
  if @response.is_a?(Hash)
    @response.keys.include?(m.to_s) ? @response.send(m) : super
  else
    super
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'lib/musoni_ruby/endpoints/_endpoint.rb', line 3

def attributes
  @attributes
end

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/musoni_ruby/endpoints/_endpoint.rb', line 3

def config
  @config
end

#endpointObject

Returns the value of attribute endpoint.



3
4
5
# File 'lib/musoni_ruby/endpoints/_endpoint.rb', line 3

def endpoint
  @endpoint
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/musoni_ruby/endpoints/_endpoint.rb', line 4

def id
  @id
end

#paginationObject

Returns the value of attribute pagination.



3
4
5
# File 'lib/musoni_ruby/endpoints/_endpoint.rb', line 3

def pagination
  @pagination
end

#responseObject

Returns the value of attribute response.



3
4
5
# File 'lib/musoni_ruby/endpoints/_endpoint.rb', line 3

def response
  @response
end

Instance Method Details

#fail?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
# File 'lib/musoni_ruby/endpoints/_endpoint.rb', line 18

def fail?
  if %w(Net::HTTP::Post Net::HTTP::Put Net::HTTP::Patch).include?(response.request.http_method.to_s)
    response.code.to_s.match(/\A2\d+/).to_s.empty? or response.resourceId.nil?
  else
    response.code.to_s.match(/\A2\d+/).to_s.empty?
  end 
rescue
  true
end

#success?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/musoni_ruby/endpoints/_endpoint.rb', line 28

def success?
  !fail?
  # if post and there is resource id and response code is 200 then success? = true
  # if post and there is resource id and response code is 200 then success? = true
  # !response.code.to_s.match(/\A2\d+/).to_s.empty? rescue false
end