quickbooks_api 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -72,7 +72,7 @@ def hash_to_obj(data)
72
72
  key = data.keys.first
73
73
  value = data[key]
74
74
 
75
- key_path = find_nested_key(container.template(true), key)
75
+ key_path = find_nested_key(container.template(true), key.to_s)
76
76
  raise(RuntimeError, "#{key} class not found in api template") unless key_path
77
77
 
78
78
  wrapped_data = build_hash_wrapper(key_path, value)
@@ -36,6 +36,7 @@ def build_qbxml_class(xml_obj)
36
36
  unless qbxml_class_defined?(obj_name)
37
37
  klass = Class.new(QbxmlBase)
38
38
  get_schema_namespace.const_set(obj_name, klass)
39
+ xml_obj = set_required_attributes(xml_obj)
39
40
  add_xml_template(klass, xml_obj.to_xml)
40
41
  else
41
42
  klass = get_schema_namespace.const_get(obj_name)
@@ -6,38 +6,22 @@ class Quickbooks::QbxmlBase
6
6
  extend Quickbooks::Support
7
7
  extend Quickbooks::Support::API
8
8
 
9
- #QB_TYPE_CONVERSION_MAP= {
10
- #"AMTTYPE" => lambda {|d| String(d)},
11
- #"BOOLTYPE" => lambda {|d| String(d)},
12
- #"DATETIMETYPE" => lambda {|d| Date.parse(d)},
13
- #"DATETYPE" => lambda {|d| Date.parse(d)},
14
- #"ENUMTYPE" => lambda {|d| String(d)},
15
- #"FLOATTYPE" => lambda {|d| String(d)},
16
- #"GUIDTYPE" => lambda {|d| String(d)},
17
- #"IDTYPE" => lambda {|d| String(d)},
18
- #"INTTYPE" => lambda {|d| Integer(d)},
19
- #"PERCENTTYPE" => lambda {|d| Float(d)},
20
- #"PRICETYPE" => lambda {|d| Float(d)},
21
- #"QUANTYPE" => lambda {|d| Integer(d)},
22
- #"STRTYPE" => lambda {|d| String(d)},
23
- #"TIMEINTERVALTYPE" => lambda {|d| String(d)}
24
- #}
25
-
26
9
  QB_TYPE_CONVERSION_MAP= {
27
- "AMTTYPE" => lambda {|d| String(d)},
28
- "BOOLTYPE" => lambda {|d| String(d)},
29
- "DATETIMETYPE" => lambda {|d| String(d)},
30
- "DATETYPE" => lambda {|d| String(d)},
31
- "ENUMTYPE" => lambda {|d| String(d)},
32
- "FLOATTYPE" => lambda {|d| String(d)},
33
- "GUIDTYPE" => lambda {|d| String(d)},
34
- "IDTYPE" => lambda {|d| String(d)},
35
- "INTTYPE" => lambda {|d| String(d)},
36
- "PERCENTTYPE" => lambda {|d| String(d)},
37
- "PRICETYPE" => lambda {|d| String(d)},
38
- "QUANTYPE" => lambda {|d| String(d)},
39
- "STRTYPE" => lambda {|d| String(d)},
40
- "TIMEINTERVALTYPE" => lambda {|d| String(d)}
10
+ "AMTTYPE" => lambda {|d| d ? Float(d) : 0.0 },
11
+ #"BOOLTYPE" => lambda {|d| d ? (d == 'True' ? true : false) : false },
12
+ "BOOLTYPE" => lambda {|d| d ? String(d) : '' },
13
+ "DATETIMETYPE" => lambda {|d| d ? Time.parse(d).xmlschema : Time.now.xmlschema },
14
+ "DATETYPE" => lambda {|d| d ? Date.parse(d).xmlschema : Date.today.xmlschema },
15
+ "ENUMTYPE" => lambda {|d| d ? String(d) : ''},
16
+ "FLOATTYPE" => lambda {|d| d ? Float(d) : 0.0},
17
+ "GUIDTYPE" => lambda {|d| d ? String(d) : ''},
18
+ "IDTYPE" => lambda {|d| d ? String(d) : ''},
19
+ "INTTYPE" => lambda {|d| d ? Integer(d) : 0 },
20
+ "PERCENTTYPE" => lambda {|d| d ? Float(d) : 0.0 },
21
+ "PRICETYPE" => lambda {|d| d ? Float(d) : 0.0 },
22
+ "QUANTYPE" => lambda {|d| d ? Integer(d.to_i) : 0 },
23
+ "STRTYPE" => lambda {|d| d ? String(d) : ''},
24
+ "TIMEINTERVALTYPE" => lambda {|d| d ? String(d) : ''}
41
25
  }
