intacct_ruby 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cba2efd7c0b7dc786b022b0135d1c1eead96abf
4
- data.tar.gz: 3cf031fd36d9422d24c32a2166077c8509be22e1
3
+ metadata.gz: de2fb5a53adf33f00f52d582ef53324de9d70609
4
+ data.tar.gz: e2d2edff9d8f4e6cd289e97e65ee918228b115e2
5
5
  SHA512:
6
- metadata.gz: a8bbb182cbf25c1dd2232efd3b5a0107001fb1cae4853b53c0eead0afac0c3cc99e207de3a85a8b2919a6d3d87d5798f0828b32e2ba31642e1b87dc02b86a53a
7
- data.tar.gz: c1ad219b8d14c5a9e7bba67630a74c5b66d036e55e71ee531d73470bb6ad371f992c66d9d0801eccf8ba928300303b2336ab9e8752d4b44d30f26c3789f0eda9
6
+ metadata.gz: c5bffa4e075a0cdca538be6f330486e7c0bf41caea339cb2c5f76c0d7c25bc6453ae5defbfeb9dd85313928df8bd1ca0de0a192e2adfd50191bf8ea86ac0aff4
7
+ data.tar.gz: d9e146508157473edef620b6869d091df313ad2549d3c6d243eb6d1280854b0b15f03311f432eb9c67c4d28ed35cb9593a9c1544308c1fa244c0e895c5b3df13
@@ -0,0 +1,5 @@
1
+ module IntacctRuby
2
+ module Exceptions
3
+ class UnknownFunctionType < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,72 @@
1
+ require 'builder'
2
+ require 'intacct_ruby/exceptions/unknown_function_type'
3
+
4
+ module IntacctRuby
5
+ # a function to be sent to Intacct. Defined by a function type (e.g. :create),
6
+ # an object type, (e.g. :customer), and arguments.
7
+ class Function
8
+ ALLOWED_TYPES = %w(
9
+ readByQuery
10
+ read
11
+ readByName
12
+ create
13
+ update
14
+ delete
15
+ ).freeze
16
+
17
+ def initialize(function_type, object_type, arguments = {})
18
+ @function_type = function_type.to_s
19
+ @object_type = object_type.to_s
20
+ @arguments = arguments
21
+
22
+ validate_type!
23
+ end
24
+
25
+ def to_xml
26
+ xml = Builder::XmlMarkup.new
27
+
28
+ xml.function controlid: controlid do
29
+ xml.tag!(@function_type) do
30
+ xml.tag!(@object_type.upcase) do
31
+ xml << argument_xml(@arguments)
32
+ end
33
+ end
34
+ end
35
+
36
+ xml.target!
37
+ end
38
+
39
+ private
40
+
41
+ def timestamp
42
+ @timestamp ||= Time.now.utc.to_s
43
+ end
44
+
45
+ def controlid
46
+ "#{@function_type}-#{@object_type}-#{timestamp}"
47
+ end
48
+
49
+ def argument_xml(arguments_to_convert)
50
+ xml = Builder::XmlMarkup.new
51
+
52
+ arguments_to_convert.each do |key, value|
53
+ argument_key = key.to_s.upcase
54
+
55
+ # Beware! Recursion below. Necessary for handling nested attrs.
56
+ argument_value = value.is_a?(Hash) ? argument_xml(value) : value.to_s
57
+
58
+ xml.tag!(argument_key) { xml << argument_value }
59
+ end
60
+
61
+ xml.target!
62
+ end
63
+
64
+ def validate_type!
65
+ unless ALLOWED_TYPES.include?(@function_type)
66
+ raise Exceptions::UnknownFunctionType,
67
+ "Type #{@object_type} not recognized. Function Type must be " \
68
+ "one of #{ALLOWED_TYPES}."
69
+ end
70
+ end
71
+ end
72
+ end
@@ -2,6 +2,8 @@ require 'builder'
2
2
 
3
3
  require 'intacct_ruby/api'
4
4
  require 'intacct_ruby/response'
5
+ require 'intacct_ruby/function'
6
+
5
7
  require 'intacct_ruby/exceptions/insufficient_credentials_exception'
6
8
  require 'intacct_ruby/exceptions/empty_request_exception'
7
9
 
@@ -58,6 +60,17 @@ module IntacctRuby
58
60
 
59
61
  attr_reader :request, :functions
60
62
 
63
+ def method_missing(method_name, *arguments, &block)
64
+ super unless Function::ALLOWED_TYPES.include? method_name.to_s
65
+
66
+ # object_type must be the first argument in arguments
67
+ @functions << Function.new(method_name, arguments.shift, *arguments)
68
+ end
69
+
70
+ def respond_to_missing?(method_name, include_private = false)
71
+ Functions::ALLOWED_TYPES.includes?(method_name) || super
72
+ end
73
+
61
74
  def validate_functions!
62
75
  unless functions.any?
63
76
  raise Exceptions::EmptyRequestException,
@@ -1,3 +1,3 @@
1
1
  module IntacctRuby
2
- VERSION = '1.4.1'.freeze
2
+ VERSION = '1.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intacct_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Zornow
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-31 00:00:00.000000000 Z
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,6 +150,8 @@ files:
150
150
  - lib/intacct_ruby/exceptions/empty_request_exception.rb
151
151
  - lib/intacct_ruby/exceptions/function_failure_exception.rb
152
152
  - lib/intacct_ruby/exceptions/insufficient_credentials_exception.rb
153
+ - lib/intacct_ruby/exceptions/unknown_function_type.rb
154
+ - lib/intacct_ruby/function.rb
153
155
  - lib/intacct_ruby/functions/base_function.rb
154
156
  - lib/intacct_ruby/functions/create_aradjustment.rb
155
157
  - lib/intacct_ruby/functions/create_customer.rb