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,48 @@
1
+ require 'intacct_ruby/functions/base_function'
2
+ require 'intacct_ruby/helpers/date_helper'
3
+
4
+ module IntacctRuby
5
+ module Functions
6
+ # creates ar adjustment instance in Intacct
7
+ class CreateARAdjustment < BaseFunction
8
+ include DateHelper
9
+
10
+ def initialize(attrs = {})
11
+ super "create_aradjustment (Customer \##{attrs[:customerid]}, " \
12
+ "(#{timestamp})", attrs
13
+ end
14
+
15
+ def to_xml
16
+ super do |xml|
17
+ xml.create_aradjustment do
18
+ xml.customerid @attrs[:customerid]
19
+
20
+ xml << date_params(:datecreated, @attrs[:datecreated])
21
+
22
+ xml.description @attrs[:description]
23
+
24
+ xml.aradjustmentitems do
25
+ xml << line_item_params(@attrs[:aradjustmentitems])
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def line_item_params(adjustment_item_attrs)
34
+ xml = Builder::XmlMarkup.new
35
+
36
+ adjustment_item_attrs.each do |item_params|
37
+ xml.lineitem do
38
+ [:glaccountno, :amount, :memo, :locationid].each do |param_key|
39
+ xml.tag!(param_key) { xml << item_params[param_key].to_s }
40
+ end
41
+ end
42
+ end
43
+
44
+ xml.target!
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,23 @@
1
+ require 'intacct_ruby/helpers/contacts_helper'
2
+ require 'intacct_ruby/functions/customer_base_function'
3
+
4
+ module IntacctRuby
5
+ module Functions
6
+ # function that creates customer instance
7
+ class CreateCustomer < CustomerBaseFunction
8
+ def initialize(attrs = {})
9
+ super "create_customer_#{attrs[:customerid]}", attrs
10
+ end
11
+
12
+ def to_xml
13
+ super do |xml|
14
+ xml.create_customer do
15
+ xml.customerid @attrs[:customerid]
16
+
17
+ xml << customer_params
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ require 'intacct_ruby/functions/employee_base_function'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # Function that creates an employee instance in Intacct
6
+ class CreateEmployee < EmployeeBaseFunction
7
+ def initialize(attrs = {})
8
+ super("create_employee_#{attrs[:employeeid]}", attrs)
9
+ end
10
+
11
+ def to_xml
12
+ super do |xml|
13
+ xml.create_employee do
14
+ xml.employeeid @attrs[:employeeid]
15
+ xml << employee_params
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'intacct_ruby/functions/item_base_function'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # creates an item instance in Intacct
6
+ class CreateItem < ItemBaseFunction
7
+ def initialize(attrs = {})
8
+ super "create_item_#{attrs[:itemid]}", attrs
9
+ end
10
+
11
+ def to_xml
12
+ super do |xml|
13
+ xml.create_item do
14
+ xml.itemid @attrs[:itemid]
15
+ xml << item_params
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'intacct_ruby/functions/location_base_function'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # Function that creates a location instance in Intacct
6
+ class CreateLocation < LocationBaseFunction
7
+ def initialize(attrs = {})
8
+ super("create_location_#{attrs[:locationid]}", attrs)
9
+ end
10
+
11
+ def to_xml
12
+ super do |xml|
13
+ xml.create_location do
14
+ xml.locationid @attrs[:locationid]
15
+ xml << location_params
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ require 'intacct_ruby/functions/project_base_function'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # creates a project instance in Intacct
6
+ class CreateProject < ProjectBaseFunction
7
+ def initialize(attrs = {})
8
+ super("create_project_#{attrs[:projectid]}", attrs)
9
+ end
10
+
11
+ def to_xml
12
+ super do |xml|
13
+ xml.create_project do
14
+ xml << project_params
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ require 'intacct_ruby/functions/base_function'
2
+ require 'intacct_ruby/helpers/contacts_helper'
3
+
4
+ module IntacctRuby
5
+ module Functions
6
+ # the parent for all customer-related functions. Includes methods that
7
+ # cut down on duplicate code
8
+ class CustomerBaseFunction < BaseFunction
9
+ include ContactsHelper
10
+
11
+ private
12
+
13
+ def customer_params
14
+ xml = Builder::XmlMarkup.new
15
+
16
+ xml.name full_name(@attrs)
17
+ xml.status @attrs[:status]
18
+ xml.contactinfo do
19
+ xml << contact_params(@attrs, @attrs[:customerid], 'Customer')
20
+ end
21
+
22
+ xml.target!
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,36 @@
1
+ require 'intacct_ruby/helpers/contacts_helper'
2
+ require 'intacct_ruby/helpers/date_helper'
3
+ require 'intacct_ruby/functions/base_function'
4
+
5
+ module IntacctRuby
6
+ module Functions
7
+ # contains code shared by all employee functions
8
+ class EmployeeBaseFunction < BaseFunction
9
+ include IntacctRuby::ContactsHelper
10
+ include IntacctRuby::DateHelper
11
+
12
+ private
13
+
14
+ def employee_params
15
+ xml = Builder::XmlMarkup.new
16
+
17
+ xml.locationid @attrs[:locationid]
18
+ xml.supervisorid @attrs[:supervisorid]
19
+
20
+ xml << start_date_params
21
+
22
+ xml.status @attrs[:status]
23
+
24
+ xml.personalinfo do
25
+ xml << employee_contact_params
26
+ end
27
+
28
+ xml.target!
29
+ end
30
+
31
+ def employee_contact_params
32
+ contact_params(@attrs, @attrs[:employeeid], 'Employee')
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ require 'intacct_ruby/functions/base_function'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # function that all item functions are built off of, to decreate dupe code
6
+ class ItemBaseFunction < BaseFunction
7
+ ALL_PARAMS = [
8
+ :name,
9
+ :itemtype,
10
+ :extended_description,
11
+ :productlineid,
12
+ :standard_cost,
13
+ :glgroup,
14
+ :uomgrp
15
+ ].freeze
16
+
17
+ def item_params
18
+ xml = Builder::XmlMarkup.new
19
+
20
+ ALL_PARAMS.each do |param_name|
21
+ param_value = @attrs[param_name]
22
+ xml.tag!(param_name) { xml << param_value } if param_value
23
+ end
24
+
25
+ xml.target!
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ require 'intacct_ruby/functions/base_function'
2
+ require 'intacct_ruby/helpers/date_helper'
3
+
4
+ module IntacctRuby
5
+ module Functions
6
+ # base for all location-related functions, to cut down on duplicate code
7
+ class LocationBaseFunction < BaseFunction
8
+ include IntacctRuby::DateHelper
9
+
10
+ private
11
+
12
+ def location_params
13
+ xml = Builder::XmlMarkup.new
14
+
15
+ xml.name @attrs[:name]
16
+ xml.parentid @attrs[:parentid]
17
+
18
+ xml << start_date_params
19
+
20
+ xml.target!
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ require 'intacct_ruby/functions/base_function'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # contains shared code for creating and updating projects
6
+ class ProjectBaseFunction < BaseFunction
7
+ private
8
+
9
+ def project_params
10
+ xml = Builder::XmlMarkup.new
11
+
12
+ [:projectid, :name, :projectcategory, :customerid].each do |key|
13
+ xml.tag!(key.to_s) { xml << @attrs[key].to_s }
14
+ end
15
+
16
+ xml << custom_field_params(@attrs[:customfields])
17
+
18
+ xml.target!
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'intacct_ruby/functions/customer_base_function'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # update customer instance
6
+ class UpdateCustomer < CustomerBaseFunction
7
+ include ContactsHelper
8
+
9
+ def initialize(attrs = {})
10
+ super "update_customer_#{attrs[:customerid]} (#{timestamp})", attrs
11
+ end
12
+
13
+ def to_xml
14
+ super do |xml|
15
+ xml.update_customer customerid: @attrs[:customerid] do
16
+ xml << customer_params
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ require 'intacct_ruby/functions/employee_base_function'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # function used to update employee instances
6
+ class UpdateEmployee < EmployeeBaseFunction
7
+ def initialize(attrs = {})
8
+ super("update_employee_#{attrs[:employeeid]} (#{timestamp})", attrs)
9
+ end
10
+
11
+ def to_xml
12
+ super do |xml|
13
+ xml.update_employee employeeid: @attrs[:employeeid] do
14
+ xml << employee_params
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'intacct_ruby/functions/item_base_function'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # updates item instance in Intacct
6
+ class UpdateItem < ItemBaseFunction
7
+ def initialize(attrs = {})
8
+ super "update_item_#{attrs[:itemid]} (#{timestamp})", attrs
9
+ end
10
+
11
+ def to_xml
12
+ super do |xml|
13
+ xml.update_item itemid: @attrs[:itemid] do
14
+ xml << item_params
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'intacct_ruby/functions/location_base_function'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # used to update location instances in Intacct
6
+ class UpdateLocation < LocationBaseFunction
7
+ def initialize(attrs = {})
8
+ super("update_location_#{attrs[:locationid]} (#{timestamp})", attrs)
9
+ end
10
+
11
+ def to_xml
12
+ super do |xml|
13
+ xml.update_location locationid: @attrs[:locationid] do
14
+ xml << location_params
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'intacct_ruby/functions/project_base_function'
2
+
3
+ module IntacctRuby
4
+ module Functions
5
+ # creates a project instance in Intacct
6
+ class UpdateProject < ProjectBaseFunction
7
+ def initialize(attrs = {})
8
+ super("update_project_#{attrs[:projectid]} (#{timestamp})", attrs)
9
+ end
10
+
11
+ def to_xml
12
+ super do |xml|
13
+ xml.update_project key: @attrs[:projectid] do
14
+ xml << project_params
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ module IntacctRuby
2
+ # methods to avoid duplication when creating and updating contact records
3
+ module ContactsHelper
4
+ def contact_params(attributes, id, person_type)
5
+ xml = Builder::XmlMarkup.new
6
+
7
+ name = full_name(attributes)
8
+
9
+ xml.contact do
10
+ xml.contactname contactname(name, id, person_type)
11
+ xml.printas full_name(attributes)
12
+ xml.firstname attributes[:first_name]
13
+ xml.lastname attributes[:last_name]
14
+ xml.email1 attributes[:email1]
15
+ end
16
+
17
+ xml.target!
18
+ end
19
+
20
+ def contactname(name, id, person_type)
21
+ # a unique identifier for a contact, to be used for Intacct's
22
+ # contactname field. Person Type required to ensure that there aren't
23
+ # duplicates (e.g. a customer and employee w/ ID 1 both named
24
+ # 'John Smith')
25
+ "#{name} (#{person_type} \##{id})"
26
+ end
27
+
28
+ def full_name(attrs = {})
29
+ "#{attrs[:first_name]} #{attrs[:last_name]}"
30
+ end
31
+ end
32
+ end