Class: AxiomusApi::Base
Direct Known Subclasses
BaseAuth, BaseOrder, Below, Delivset, DpdServices, EmsAddress, EmsServices, ExportItems, ExportServices, Item, Items, PostAddress, PostServices, RegionCourierAddress, RegionPickupAddress, RegionServices, Request, Services, StatusListRequest::Okey, StatusListRequest::Okeylist
Instance Attribute Summary
Attributes included from Validated
#validation_errors
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Validated
#valid?
#to_xml
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
65
66
67
68
69
70
71
72
73
|
# File 'lib/axiomus_api/base.rb', line 65
def initialize
self.class.attribute_meta.each do |k, v|
if v[:array]
self.send("#{k}=".to_sym, [])
elsif v[:type]
self.send("#{k}=".to_sym, v[:type].new)
end
end
end
|
Class Method Details
36
37
38
39
|
# File 'lib/axiomus_api/base.rb', line 36
def self.attribute_meta
res = superclass.respond_to?(:attribute_meta) ? superclass.attribute_meta : {}
res.merge(@attr_info || {})
end
|
57
58
59
60
61
62
63
|
# File 'lib/axiomus_api/base.rb', line 57
def self.(args)
if args.last.is_a?(Hash) && args.last.instance_of?(Hash)
args.pop
else
{}
end
end
|
.tag_name ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/axiomus_api/base.rb', line 41
def self.tag_name
if @xml_element.nil?
if superclass.respond_to?(:tag_name)
superclass.tag_name
else
raise 'xml_element not specified'
end
else
@xml_element
end
end
|
.xml_attribute(*args) ⇒ Object
26
27
28
29
30
|
# File 'lib/axiomus_api/base.rb', line 26
def self.xml_attribute(*args)
options = (args)
args << options.merge({xml_type: :attribute})
xml_field(*args)
end
|
.xml_element(element_name) ⇒ Object
8
9
10
|
# File 'lib/axiomus_api/base.rb', line 8
def self.xml_element(element_name)
@xml_element = element_name
end
|
.xml_field(*args) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/axiomus_api/base.rb', line 12
def self.xml_field(*args)
options = (args)
options.keys.each do |k|
raise "Wrong attribute #{k}" if ![:xml_type, :xml_name, :optional, :type, :array, :max_occurs].include?(k)
end
args.each do |attr_name|
@attr_info ||= {}
@attr_info[attr_name] = options
attr_accessor attr_name
end
end
|
.xml_field_array(name, options = {}) ⇒ Object
32
33
34
|
# File 'lib/axiomus_api/base.rb', line 32
def self.xml_field_array(name, options = {})
xml_field(name, options.merge({array: true}))
end
|
Instance Method Details
#tag_name ⇒ Object
53
54
55
|
# File 'lib/axiomus_api/base.rb', line 53
def tag_name
self.class.tag_name
end
|