quickbooks_api 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,33 +0,0 @@
1
- # namespace for dynamically gnerated schema classes
2
- module Quickbooks::QBXML; end
3
- module Quickbooks::QBPOSXML; end
4
-
5
- module Quickbooks::Support
6
-
7
- def to_attribute_name(obj)
8
- name = \
9
- case obj
10
- when Class
11
- simple_class_name(obj)
12
- when Nokogiri::XML::Element
13
- obj.name
14
- else
15
- obj.to_s
16
- end
17
- inflector.underscore(name)
18
- end
19
-
20
- def simple_class_name(klass)
21
- klass.to_s.split("::").last
22
- end
23
-
24
- # easily convert between CamelCase and under_score
25
- def inflector
26
- ActiveSupport::Inflector
27
- end
28
-
29
- def log
30
- Quickbooks::API.log
31
- end
32
-
33
- end
@@ -1,98 +0,0 @@
1
- module Quickbooks::Support::API
2
- include Quickbooks
3
-
4
- API_ROOT = File.join(File.dirname(__FILE__), '..', '..', '..').freeze
5
- XML_SCHEMA_PATH = File.join(API_ROOT, 'xml_schema').freeze
6
- RUBY_SCHEMA_PATH = File.join(API_ROOT, 'ruby_schema').freeze
7
-
8
- SCHEMA_MAP = {
9
- :qb => {:dtd_file => "qbxmlops70.xml",
10
- :namespace => QBXML,
11
- :container_class => lambda { Quickbooks::QBXML::QBXML },
12
- :required_xml_attributes => {
13
- "onError" => "stopOnError"
14
- }
15
- }.freeze,
16
- :qbpos => {:dtd_file => "qbposxmlops30.xml",
17
- :namespace => QBPOSXML,
18
- :container_class => lambda { Quickbooks::QBPOSXML::QBPOSXML },
19
- :required_xml_attributes => {
20
- "onError" => "stopOnError"
21
- }
22
- }.freeze,
23
- }.freeze
24
-
25
- DEFAULT_LOG_LEVEL = 1
26
-
27
- private
28
-
29
- def valid_schema_types
30
- SCHEMA_MAP.keys
31
- end
32
-
33
- def valid_schema_type?
34
- SCHEMA_MAP.include?(schema_type)
35
- end
36
-
37
- def get_dtd_file
38
- "#{XML_SCHEMA_PATH}/#{SCHEMA_MAP[schema_type][:dtd_file]}"
39
- end
40
-
41
- def get_schema_namespace
42
- SCHEMA_MAP[schema_type][:namespace]
43
- end
44
-
45
- def get_container_class
46
- SCHEMA_MAP[schema_type][:container_class].call
47
- end
48
-
49
- def get_disk_cache_path
50
- "#{RUBY_SCHEMA_PATH}/#{schema_type.to_s}"
51
- end
52
-
53
- def get_template_cache_path
54
- "#{RUBY_SCHEMA_PATH}/#{schema_type.to_s}/templates"
55
- end
56
-
57
- def get_required_xml_attributes
58
- SCHEMA_MAP[schema_type][:required_xml_attributes]
59
- end
60
-
61
- # fetches all the dynamically generated schema classes
62
- def cached_classes
63
- cached_classes = SCHEMA_MAP.inject({}) do |h, (schema_type, opts)|
64
- namespace = opts[:namespace]
65
- h[schema_type] = namespace.constants.map { |klass| namespace.const_get(klass) }; h
66
- end
67
- cached_classes[schema_type]
68
- end
69
-
70
- def is_cached_class?(klass)
71
- SCHEMA_MAP.any? do |schema_type, opts|
72
- namespace = opts[:namespace]
73
- namespace.constants.include?(simple_class_name(klass))
74
- end
75
- end
76
-
77
- def find_nested_key(hash, key)
78
- hash.each do |k,v|
79
- path = [k]
80
- if k == key
81
- return path
82
- elsif v.is_a? Hash
83
- nested_val = find_nested_key(v, key)
84
- nested_val ? (return path + nested_val) : nil
85
- end
86
- end
87
- return nil
88
- end
89
-
90
- def build_hash_wrapper(path, value)
91
- hash_constructor = lambda { |h, k| h[k] = Hash.new(&hash_constructor) }
92
-
93
- wrapped_data = Hash.new(&hash_constructor)
94
- path.inject(wrapped_data) { |h, k| k == path.last ? h[k] = value: h[k] }
95
- wrapped_data
96
- end
97
-
98
- end
@@ -1,56 +0,0 @@
1
- require 'forwardable'
2
-
3
- class Quickbooks::Support::Logger
4
- extend Forwardable
5
-
6
- def_delegators :@logger, :level, :flush, :auto_flushing=
7
-
8
- DEFAULT_FORMATTER = "%s"
9
- DEFAULT_PADDING = ""
10
- PADDING_CHAR = " "
11
-
12
- def initialize(log_file, log_level, log_count = nil, log_size = nil)
13
- @logger = ActiveSupport::BufferedLogger.new(log_file, log_level)
14
- @padding, @formatter = {}, {}
15
- end
16
-
17
- def buffer
18
- buf = @logger.send(:buffer)
19
- buf && buf.join('')
20
- end
21
-
22
- # overwrite all the logging methods
23
- class_eval do
24
- [:debug, :info, :warn, :error, :fatal, :unknown].each do |method|
25
- define_method(method) do |message|
26
- @logger.send(method, (padding + formatter) % message.to_s)
27
- end
28
- end
29
- end
30
-
31
- def indent(indent_level)
32
- @padding[Thread.current] = \
33
- if indent_level == :reset
34
- ""
35
- elsif indent_level > 0
36
- padding + (PADDING_CHAR * indent_level)
37
- else
38
- padding[0..(-1+indent_level)]
39
- end
40
- end
41
-
42
- def formatter=(format)
43
- @formatter[Thread.current] = format
44
- end
45
-
46
- protected
47
-
48
- def padding
49
- @padding[Thread.current] ||= DEFAULT_PADDING
50
- end
51
-
52
- def formatter
53
- @formatter[Thread.current] ||= DEFAULT_FORMATTER
54
- end
55
-
56
- end
File without changes
File without changes
@@ -1,23 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "spec_helper.rb")
2
-
3
- describe Quickbooks::QbxmlBase do
4
-
5
- it "should have a type conversion map with all qb types" do
6
- end
7
-
8
- it "should build up a wrapper object given an attribute hash" do
9
- end
10
-
11
- it "should convert a wrapper object to its equivalent qbxml" do
12
- end
13
-
14
- it "should return the attribute values of the wrapper object" do
15
- end
16
-
17
- it "should return the attribute names of the wrapper class" do
18
- end
19
-
20
- it "should return the type map of the wrapper class" do
21
- end
22
-
23
- end
@@ -1,118 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "spec_helper.rb")
2
-
3
- include Quickbooks::Support
4
- include Quickbooks::Support::QBXML
5
-
6
- describe Quickbooks::Support do
7
-
8
- describe "configuration helpers" do
9
-
10
- it "should return the supported schema types" do
11
- valid_schema_types.should be_an_instance_of(Array)
12
- valid_schema_types.include?(:qb).should be_true
13
- valid_schema_types.include?(:qbpos).should be_true
14
- end
15
-
16
- it "should check if a particular schema type is supported" do
17
- self.stub!(:schema_type => :qb)
18
- valid_schema_type?.should be_true
19
- self.stub!(:schema_type => :qbpos)
20
- valid_schema_type?.should be_true
21
- self.stub!(:schema_type => :doesntexist)
22
- valid_schema_type?.should == false
23
- end
24
-
25
- it "should determine the dtd file path for any supported schema type" do
26
- self.stub!(:schema_type => :qb)
27
- File.exists?(get_dtd_file).should be_true
28
- self.stub!(:schema_type => :qbpos)
29
- File.exists?(get_dtd_file).should be_true
30
- end
31
-
32
- it "should determine the namespace for any supported schema type" do
33
- self.stub!(:schema_type => :qb)
34
- get_schema_namespace.should be_a_kind_of(Module)
35
- self.stub!(:schema_type => :qbpos)
36
- get_schema_namespace.should be_a_kind_of(Module)
37
- end
38
-
39
- it "should determine the container class for any supported schema type" do
40
- end
41
-
42
- it "should return the disk cache path" do
43
- self.stub!(:schema_type => :qb)
44
- File.exists?(get_disk_cache_path).should be_true
45
- end
46
-
47
- end
48
-
49
- describe "other helpers" do
50
-
51
- before :all do
52
- @qb_api = Quickbooks::API.new(:qb)
53
- @qbpos_api = Quickbooks::API.new(:qbpos)
54
- end
55
-
56
- it "should return all the cached classes" do
57
- self.stub!(:schema_type => :qb)
58
- cached_classes.should be_an_instance_of(Array)
59
- cached_classes.empty?.should be_false
60
- self.stub!(:schema_type => :qbpos)
61
- cached_classes.should be_an_instance_of(Array)
62
- cached_classes.empty?.should be_false
63
- end
64
-
65
- it "should check if a particular class is cached" do
66
- self.stub!(:schema_type => :qb)
67
- is_cached_class?(Quickbooks::QBXML::QBXML).should be_true
68
- self.stub!(:schema_type => :qbpos)
69
- is_cached_class?(Quickbooks::QBPOSXML::QBPOSXML).should be_true
70
- end
71
-
72
- end
73
-
74
- end
75
-
76
- describe Quickbooks::Support::QBXML do
77
-
78
- it "should set useful parsing constants" do
79
- XML_DOCUMENT.should == Nokogiri::XML::Document
80
- XML_NODE_SET.should == Nokogiri::XML::NodeSet
81
- XML_NODE.should == Nokogiri::XML::Node
82
- XML_ELEMENT.should == Nokogiri::XML::Element
83
- XML_COMMENT= Nokogiri::XML::Comment
84
- XML_TEXT.should == Nokogiri::XML::Text
85
- end
86
-
87
- describe "xml parsing helpers" do
88
-
89
- before :each do
90
- @klass = Nokogiri::XML::NodeSet
91
- stub_child = stub(:class => XML_TEXT)
92
- @stub_xml_node = stub(:name => "SomeNodeName", :children => [stub_child])
93
- @stub_xml_node.stub!(:is_a?).with(anything).and_return(false)
94
- @stub_xml_node.stub!(:is_a?).with(XML_ELEMENT).and_return(true)
95
- end
96
-
97
- it "should check if a node is a leaf node" do
98
- is_leaf_node?(@stub_xml_node).should be_true
99
- end
100
-
101
- it "should convert a class or xml element name to underscored" do
102
- to_attribute_name(@klass).should == 'node_set'
103
- to_attribute_name(@stub_xml_node).should == 'some_node_name'
104
- end
105
-
106
- it "should convert a full class name to a simple class name" do
107
- simple_class_name(@klass).should == 'NodeSet'
108
- end
109
-
110
- end
111
-
112
- it "should check if a class is already defined in a particular namespace" do
113
- end
114
-
115
- it "should cleanup qbxml" do
116
- end
117
-
118
- end