Class: MonoMerchant::ApiRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/mono-merchant/api_request.rb

Constant Summary collapse

API_URL =
"https://api.monobank.ua/api"
DEFAULT_CURRENCY =
"UAH"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: :post) ⇒ ApiRequest

Returns a new instance of ApiRequest.



11
12
13
14
15
# File 'lib/mono-merchant/api_request.rb', line 11

def initialize(type: :post)
  @type = type
  @errors = []
  response
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)



77
78
79
80
81
82
# File 'lib/mono-merchant/api_request.rb', line 77

def method_missing(name, *args)
  cam_name = name.to_s.camelize(:lower)
  return super unless data.include?(cam_name)

  response[cam_name] if response
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/mono-merchant/api_request.rb', line 9

def errors
  @errors
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/mono-merchant/api_request.rb', line 9

def type
  @type
end

Instance Method Details

#urlObject



17
18
19
# File 'lib/mono-merchant/api_request.rb', line 17

def url
  "#{API_URL}/#{self.class.name.underscore.dasherize.sub('mono-', '')}#{url_query}"
end