netsuite_api 0.1.3 → 0.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 007d3e8a1e0314c293ea7be440ec1565a58442402f783416ec6c62977424773d
4
- data.tar.gz: 72420ff8f2a764d7eb5278e76ddfee5ed1f17eb3039277cdeb166f25503a88a9
3
+ metadata.gz: b861b814e33ac144071c716dddf8521a841f93b326bb6fd7e5f8ebb8080adfac
4
+ data.tar.gz: c94c8a38c727d9bad116b7191e518e95c5651a2c675d308b45ccc7c798599846
5
5
  SHA512:
6
- metadata.gz: fa6d2859d5376a90bb0a5808e902dcbd5c3dd77c0cb89f1c1b2df1a56c1edf743f5a4a8b37e77ee4a43d2c97bba829a96f9baf297e85feec51c3563ca4a0a346
7
- data.tar.gz: 74aeef7a92fa667dc3a10fdd2594fa827d5a8b8d73db536899f0079dbac80ec9b61b168031a7d1fd9d99a671f32be28f0666f85474e4fdff1f459544548ce87c
6
+ metadata.gz: d1d3d8c063ad9d921f83d18a5c63d06b69337a6b57561c731c3c79675f9e22c32ee484be749a61e9c621c5498a15bb369e479329c688a386c06234d98fd4b2f8
7
+ data.tar.gz: 793115ac5a261d39fd397793fee6beda66be7c89d98e923db73c8e0a368cbc0200da8d3e621cc18af4f79406c09a8fcfcb34d08c2a5555af376c07b6440bd11d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- netsuite_api (0.1.2)
4
+ netsuite_api (0.1.4)
5
5
  activesupport
6
6
  faraday
7
7
  securerandom
@@ -9,38 +9,58 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (6.1.7.10)
13
- concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ activesupport (8.0.1)
13
+ base64
14
+ benchmark (>= 0.3)
15
+ bigdecimal
16
+ concurrent-ruby (~> 1.0, >= 1.3.1)
17
+ connection_pool (>= 2.2.5)
18
+ drb
14
19
  i18n (>= 1.6, < 2)
20
+ logger (>= 1.4.2)
15
21
  minitest (>= 5.1)
16
- tzinfo (~> 2.0)
17
- zeitwerk (~> 2.3)
22
+ securerandom (>= 0.3)
23
+ tzinfo (~> 2.0, >= 2.0.5)
24
+ uri (>= 0.13.1)
18
25
  addressable (2.8.7)
19
26
  public_suffix (>= 2.0.2, < 7.0)
20
27
  base64 (0.2.0)
21
- bigdecimal (3.1.8)
22
- concurrent-ruby (1.3.4)
28
+ benchmark (0.4.0)
29
+ bigdecimal (3.1.9)
30
+ coderay (1.1.3)
31
+ concurrent-ruby (1.3.5)
32
+ connection_pool (2.5.0)
23
33
  crack (1.0.0)
24
34
  bigdecimal
25
35
  rexml
26
- diff-lcs (1.5.1)
27
- faraday (2.8.1)
28
- base64
29
- faraday-net_http (>= 2.0, < 3.1)
30
- ruby2_keywords (>= 0.0.4)
31
- faraday-net_http (3.0.2)
32
- hashdiff (1.1.1)
33
- i18n (1.14.6)
36
+ diff-lcs (1.6.0)
37
+ drb (2.2.1)
38
+ faraday (2.12.2)
39
+ faraday-net_http (>= 2.0, < 3.5)
40
+ json
41
+ logger
42
+ faraday-net_http (3.4.0)
43
+ net-http (>= 0.5.0)
44
+ hashdiff (1.1.2)
45
+ i18n (1.14.7)
34
46
  concurrent-ruby (~> 1.0)
