intacct_ruby 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +173 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/intacct_ruby.gemspec +37 -0
  13. data/lib/intacct_ruby.rb +24 -0
  14. data/lib/intacct_ruby/api.rb +31 -0
  15. data/lib/intacct_ruby/exceptions/function_failure_exception.rb +5 -0
  16. data/lib/intacct_ruby/functions/base_function.rb +46 -0
  17. data/lib/intacct_ruby/functions/create_aradjustment.rb +48 -0
  18. data/lib/intacct_ruby/functions/create_customer.rb +23 -0
  19. data/lib/intacct_ruby/functions/create_employee.rb +21 -0
  20. data/lib/intacct_ruby/functions/create_item.rb +21 -0
  21. data/lib/intacct_ruby/functions/create_location.rb +21 -0
  22. data/lib/intacct_ruby/functions/create_project.rb +20 -0
  23. data/lib/intacct_ruby/functions/customer_base_function.rb +26 -0
  24. data/lib/intacct_ruby/functions/employee_base_function.rb +36 -0
  25. data/lib/intacct_ruby/functions/item_base_function.rb +29 -0
  26. data/lib/intacct_ruby/functions/location_base_function.rb +24 -0
  27. data/lib/intacct_ruby/functions/project_base_function.rb +22 -0
  28. data/lib/intacct_ruby/functions/update_customer.rb +22 -0
  29. data/lib/intacct_ruby/functions/update_employee.rb +20 -0
  30. data/lib/intacct_ruby/functions/update_item.rb +20 -0
  31. data/lib/intacct_ruby/functions/update_location.rb +20 -0
  32. data/lib/intacct_ruby/functions/update_project.rb +20 -0
  33. data/lib/intacct_ruby/helpers/contacts_helper.rb +32 -0
  34. data/lib/intacct_ruby/helpers/date_helper.rb +22 -0
  35. data/lib/intacct_ruby/request.rb +88 -0
  36. data/lib/intacct_ruby/response.rb +43 -0
  37. data/lib/intacct_ruby/version.rb +3 -0
  38. metadata +217 -0
