netsuite_api 0.1.4 → 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 +4 -4
- data/Gemfile.lock +47 -26
- data/lib/netsuite_api/base.rb +14 -14
- data/lib/netsuite_api/concerns/response_handler.rb +22 -4
- data/lib/netsuite_api/version.rb +1 -1
- data/lib/netsuite_api.rb +8 -3
- data/netsuite_api.gemspec +2 -2
- metadata +24 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b861b814e33ac144071c716dddf8521a841f93b326bb6fd7e5f8ebb8080adfac
|
4
|
+
data.tar.gz: c94c8a38c727d9bad116b7191e518e95c5651a2c675d308b45ccc7c798599846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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 (
|
13
|
-
|
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
|
-
|
17
|
-
|
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
|
-
|
22
|
-
|
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.
|
27
|
-
|
28
|
-
|
29
|
-
faraday-net_http (>= 2.0, < 3.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
36
|
-
|
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.
|
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.
|
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.
|
52
|
-
|
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
|
-
|
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
|
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
|
-
|
94
|
+
2.5.9
|
data/lib/netsuite_api/base.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'securerandom'
|
3
3
|
require 'active_support/core_ext/object'
|
4
|
-
require
|
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
|
-
|
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
|
-
|
46
|
-
|
50
|
+
timestamp = Time.now.to_i
|
51
|
+
nonce = SecureRandom.hex(16)
|
47
52
|
|
48
|
-
|
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' =>
|
75
|
-
'oauth_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(
|
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"]
|
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
|
-
|
39
|
-
|
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
|
data/lib/netsuite_api/version.rb
CHANGED
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 "
|
9
|
+
require "logger"
|
10
|
+
# require "pry"
|
10
11
|
|
11
12
|
module NetsuiteApi
|
12
|
-
|
13
|
-
|
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"
|
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
|
-
|
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.
|
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:
|
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: '
|
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: '
|
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.
|
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: []
|