35
- minitest (5.25.1)
36
- public_suffix (5.1.1)
47
+ json (2.10.1)
48
+ logger (1.6.6)
49
+ method_source (1.1.0)
50
+ minitest (5.25.4)
51
+ net-http (0.6.0)
52
+ uri
53
+ pry (0.15.2)
54
+ coderay (~> 1.1)
55
+ method_source (~> 1.0)
56
+ public_suffix (6.0.1)
37
57
  rake (10.5.0)
38
- rexml (3.3.9)
58
+ rexml (3.4.1)
39
59
  rspec (3.13.0)
40
60
  rspec-core (~> 3.13.0)
41
61
  rspec-expectations (~> 3.13.0)
42
62
  rspec-mocks (~> 3.13.0)
43
- rspec-core (3.13.2)
63
+ rspec-core (3.13.3)
44
64
  rspec-support (~> 3.13.0)
45
65
  rspec-expectations (3.13.3)
46
66
  diff-lcs (>= 1.2.0, < 2.0)
@@ -48,26 +68,27 @@ GEM
48
68
  rspec-mocks (3.13.2)
49
69
  diff-lcs (>= 1.2.0, < 2.0)
50
70
  rspec-support (~> 3.13.0)
51
- rspec-support (3.13.1)
52
- ruby2_keywords (0.0.5)
53
- securerandom (0.3.1)
71
+ rspec-support (3.13.2)
72
+ securerandom (0.4.1)
54
73
  tzinfo (2.0.6)
55
74
  concurrent-ruby (~> 1.0)
56
- webmock (3.24.0)
75
+ uri (1.0.2)
76
+ webmock (3.25.0)
57
77
  addressable (>= 2.8.0)
58
78
  crack (>= 0.3.2)
59
79
  hashdiff (>= 0.4.0, < 2.0.0)
60
- zeitwerk (2.6.18)
61
80
 
62
81
  PLATFORMS
82
+ arm64-darwin-22
63
83
  ruby
64
84
 
65
85
  DEPENDENCIES
66
- bundler (~> 1.17)
86
+ bundler
67
87
  netsuite_api!
88
+ pry
68
89
  rake (~> 10.0)
69
90
  rspec (~> 3.0)
70
91
  webmock (~> 3.0)
71
92
 
72
93
  BUNDLED WITH
73
- 1.17.2
94
+ 2.5.9
data/README.md CHANGED
@@ -1,14 +1,17 @@
1
1
  # NetsuiteApi
2
2
 
3
3
  This library is designed to help ruby/rails based applications communicate with the publicly available REST API for NetSuite.
4
+
4
5
  If you are unfamiliar with the NetSuite REST API, you should first read the documentation located at [SuiteTalk REST Web Services API Guide](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/book_1559132836.html).
5
6
 
