Class: AxiomusApi::Base
Direct Known Subclasses
BaseAuth, BaseOrder, EmsAddress, ExportServices, Item, PostAddress, PostServices, RegionCourierAddress, RegionPickupAddress, RegionServices, Request, Services
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.
61
62
63
64
65
66
67
|
# File 'lib/axiomus_api/base.rb', line 61
def initialize
self.class.attribute_meta.each do |k, v|
if v[:type]
self.send("#{k}=".to_sym, v[:type].new)
end
end
end
|
Class Method Details
32
33
34
35
|
# File 'lib/axiomus_api/base.rb', line 32
def self.attribute_meta
res = superclass.respond_to?(:attribute_meta) ? superclass.attribute_meta : {}
res.merge(@attr_info || {})
end
|
53
54
55
56
57
58
59
|
# File 'lib/axiomus_api/base.rb', line 53
def self.(args)
if args.last.is_a?(Hash) && args.last.instance_of?(Hash)
args.pop
else
{}
end
end
|
.tag_name ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/axiomus_api/base.rb', line 37
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].include?(k)
end
args.each do |attr_name|
@attr_info ||= {}
@attr_info[attr_name] = options
attr_accessor attr_name
end
end
|
Instance Method Details
#tag_name ⇒ Object
49
50
51
|
# File 'lib/axiomus_api/base.rb', line 49
def tag_name
self.class.tag_name
end
|