intacctrb 0.6.3 → 0.6.4

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: 609eacac3273306972a5dcdfdb1235531eb25b78
4
- data.tar.gz: a5a1b1b36acdd3c8cf02380da4610bafc6dac57f
3
+ metadata.gz: cebe8f8462674253ac9513ae003769f24442edba
4
+ data.tar.gz: c69679328b21385369513d1021ea63c0a3d7e87a
5
5
  SHA512:
6
- metadata.gz: 7b9642b1e6bedd8bed6b82327a8b783ca2fbdb7824dee7adcc5159d4a1dc9ce5b0c00e2454c26f19d72b5535101274785d48550b419320aff92862501eba9389
7
- data.tar.gz: 89e8095c781198fbe4328a8ffccc4f621592e23304ec16cc7dd3926d27f83288414860384d63265ce975567075e8246c2e65f0808838f56118bc42a57d8e6caf
6
+ metadata.gz: a2c0d2b780a3f13999a5e945c8dbc8fe4b34149c4fd5a6022f413bd099945ec196985ed540390821161409017684aeb21e40231e6f788e1a6ea7c735be1ae6fa
7
+ data.tar.gz: fd801253a5d2c4b6b783c2927cbf05912e4d2ded774667f4084c6b508fda9c023a3784ee8b7ce9a5875c3ccdc677effd045091d0d9b490c08175e6899b9ccf35
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- intacctrb (0.6.3)
4
+ intacctrb (0.6.4)
5
5
  hooks
6
6
  nokogiri
7
7
 
data/lib/intacctrb.rb CHANGED
@@ -3,6 +3,7 @@ require 'net/http'
3
3
  require 'nokogiri'
4
4
  require 'hooks'
5
5
  require 'ostruct'
6
+ require "intacctrb/logger"
6
7
  require "intacctrb/base"
7
8
  require "intacctrb/contact"
8
9
  require "intacctrb/customer"
@@ -29,57 +29,67 @@ module IntacctRB
29
29
  private
30
30
 
31
31
  def send_xml action
32
- @intacct_action = action.to_s
33
- run_hook :"before_#{intacct_action}" if action=="create"
34
-
35
- builder = Nokogiri::XML::Builder.new do |xml|
36
- xml.request {
37
- xml.control {
38
- xml.senderid IntacctRB.xml_sender_id
39
- xml.password IntacctRB.xml_password
40
- xml.controlid "INVOICE XML"
41
- xml.uniqueid "false"
42
- xml.dtdversion "3.0"
43
- }
44
- xml.operation(transaction: "false") {
45
- xml.authentication {
46
- xml.login {
47
- xml.userid IntacctRB.app_user_id
48
- xml.companyid IntacctRB.app_company_id
49
- xml.password IntacctRB.app_password
50
- }
32
+ retry_count = 0
33
+ begin
34
+ @intacct_action = action.to_s
35
+ run_hook :"before_#{intacct_action}" if action=="create"
36
+
37
+ builder = Nokogiri::XML::Builder.new do |xml|
38
+ xml.request {
39
+ xml.control {
40
+ xml.senderid IntacctRB.xml_sender_id
41
+ xml.password IntacctRB.xml_password
42
+ xml.controlid "INVOICE XML"
43
+ xml.uniqueid "false"
44
+ xml.dtdversion "3.0"
51
45
  }
52
- xml.content {
53
- yield xml
46
+ xml.operation(transaction: "false") {
47
+ xml.authentication {
48
+ xml.login {
49
+ xml.userid IntacctRB.app_user_id
50
+ xml.companyid IntacctRB.app_company_id
51
+ xml.password IntacctRB.app_password
52
+ }
53
+ }
54
+ xml.content {
55
+ yield xml
56
+ }
54
57
  }
55
58
  }
56
- }
57
- end
58
-
59
- xml = builder.doc.root.to_xml
60
- puts xml
61
- @sent_xml = xml
59
+ end
62
60
 
63
- url = "https://www.intacct.com/ia/xml/xmlgw.phtml"
64
- uri = URI(url)
61
+ xml = builder.doc.root.to_xml
62
+ IntacctRB.logger.info xml
63
+ @sent_xml = xml
64
+
65
+ url = "https://www.intacct.com/ia/xml/xmlgw.phtml"
66
+ uri = URI(url)
67
+ retry_count += 1
68
+ res = Net::HTTP.post_form(uri, 'xmlrequest' => xml)
69
+ @response = Nokogiri::XML(res.body)
70
+ IntacctRB.logger.info res.body
71
+ if successful?
72
+ if key = response.at('//result//RECORDNO') || response.at('//result//key')
73
+ set_intacct_id key.content if object
74
+ end
65
75
 
66
- res = Net::HTTP.post_form(uri, 'xmlrequest' => xml)
67
- @response = Nokogiri::XML(res.body)
68
- puts res.body
69
- if successful?
70
- if key = response.at('//result//RECORDNO') || response.at('//result//key')
71
- set_intacct_id key.content if object
76
+ if intacct_action
77
+ run_hook :after_send_xml, intacct_action
78
+ #run_hook :"after_#{intacct_action}"
79
+ end
80
+ else
81
+ run_hook :on_error
72
82
  end
73
-
74
- if intacct_action
75
- run_hook :after_send_xml, intacct_action
76
- #run_hook :"after_#{intacct_action}"
83
+ @response
84
+ rescue Net::ReadTimeout => e
85
+ if retry_count <= 3
86
+ IntacctRB.logger.warning "Net::ReadTimeout in IntacctRB; retrying"
87
+ retry
88
+ else
89
+ IntacctRB.logger.error "Net::ReadTimeout in IntacctRB; retries exhausted"
90
+ raise e
77
91
  end
78
- else
79
- run_hook :on_error
80
92
  end
81
-
82
- @response
83
93
  end
84
94
 
85
95
  def successful?
@@ -92,7 +102,7 @@ module IntacctRB
92
102
 
93
103
  def return_result(response)
94
104
  if successful?
95
- data = OpenStruct.new({result: true})
105
+ data = OpenStruct.new({result: true, object: response})
96
106
  else
97
107
  data = OpenStruct.new({result: false})
98
108
  response.xpath("//result/errormessage/error").each do |error|
@@ -0,0 +1,11 @@
1
+ require 'logger'
2
+
3
+ module IntacctRB
4
+ def self.logger
5
+ @@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
6
+ end
7
+
8
+ def self.logger=(logger)
9
+ @@logger = logger
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module IntacctRB
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intacctrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Hale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-19 00:00:00.000000000 Z
11
+ date: 2018-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -184,6 +184,7 @@ files:
184
184
  - lib/intacctrb/exceptions/vendor.rb
185
185
  - lib/intacctrb/invoice.rb
186
186
  - lib/intacctrb/journal_entry.rb
187
+ - lib/intacctrb/logger.rb
187
188
  - lib/intacctrb/vendor.rb
188
189
  - lib/intacctrb/version.rb
189
190
  - pkg/intacctrb-0.1.gem