intacct_ruby 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d42a536100b60ef09ae692e1ca89d06cf8842684
4
+ data.tar.gz: 451891434ad91b2f70873d30c64a790170c733a6
5
+ SHA512:
6
+ metadata.gz: 9dbd0f7d721c24e1eca287937f417f22ad9b204d6d77a6e17286188982d808a531805a77ccd3cb8ec29c974197423d27959947b68f390b9bcd9110c711d3de69
7
+ data.tar.gz: b75ce4f70c468cce6fd67bf715a4daa75bfd004389fc5752f84d792ca1707c7257c6bf4bcfbbfb2b821dad078381233b73d42cdf3fd4bbab97d386681d480625
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.2.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jeremy@zornow.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in intacct_ruby.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jeremy Zornow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,173 @@
1
+ [ ![Codeship Status for jzornow/intacct-ruby](https://app.codeship.com/projects/161bbcb0-037f-0135-febb-660dbc75d940/status?branch=master)](https://app.codeship.com/projects/213338)
2
+
3
+ # IntacctRuby
4
+
5
+ A wrapper for [Intacct's API](https://developer.intacct.com/wiki/functions-object), which tries to stay as close as it can to the syntax and philosophy of the API itself.
6
+
7
+ ## The Power of Multi-Function Api Calls
8
+ Unlike the other Gems out in the Rubyverse, this library supports one of the Intacct API's most powerful features: multi-function API calls.
9
+
10
+ ### Why Does This Matter?
11
+ In an ERP system like Intacct, you'll probably want to perform multiple actions at once, like debiting one account and crediting another, or creating several associated records simulatenously. The more calls you make, the longer it will take to see a response. That's just a fact. But if you can bundle all of those actions together into a single call, you lower the load on both your system and Intacct's servers and guarantee yourself a quicker response. Intacct's entire API is built around this idea, and `IntacctRuby` tries to translate that philosophy into Ruby code as best as it can.
12
+
13
+ ### How Do It Do?
14
+ Let's say you want to create a project and a customer associated with that project simultaneously. The Intacct API would tell you to create a call with a `<create_customer>` function followed by a `<create_project>` function. So let's do it!
15
+
16
+ ```ruby
17
+ create_customer = IntacctRuby::Functions::CreateCustomer.new(
18
+ customerid: '1',
19
+ first_name: 'Han',
20
+ last_name: 'Solo',
21
+ type: 'Person',
22
+ email1: 'han@solo.com',
23
+ status: 'active'
24
+ )
25
+
26
+ create_project = IntacctRuby::Functions::CreateProject.new(
27
+ projectid: '1',
28
+ name: 'Get Chewie a Haircut',
29
+ projectcategory: 'Improve Wookie Hygene',
30
+ customerid: '1',
31
+ customfields: {
32
+ shampoo: 'true',
33
+ blowdry: 'false'
34
+ }
35
+ )
36
+
37
+ request = IntacctRuby::Request.new(create_customer, create_project)
38
+ request.send
39
+ ```
40
+
41
+ This will fire off a request that looks something like this:
42
+
43
+ ```xml
44
+ <?xml version="1.0" encoding="UTF-8"?>
45
+ <request>
46
+ <control>
47
+ ** omitted **
48
+ </control>
49
+ <operation transaction="true">
50
+ <authentication>
51
+ ** omitted **
52
+ </authentication>
53
+ <content>
54
+ <function controlid="create_customer_1">
55
+ <create_customer>
56
+ <customerid>1</customerid>
57
+ <name>Han Solo</name>
58
+ <status>active</status>
59
+ <contactinfo>
60
+ <contact>
61
+ <contactname>Han Solo (Customer #1)</contactname>
62
+ <printas>Han Solo</printas>
63
+ <firstname>Han</firstname>
64
+ <lastname>Solo</lastname>
65
+ <email1>han@solo.com</email1>
66
+ </contact>
67
+ </contactinfo>
68
+ </create_customer>
69
+ </function>
70
+ <function controlid="create_project_1">
71
+ <create_project>
72
+ <projectid>1</projectid>
73
+ <name>Get Chewie a Haircut</name>
74
+ <projectcategory>Improve Wookie Hygene</projectcategory>
75
+ <customerid>1</customerid>
76
+ <customfields>
77
+ <customfield>
78
+ <customfieldname>shampoo</customfieldname>
79
+ <customfieldvalue>true</customfieldvalue>
80
+ </customfield>
81
+ <customfield>
82
+ <customfieldname>blowdry</customfieldname>
83
+ <customfieldvalue>false</customfieldvalue>
84
+ </customfield>
85
+ </customfields>
86
+ </create_project>
87
+ </function>
88
+ </content>
89
+ </operation>
90
+ </request>
91
+ ```
92
+ If there are function errors (e.g. you omitted a required field) you'll see an error on response. Same if you see an internal server error, or any error outside of the 2xx range.
93
+
94
+ ## Customizing Calls
95
+
96
+ Before we go any further, make sure you've read the [Intacct API Quickstart Guide](https://developer.intacct.com/wiki/constructing-web-services-request#The%20Intacct%20DTDs).
97
+
98
+ This gem creates calls using the following defaults:
99
+ - **uniqueid:** false,
100
+ - **dtdversion:** 3.0,
101
+ - **includewhitespace:** false,
102
+ - **transaction:** true
103
+
104
+ If you'd like to override any of these, you can do so when you create a new request:
105
+
106
+ ```ruby
107
+ IntacctRuby::Request.new(
108
+ function_1,
109
+ function_2,
110
+ uniqueid: 'some_uniqueid_override',
111
+ dtdversion: 'some_dtd_override'
112
+ )
113
+ ```
114
+ ## Installation
115
+
116
+ ### The Gem Itself
117
+ Add this line to your application's Gemfile:
118
+
119
+ ```ruby
120
+ gem 'intacct_ruby'
121
+ ```
122
+
123
+ And then execute:
124
+
125
+ $ bundle
126
+
127
+ Or install it yourself as:
128
+
129
+ $ gem install intacct_ruby
130
+
131
+ ### The Configuration (Don't Skip This Part!)
132
+ Once the gem's in place, you'll have it teach it your company secrets.
133
+
134
+ Intacct requires that the following credentials be passed along in the `<control>` block of each request:
135
+ - `senderid`
136
+ - (sender) `password`
137
+
138
+ and that the following be sent in the `<authentication>` block, too:
139
+ - `userid`
140
+ - `companyid`
141
+ - `password`
142
+
143
+ IntacctRuby handles all this for you, but you'll need to tell it which is which. The gem pulls these values from Environmental variables, and it uses [Figaro](https://github.com/laserlemon/figaro) to manage the whole process. In order to get this to work, you'll need to have an `application.yml` file in your project directory with the following definitions:
144
+ ```yaml
145
+ intacct_senderid: 'some senderid'
146
+ intacct_sender_password: 'some password'
147
+ intacct_userid: 'some userid'
148
+ intacct_user_password: 'some password'
149
+ intacct_companyid: 'some companyid'
150
+ ```
151
+ Once those are in place, IntacctRuby will suck 'em up and deposit them in the requests that you generate. Eeeasy squeezey.
152
+
153
+ ## Adding New Functions
154
+ This gem was designed, as so many are, for a specific use case. The Intacct API has hundreds of API calls, though I only built out a dozen or so. Within that dozen, I only built out the fields that I needed in each call.
155
+
156
+ I know what you're thinking:
157
+ **You dweeb! Why didn't make the stuff that I need, too?**
158
+
159
+ I didn't, because I have full confidence in your ability to do it yourself. These calls are easy to construct, and they almost perfectly mirror the structure of the XML shown in Intacct's API documentation. You can figure it out! You're a developer, for shirt's sake.
160
+
161
+ If you're interested, feel free to reach out to me for information on how to build or improve the functions that are already present in this gem.
162
+
163
+ ## Contributing
164
+
165
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jzornow/intacct-ruby/.
166
+
167
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
168
+
169
+
170
+ ## License
171
+
172
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
173
+
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'intacct_ruby'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'intacct_ruby/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'intacct_ruby'
9
+ spec.version = IntacctRuby::VERSION
10
+ spec.authors = ['Jeremy Zornow']
11
+ spec.email = ['jeremy@zornow.com']
12
+ spec.required_ruby_version = '>= 1.9.3'
13
+ spec.summary = 'A Ruby wrapper for the Intacct API'
14
+ spec.description = 'Allows for multi-function API calls, the ' \
15
+ 'addition of custom fields, and more. All in ' \
16
+ 'an easy-to-use package!'
17
+ spec.homepage = 'https://github.com/jzornow/intacct-ruby'
18
+ spec.license = 'MIT'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
+ f.match(%r{^(test|spec|features)/})
22
+ end
23
+
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.13'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
32
+ spec.add_development_dependency 'mocha', '~> 0.13.3'
33
+ spec.add_development_dependency 'pry-byebug', '~> 3.4', '>= 3.4.2'
34
+
35
+ spec.add_runtime_dependency 'builder', '~> 3.0', '>= 3.0.4'
36
+ spec.add_runtime_dependency 'figaro', '~> 1.1', '>= 1.1.1'
37
+ end
@@ -0,0 +1,24 @@
1
+ require 'intacct_ruby/api'
2
+ require 'intacct_ruby/version'
3
+
4
+ require 'intacct_ruby/request'
5
+ require 'intacct_ruby/response'
6
+
7
+ require 'intacct_ruby/functions/base_function'
8
+
9
+ require 'intacct_ruby/functions/create_customer'
10
+ require 'intacct_ruby/functions/update_customer'
11
+
12
+ require 'intacct_ruby/functions/create_project'
13
+ require 'intacct_ruby/functions/update_project'
14
+
15
+ require 'intacct_ruby/functions/create_employee'
16
+ require 'intacct_ruby/functions/update_employee'
17
+
18
+ require 'intacct_ruby/functions/create_location'
19
+ require 'intacct_ruby/functions/update_location'
20
+
21
+ require 'intacct_ruby/functions/create_item'
22
+ require 'intacct_ruby/functions/update_item'
23
+
24
+ require 'intacct_ruby/functions/create_aradjustment'
@@ -0,0 +1,31 @@
1
+ module IntacctRuby
2
+ # the gateway by which IntacctRuby::Request instances are sent off to Intacct
3
+ class Api
4
+ def initialize(http_gateway = nil)
5
+ @http_gateway = http_gateway
6
+ end
7
+
8
+ def send(request_object, post_request = nil)
9
+ post_request ||= Net::HTTP::Post.new(uri.request_uri)
10
+
11
+ post_request['Content-Type'] = 'x-intacct-xml-request'
12
+ post_request.body = request_object.to_xml
13
+
14
+ https_request(post_request, uri)
15
+ end
16
+
17
+ private
18
+
19
+ URI_STRING = 'https://api.intacct.com/ia/xml/xmlgw.phtml'.freeze
20
+
21
+ def uri
22
+ @uri ||= URI.parse URI_STRING
23
+ end
24
+
25
+ def https_request(request, uri)
26
+ @http_gateway ||= Net::HTTP.new uri.host, uri.port
27
+ @http_gateway.use_ssl = true
28
+ @http_gateway.request request
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module IntacctRuby
2
+ module Exceptions
3
+ class FunctionFailureException < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ require 'builder'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # Creates the basic structure for all functions.
6
+ # Meant to be an interface: this should not be implemented on its own.
7
+ class BaseFunction
8
+ def initialize(controlid, attrs = {})
9
+ @controlid = controlid
10
+ @attrs = attrs
11
+
12
+ @xml = Builder::XmlMarkup.new
13
+ end
14
+
15
+ def to_xml
16
+ @xml.function controlid: @controlid do
17
+ yield(@xml)
18
+ end
19
+
20
+ # converts xml to string
21
+ @xml.target!
22
+ end
23
+
24
+ private
25
+
26
+ def timestamp
27
+ @timestamp ||= Time.now.utc.to_s
28
+ end
29
+
30
+ def custom_field_params(custom_fields)
31
+ xml = Builder::XmlMarkup.new
32
+
33
+ xml.customfields do
34
+ custom_fields.each do |name, value|
35
+ xml.customfield do
36
+ xml.customfieldname name.to_s
37
+ xml.customfieldvalue value.to_s
38
+ end
39
+ end
40
+ end
41
+
42
+ xml.target!
43
+ end
44
+ end
45
+ end
46
+ end