42
26
 
43
27
 
@@ -101,7 +85,9 @@ def inner_attributes
101
85
  end
102
86
 
103
87
  values = top_level_attrs.values.compact
104
- if values.size > 1 || values.first.is_a?(Array)
88
+ if values.empty?
89
+ {}
90
+ elsif values.size > 1 || values.first.is_a?(Array)
105
91
  attributes
106
92
  else
107
93
  values.first.inner_attributes
@@ -92,5 +92,4 @@ def set_attribute_value(instance, attr_name, data)
92
92
  end
93
93
  end
94
94
 
95
-
96
95
  end
@@ -9,10 +9,16 @@ module Quickbooks::Support::API
9
9
  :qb => {:dtd_file => "qbxmlops70.xml",
10
10
  :namespace => QBXML,
11
11
  :container_class => lambda { Quickbooks::QBXML::QBXML },
12
+ :required_xml_attributes => {
13
+ "onError" => "stopOnError"
14
+ }
12
15
  }.freeze,
13
16
  :qbpos => {:dtd_file => "qbposxmlops30.xml",
14
17
  :namespace => QBPOSXML,
15
18
  :container_class => lambda { Quickbooks::QBPOSXML::QBPOSXML },
19
+ :required_xml_attributes => {
20
+ "onError" => "stopOnError"
21
+ }
16
22
  }.freeze,
17
23
  }.freeze
18
24
 
@@ -48,6 +54,10 @@ private
48
54
  "#{RUBY_SCHEMA_PATH}/#{schema_type.to_s}/templates"
49
55
  end
50
56
 
57
+ def get_required_xml_attributes
58
+ SCHEMA_MAP[schema_type][:required_xml_attributes]
59
+ end
60
+
51
61
  # fetches all the dynamically generated schema classes
52
62
  def cached_classes
53
63
  cached_classes = SCHEMA_MAP.inject({}) do |h, (schema_type, opts)|
@@ -11,9 +11,10 @@ def add_strict_attribute(klass, attr_name, type)
11
11
 
12
12
  def #{attr_name}=(obj)
13
13
  expected_type = self.class.#{attr_name}_type
14
- if obj.class == expected_type
14
+ case obj
15
+ when expected_type, Array
15
16
  @#{attr_name} = obj
16
- elsif obj.is_a?(Hash)
17
+ when Hash
17
18
  @#{attr_name} = #{type}.new(obj)
18
19
  else
19
20
  raise(TypeError, "expecting an object of type \#{expected_type}")
@@ -25,8 +26,8 @@ end
25
26
 
26
27
  def add_casting_attribute(klass, attr_name, type)
27
28
  type_casting_proc = klass::QB_TYPE_CONVERSION_MAP[type]
28
- type = type_casting_proc.call(nil).class
29
- add_attribute_type(klass, attr_name, type)
29
+ ruby_type = type_casting_proc.call(nil).class
30
+ add_attribute_type(klass, attr_name, ruby_type)
30
31
 
31
32
  eval <<-class_body
32
33
  class #{klass}
@@ -28,4 +28,16 @@ module Quickbooks::Support::QBXML
28
28
  qbxml.join('')
29
29
  end
30
30
 
31
+ def set_required_attributes(xml_obj)
32
+ required_attributes = get_required_xml_attributes
33
+ xml_obj.attributes.each do |a,v|
34
+ if required_attributes.keys.include?(a)
35
+ xml_obj.set_attribute(a, required_attributes[a])
36
+ else
37
+ xml_obj.remove_attribute(a)
38
+ end
39
+ end
40
+ xml_obj
41
+ end
42
+
31
43
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quickbooks_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Skryl
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-15 00:00:00 -05:00
18
+ date: 2011-06-17 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency