Class: NovaPoshtaApi::Base

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

Direct Known Subclasses

Request

Class Method Summary collapse

Class Method Details

.class_attr_accessor(*names) ⇒ Object



3
4
5
6
7
8
# File 'lib/nova_poshta_api/base.rb', line 3

def self.class_attr_accessor(*names)
  names.each do |name|
    define_singleton_method("#{name.to_s}=".to_sym){ |attr| class_variable_set("@@#{name}", attr) }
    define_singleton_method(name.to_sym){ class_variable_get("@@#{name}") }
  end
end

.make_body(model, meth, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/nova_poshta_api/base.rb', line 21

def make_body(model, meth, options={})
  {
    'modelName'         => model,
    'calledMethod'      => meth,
    'methodProperties'  => options,
    'apiKey'            => api_key
  }
end

.post_request(body) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/nova_poshta_api/base.rb', line 13

def post_request(body)
  response = perform_request body
  format_response response
rescue => e
  puts e
  {}
end