@@ -0,0 +1,22 @@
1
+ require 'builder'
2
+
3
+ module IntacctRuby
4
+ # methods to help generate date XML for calls
5
+ module DateHelper
6
+ def date_params(block_name, attrs = {})
7
+ xml = Builder::XmlMarkup.new
8
+
9
+ xml.tag!(block_name) do
10
+ xml.year attrs[:year]
11
+ xml.month attrs[:month]
12
+ xml.day attrs[:day]
13
+ end
14
+ end
15
+
16
+ # Note: @attrs[:startdate] MUST be defined in the invoking context for this
17
+ # bad boy to work
18
+ def start_date_params
19
+ date_params :startdate, @attrs[:startdate]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,88 @@
1
+ require 'builder'
2
+ require 'figaro'
3
+
4
+ require 'intacct_ruby/api'
5
+ require 'intacct_ruby/response'
6
+
7
+ module IntacctRuby
8
+ # An outgoing request to the Intacct API. Can have multiple functions.
9
+ # Complete with send method that gets (and wraps) response from Intacct.
10
+ class Request
11
+ DEFAULTS = {
12
+ uniqueid: false,
13
+ dtdversion: 3.0,
14
+ includewhitespace: false,
15
+ transaction: true
16
+ }.freeze
17
+
18
+ def initialize(*args)
19
+ @opts = DEFAULTS.dup
20
+
21
+ # `args` should be a list of Intacct::Function objects, with the last
22
+ # argument optionally providing overrides to request defaults
23
+ @opts.merge!(args.pop) if args.last.is_a? Hash
24
+
25
+ # If a hash is provided + popped, the remaining attrs are functions
26
+ @functions = args
27
+ end
28
+
29
+ def to_xml
30
+ @request = Builder::XmlMarkup.new
31
+
32
+ request.instruct!
33
+ request.request do
34
+ control_block
35
+ operation_block
36
+ end
37
+ end
38
+
39
+ def send(api = nil)
40
+ api ||= Api.new
41
+
42
+ Response.new api.send(self)
43
+ end
44
+
45
+ private
46
+
47
+ attr_reader :request, :functions
48
+
49
+ def timestamp
50
+ @timestamp ||= Time.now.utc.to_s
51
+ end
52
+
53
+ def control_block
54
+ request.control do
55
+ request.senderid Figaro.env.intacct_senderid
56
+ request.password Figaro.env.intacct_sender_password
57
+
58
+ # As recommended by Intacct API reference. This ID should be unique
59
+ # to the call: it's used to associate a response with a request.
60
+ request.controlid timestamp
61
+ request.uniqueid @opts[:uniqueid]
62
+ request.dtdversion @opts[:dtdversion]
63
+ request.includewhitespace @opts[:includewhitespace]
64
+ end
65
+ end
66
+
67
+ def authentication_block
68
+ request.authentication do
69
+ request.login do
70
+ request.userid Figaro.env.intacct_userid
71
+ request.companyid Figaro.env.intacct_companyid
72
+ request.password Figaro.env.intacct_user_password
73
+ end
74
+ end
75
+ end
76
+
77
+ def operation_block
78
+ request.operation transaction: @opts[:transaction] do
79
+ authentication_block
80
+ request.content do
81
+ functions.each do |function|
82
+ request << function.to_xml
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,43 @@
1
+ require 'nokogiri'
2
+ require 'intacct_ruby/exceptions/function_failure_exception'
3
+
4
+ module IntacctRuby
5
+ # Wraps an XML API response, throwing an exception if the call was unsucessful
6
+ #
7
+ # This class *can* be instantiated on its own, but only in cases where the
8
+ # contents of the response (e.g. generated keys, query results) aren't
9
+ # important.
10
+ #
11
+ # If, for example, a key returned needs to be extracted from the response,
12
+ # extend this class and add methods that access whatever data is required.
13
+ class Response
14
+ attr_reader :response_body
15
+
16
+ def initialize(xml_response)
17
+ @response_body = Nokogiri::XML(xml_response.body)
18
+
19
+ # raises an error unless the response is in the 2xx range.
20
+ xml_response.value
21
+
22
+ # in case the response is a success, but one of the included functions
23
+ # failed and the transaction was rolled back
24
+ raise_function_errors unless transaction_successful?
25
+ end
26
+
27
+ def function_errors
28
+ @function_errors ||= @response_body.xpath('//error/description2')
29
+ .map(&:text)
30
+ end
31
+
32
+ private
33
+
34
+ def transaction_successful?
35
+ function_errors.none?
36
+ end
37
+
38
+ def raise_function_errors
39
+ raise Exceptions::FunctionFailureException,
40
+ function_errors.join("\n")
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module IntacctRuby
2
+ VERSION = '0.2.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: intacct_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Zornow
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.6.8
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.6'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.6.8
75
+ - !ruby/object:Gem::Dependency
76
+ name: mocha
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.13.3
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.13.3
89
+ - !ruby/object:Gem::Dependency
90
+ name: pry-byebug
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.4'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 3.4.2
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '3.4'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 3.4.2
109
+ - !ruby/object:Gem::Dependency
110
+ name: builder
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '3.0'
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 3.0.4
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '3.0'
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 3.0.4
129
+ - !ruby/object:Gem::Dependency
130
+ name: figaro
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '1.1'
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 1.1.1
139
+ type: :runtime
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.1'
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: 1.1.1
149
+ description: Allows for multi-function API calls, the addition of custom fields, and
150
+ more. All in an easy-to-use package!
151
+ email:
152
+ - jeremy@zornow.com
153
+ executables: []
154
+ extensions: []
155
+ extra_rdoc_files: []
156
+ files:
157
+ - ".gitignore"
158
+ - ".rspec"
159
+ - ".ruby-version"
160
+ - CODE_OF_CONDUCT.md
161
+ - Gemfile
162
+ - LICENSE.txt
163
+ - README.md
164
+ - Rakefile
165
+ - bin/console
166
+ - bin/setup
167
+ - intacct_ruby.gemspec
168
+ - lib/intacct_ruby.rb
169
+ - lib/intacct_ruby/api.rb
170
+ - lib/intacct_ruby/exceptions/function_failure_exception.rb
171
+ - lib/intacct_ruby/functions/base_function.rb
172
+ - lib/intacct_ruby/functions/create_aradjustment.rb
173
+ - lib/intacct_ruby/functions/create_customer.rb
174
+ - lib/intacct_ruby/functions/create_employee.rb
175
+ - lib/intacct_ruby/functions/create_item.rb
176
+ - lib/intacct_ruby/functions/create_location.rb
177
+ - lib/intacct_ruby/functions/create_project.rb
178
+ - lib/intacct_ruby/functions/customer_base_function.rb
179
+ - lib/intacct_ruby/functions/employee_base_function.rb
180
+ - lib/intacct_ruby/functions/item_base_function.rb
181
+ - lib/intacct_ruby/functions/location_base_function.rb
182
+ - lib/intacct_ruby/functions/project_base_function.rb
183
+ - lib/intacct_ruby/functions/update_customer.rb
184
+ - lib/intacct_ruby/functions/update_employee.rb
185
+ - lib/intacct_ruby/functions/update_item.rb
186
+ - lib/intacct_ruby/functions/update_location.rb
187
+ - lib/intacct_ruby/functions/update_project.rb
188
+ - lib/intacct_ruby/helpers/contacts_helper.rb
189
+ - lib/intacct_ruby/helpers/date_helper.rb
190
+ - lib/intacct_ruby/request.rb
191
+ - lib/intacct_ruby/response.rb
192
+ - lib/intacct_ruby/version.rb
193
+ homepage: https://github.com/jzornow/intacct-ruby
194
+ licenses:
195
+ - MIT
196
+ metadata: {}
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: 1.9.3
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 2.4.8
214
+ signing_key:
215
+ specification_version: 4
216
+ summary: A Ruby wrapper for the Intacct API
217
+ test_files: []