netsuite_api 0.1.4 → 0.1.6
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 +1 -2
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44b137ba7701fb8323c6d5c331a57ab1f54805cba23fb10cc49818a7784d108a
|
4
|
+
data.tar.gz: 6eba868bf5886e06f4a13b0c2bd943dd8bc909dce325c297de6eb0645fc79ea7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8aa4487dff624b07c217c406bc457b573f5cc0cbbdfe3e0908a58a5501ea6888b78238ed309ded49e507e3b86bfcdea1f4fb991e585f9bb29aad318df837a66
|
7
|
+
data.tar.gz: 3fe6572a13e4f83f8c864c54508456ce422c5bb595d2a56668ef32fb15ed6c2ab3cdcec1f3189a8b1d2ca10eb65e351b84d053d38c9358350e7ad34d65b59690
|
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.5)
|
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,10 @@ 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
|
-
# spec.add_development_dependency "pry",
|
42
41
|
spec.add_dependency "faraday"
|
43
42
|
spec.add_dependency "activesupport"
|
44
43
|
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.6
|
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
|
@@ -147,7 +147,7 @@ metadata:
|
|
147
147
|
homepage_uri: https://github.com/iceland101113/netsuite_api
|
148
148
|
source_code_uri: https://github.com/iceland101113/netsuite_api
|
149
149
|
changelog_uri: https://github.com/iceland101113/netsuite_api
|
150
|
-
post_install_message:
|
150
|
+
post_install_message:
|
151
151
|
rdoc_options: []
|
152
152
|
require_paths:
|
153
153
|
- lib
|
@@ -162,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
|
-
rubygems_version: 3.
|
166
|
-
signing_key:
|
165
|
+
rubygems_version: 3.5.9
|
166
|
+
signing_key:
|
167
167
|
specification_version: 4
|
168
168
|
summary: Ruby Library for NetSuite REST API.
|
169
169
|
test_files: []
|