7
+ The NetSuite REST API document could be found at [NetSuite REST API Browser: Record API v1](https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2024.1/index.html#tag-account)
8
+
6
9
  ## Installation
7
10
 
8
11
  Add this line to your application's Gemfile:
9
12
 
10
13
  ```ruby
11
- gem 'netsuite_api'
14
+ gem 'netsuite_api', '0.1.4'
12
15
  ```
13
16
 
14
17
  And then execute:
@@ -19,9 +22,106 @@ Or install it yourself as:
19
22
 
20
23
  $ gem install netsuite_api
21
24
 
22
- ## Usage
25
+ ## Basic Usage
26
+
27
+ ### Setup Credential Information
28
+
29
+ Set All the credential information in your project .env file
30
+ ```
31
+ NETSUITE_HOST = ""
32
+ NETSUITE_ACCOUNT_ID = ""
33
+ NETSUITE_CONSUMER_KEY = ""
34
+ NETSUITE_CONSUMER_SECRET = ""
35
+ NETSUITE_TOKEN = ""
36
+ NETSUITE_TOKEN_SECRET = ""
37
+ NETSUITE_PDF_HOST =
38
+ ```
39
+
40
+ or pass those information when initialize NetsuiteApi instance, for example, initializing NetsuiteApi::Invoice
41
+ ```
42
+ NetsuiteApi::Invoice.new(netsuite_host: "", netsuite_pdf_host: "", account_id: "", consumer_key: "", token: "", token_secret: "", consumer_secret: "")
43
+ ```
44
+
45
+ ## NetsuiteApi Object Usage
46
+
47
+ There are 7 objects could be used: `NetsuiteApi::Invoice`, `NetsuiteApi::CreditMemo`, `NetsuiteApi::Payment`, `NetsuiteApi::Customer`, `NetsuiteApi::Contact`, `NetsuiteApi::Vendor`, `NetsuiteApi::VendorBill`.
48
+
49
+ More information about the objects could be found in `lib/netsuite_api`.
50
+
51
+ All the objects have method to get record, create data, update data, delete data in NetSuite through Netsuite REST API.
52
+
53
+ Following section shows an example of using `NetsuiteApi::Invoice`. The way to use other objects is similar.
54
+
55
+ ### Get data
56
+
57
+ * Get a specific invoice data.
58
+ ```
59
+ service = NetsuiteApi::Invoice.new
60
+ service.get(netsuite_invoice_id)
61
+ ```
62
+
63
+ * Query some invoice data.
64
+ ```
65
+ # query invoices which entity is 12
66
+
67
+ service = NetsuiteApi::Invoice.new
68
+ query_params = { "q" => "entity EQUAL 12" }
69
+ service.query(query_params)
70
+ ```
71
+ More information about the query parameters could be found in [Record Collection Filtering](https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1545222128.html#Record-Collection-Filtering)
72
+
73
+
74
+ ### Create data
75
+
76
+ * Create an invoice
77
+ ```
78
+ service = NetsuiteApi::Invoice.new
79
+ params = {
80
+ "entity" => {
81
+ "id" => "12"
82
+ },
83
+ "postingperiod" => "121",
84
+ "item" => {
85
+ "items" => [
86
+ {
87
+ "amount" => 100.0,
88
+ "item" => {
89
+ "id" => "26"
90
+ }
91
+ }
92
+ ]
93
+ },
94
+ "subsidiary" => {
95
+ "id" => "8"
96
+ },
97
+ "currency" => {
98
+ "id": "2"
99
+ }
100
+ }
101
+ service.create(invoice_params)
102
+ ```
103
+
104
+
105
+ ### Update data
106
+
107
+ * Update an invoice
108
+ ```
109
+ service = NetsuiteApi::Invoice.new
110
+ update_params = { "otherRefNum": "1234" }
111
+ invoice_id = 1
112
+ service.update(invoice_id, update_params)
113
+ ```
114
+
115
+
116
+ ### Delete data
117
+
118
+ * Delete an invoice
119
+ ```
120
+ service = NetsuiteApi::Invoice.new
121
+ invoice_id = 1
122
+ service.delete(invoice_id)
123
+ ```
23
124
 
24
- TODO: Write usage instructions here
25
125
 
26
126
  ## Development
27
127
 
@@ -31,7 +131,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
31
131
 
32
132
  ## Contributing
33
133
 
34
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/netsuite_api. 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.
134
+ Bug reports and pull requests are welcome on GitHub at https://github.com/iceland101113/netsuite_api. 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.
35
135
 
36
136
  ## License
37
137
 
@@ -1,7 +1,8 @@
1
1
  require 'faraday'
2
2
  require 'securerandom'
3
3
  require 'active_support/core_ext/object'
4
- require "pry"
4
+ require 'base64'
5
+ # require "pry"
5
6
 
6
7
  module NetsuiteApi
7
8
  class Base
@@ -31,8 +32,12 @@ module NetsuiteApi
31
32
  private
32
33
 
33
34
  def connection(host)
34
- conn = Faraday.new(url: host) do |faraday|
35
+ Faraday.new(url: host) do |faraday|
36
+ faraday.request :json # handle JSON payload
37
+ faraday.response :logger, NetsuiteApi.logger if NetsuiteApi.logger
35
38
  faraday.adapter Faraday.default_adapter
39
+ faraday.options.timeout = 10 # 10 seconds timeout
40
+ faraday.options.open_timeout = 5 # 5 seconds open timeout
36
41
  faraday.ssl.verify = true # You can set this to false if you have SSL verification issues
37
42
  end
38
43
  end
@@ -42,15 +47,10 @@ module NetsuiteApi
42
47
  end
43
48
 
44
49
  def authorization_header(url, method, query_params, host:)
45
- "OAuth realm=\"#{account_id}\",oauth_consumer_key=\"#{consumer_key}\",oauth_token=\"#{token}\",oauth_signature_method=\"HMAC-SHA256\",oauth_timestamp=\"#{oauth_timestamp}\",oauth_nonce=\"#{oauth_nonce}\",oauth_version=\"1.0\",oauth_signature=\"#{generate_oauth_signature(url, method, query_params, host: host)}\""
46
- end
50
+ timestamp = Time.now.to_i
51
+ nonce = SecureRandom.hex(16)
47
52
 
48
- def oauth_nonce
49
- @oauth_nonce = SecureRandom.hex(16)
50
- end
51
-
52
- def oauth_timestamp
53
- @oauth_timestamp = Time.now.to_i
53
+ "OAuth realm=\"#{account_id}\",oauth_consumer_key=\"#{consumer_key}\",oauth_token=\"#{token}\",oauth_signature_method=\"HMAC-SHA256\",oauth_timestamp=\"#{timestamp}\",oauth_nonce=\"#{nonce}\",oauth_version=\"1.0\",oauth_signature=\"#{generate_oauth_signature(url, method, query_params, host: host, timestamp: timestamp, nonce: nonce)}\""
54
54
  end
55
55
 
56
56
  def full_url(url, query_params)
@@ -65,14 +65,14 @@ module NetsuiteApi
65
65
  CGI.escape(url)
66
66
  end
67
67
 
68
- def generate_oauth_signature(url, http_method, query_params, host:)
68
+ def generate_oauth_signature(url, http_method, query_params, host:, timestamp:, nonce:)
69
69
  # Step 1: Combine parameters
70
70
  all_params = {
71
71
  'oauth_consumer_key' => consumer_key,
72
72
  'oauth_token' => token,
73
73
  'oauth_signature_method' => 'HMAC-SHA256',
74
- 'oauth_timestamp' => @oauth_timestamp,
75
- 'oauth_nonce' => @oauth_nonce, # Generate a random nonce
74
+ 'oauth_timestamp' => timestamp,
75
+ 'oauth_nonce' => nonce, # Generate a random nonce
76
76
  'oauth_version' => '1.0'
77
77
  }
78
78
  all_params.merge!(query_params) if query_params
@@ -90,7 +90,7 @@ module NetsuiteApi
90
90
  digest = OpenSSL::Digest.new('sha256')
91
91
  hmac = OpenSSL::HMAC.digest(digest, signing_key, sbs)
92
92
 
93
- oauth_signature = CGI.escape(Base64.encode64(hmac).chomp.gsub('\n', ''))
93
+ oauth_signature = CGI.escape(::Base64.encode64(hmac).chomp.gsub('\n', ''))
94
94
 
95
95
  oauth_signature
96
96
  end
@@ -1,11 +1,14 @@
1
+ require 'pry'
2
+
1
3
  module NetsuiteApi
2
4
  module Concerns
3
5
  module ResponseHandler
4
6
  class NetSuiteApiError < StandardError
5
7
  attr_reader :title, :details
6
- def initialize(msg, title, details)
8
+ def initialize(title, details)
7
9
  @title = title
8
10
  @details = details
11
+ msg = "#{title}: #{details}"
9
12
  super(msg)
10
13
  end
11
14
  end
@@ -20,7 +23,13 @@ module NetsuiteApi
20
23
 
21
24
  def post_and_patch_response_handler(response)
22
25
  if response.success?
23
- response.headers["location"].split('/').last
26
+ location = response.headers["location"]
27
+ if location
28
+ location.split('/').last
29
+ else
30
+ NetsuiteApi.logger.error("NetSuite API Error: No location header in response")
31
+ nil
32
+ end
24
33
  else
25
34
  error_handler(response)
26
35
  end
@@ -35,8 +44,17 @@ module NetsuiteApi
35
44
  end
36
45
 
37
46
  def error_handler(response)
38
- response_body = JSON.parse(response.body)
39
- raise NetSuiteApiError.new(response_body["title"], response_body["title"], response_body["o:errorDetails"])
47
+ begin
48
+ response_body = JSON.parse(response.body)
49
+ title = response_body["title"] || "NetSuite API Error"
50
+ details = response_body["o:errorDetails"] || "No additional details provided."
51
+ rescue JSON::ParserError
52
+ title = "Invalid API Response"
53
+ details = response.body.to_s.strip.empty? ? "Empty response body" : response.body
54
+ end
55
+
56
+ NetsuiteApi.logger.error("NetSuite API Error: #{title} - #{details}")
57
+ raise NetSuiteApiError.new(title, details)
40
58
  end
41
59
  end
42
60
  end
@@ -1,3 +1,3 @@
1
1
  module NetsuiteApi
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/netsuite_api.rb CHANGED
@@ -6,11 +6,16 @@ require "netsuite_api/contact"
6
6
  require "netsuite_api/payment"
7
7
  require "netsuite_api/vendor"
8
8
  require "netsuite_api/vendor_bill"
9
- require "pry"
9
+ require "logger"
10
+ # require "pry"
10
11
 
11
12
  module NetsuiteApi
12
- # class Error < StandardError; end
13
- # Your code goes here...
13
+ class << self
14
+ attr_accessor :logger
15
+ end
16
+
17
+ # 預設 Logger 為 STDOUT
18
+ self.logger = Logger.new(STDOUT)
14
19
 
15
20
  def self.hi
16
21
  "Hello World!"
data/netsuite_api.gemspec CHANGED
@@ -34,11 +34,11 @@ Gem::Specification.new do |spec|
34
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
35
  spec.require_paths = ["lib"]
36
36
 
37
- spec.add_development_dependency "bundler", "~> 1.17"
37
+ spec.add_development_dependency "bundler"
38
38
  spec.add_development_dependency "rake", "~> 10.0"
39
39
  spec.add_development_dependency "rspec", "~> 3.0"
40
40
  spec.add_development_dependency "webmock", "~> 3.0"
41
- # spec.add_development_dependency "pry",
41
+ spec.add_development_dependency "pry"
42
42
  spec.add_dependency "faraday"
43
43
  spec.add_dependency "activesupport"
44
44
  spec.add_dependency "securerandom"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsuite_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - HueiYi Lucy Cheng
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-07 00:00:00.000000000 Z
11
+ date: 2025-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.17'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.17'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: faraday
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +161,7 @@ metadata:
147
161
  homepage_uri: https://github.com/iceland101113/netsuite_api
148
162
  source_code_uri: https://github.com/iceland101113/netsuite_api
149
163
  changelog_uri: https://github.com/iceland101113/netsuite_api
150
- post_install_message:
164
+ post_install_message:
151
165
  rdoc_options: []
152
166
  require_paths:
153
167
  - lib
@@ -162,8 +176,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
176
  - !ruby/object:Gem::Version
163
177
  version: '0'
164
178
  requirements: []
165
- rubygems_version: 3.0.3.1
166
- signing_key:
179
+ rubygems_version: 3.5.9
180
+ signing_key:
167
181
  specification_version: 4
168
182
  summary: Ruby Library for NetSuite REST API.
169
183
  test_files: []