tcat 0.1.9 → 0.2.1
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/README.md +23 -1
- data/lib/tcat/http_client.rb +47 -4
- data/lib/tcat/query.rb +20 -3
- data/lib/tcat/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ad6c2ffd128652a809518fd30dc48b80cfaa4b67fed9316ac718b750aab81119
|
|
4
|
+
data.tar.gz: 10e9ecda054bee5aded67ccedace1fb173c65fc6ecd8ce72b84b55bf2f2c2230
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cb8df071bac9d109f97ab45e2a7981ce48ddcdebfad1384ff874cb4e314bfbd1a0b166bd9fe6ffd10dc68aacda986b80a802506a3d5d17398780fa05a76a4b73
|
|
7
|
+
data.tar.gz: b5bcf421668bfe8d684042a65ff8b4f263ae419fb2d777a59feaf634b5859aa9a03cfcaa462d489aa2a619e397a44be7efd816feb4848c3cbe0ad8c1a1e7547e
|
data/README.md
CHANGED
|
@@ -58,6 +58,7 @@ status = query.status_code
|
|
|
58
58
|
# :in_transit - In transit
|
|
59
59
|
# :returned - Return completed
|
|
60
60
|
# :held - Held at post office
|
|
61
|
+
# :rescheduled - Delivery time rescheduled
|
|
61
62
|
# :forwarding - Being forwarded
|
|
62
63
|
# :investigation - Under investigation
|
|
63
64
|
# :rejected - Delivery rejected
|
|
@@ -92,6 +93,7 @@ end
|
|
|
92
93
|
- `:in_transit` - In transit
|
|
93
94
|
- `:returned` - Return completed
|
|
94
95
|
- `:held` - Package is being held at post office
|
|
96
|
+
- `:rescheduled` - Delivery time rescheduled
|
|
95
97
|
- `:forwarding` - Package is being forwarded
|
|
96
98
|
- `:investigation` - Package is under investigation (e.g., address change, rejection)
|
|
97
99
|
- `:rejected` - Delivery was rejected
|
|
@@ -128,6 +130,26 @@ This gem is available as open source under the terms of the [MIT License](https:
|
|
|
128
130
|
|
|
129
131
|
## Changelog
|
|
130
132
|
|
|
133
|
+
### 0.2.1
|
|
134
|
+
|
|
135
|
+
- Updated base64 gem dependency to ~> 0.3
|
|
136
|
+
- Code formatting improvements
|
|
137
|
+
|
|
138
|
+
### 0.2.0
|
|
139
|
+
|
|
140
|
+
- Fixed SSL certificate verification issues with T-Cat API
|
|
141
|
+
- Added session initialization to obtain cookies before queries
|
|
142
|
+
- Added cookie management for maintaining session state
|
|
143
|
+
- Added new status code mappings: `:rescheduled` (另約時間) and `:held` (暫置營業所)
|
|
144
|
+
- Removed Rails.logger dependency for better standalone gem compatibility
|
|
145
|
+
- Added base64 gem dependency for Ruby 3.4+ compatibility
|
|
146
|
+
- Updated HTTP headers to match latest BlackCat iOS app (version 3)
|
|
147
|
+
- Improved error handling with better debug output
|
|
148
|
+
|
|
149
|
+
### 0.1.9
|
|
150
|
+
|
|
151
|
+
- Updated User-Agent and API version
|
|
152
|
+
|
|
131
153
|
### 0.1.7
|
|
132
154
|
|
|
133
155
|
- Improved method naming, removed get_ prefix
|
|
@@ -143,7 +165,7 @@ This gem is available as open source under the terms of the [MIT License](https:
|
|
|
143
165
|
- Improved error handling
|
|
144
166
|
- Added test coverage
|
|
145
167
|
|
|
146
|
-
### 0.1.5
|
|
168
|
+
### 0.1.5
|
|
147
169
|
|
|
148
170
|
- Refactored HTTP request handling with new HttpClient class
|
|
149
171
|
- Refactored encryption logic with new EncryptionService class
|
data/lib/tcat/http_client.rb
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'net/http'
|
|
4
|
+
require 'openssl'
|
|
4
5
|
|
|
5
6
|
module Tcat
|
|
6
7
|
class HttpClient
|
|
7
8
|
DEFAULT_HEADERS = {
|
|
8
|
-
'User-Agent' => 'BlackCat/
|
|
9
|
-
'Accept-Language' => '
|
|
10
|
-
'
|
|
9
|
+
'User-Agent' => 'BlackCat/3 (iPhone; iOS 26.2; Scale/3.00)',
|
|
10
|
+
'Accept-Language' => 'en-TW;q=1, zh-Hant-TW;q=0.9',
|
|
11
|
+
'Accept' => '*/*',
|
|
12
|
+
'Accept-Encoding' => 'gzip, deflate, br',
|
|
13
|
+
'Connection' => 'keep-alive'
|
|
11
14
|
}.freeze
|
|
12
15
|
|
|
13
16
|
API_ENDPOINT = 'https://www.t-cat.com.tw/iPhone/TCatApp.aspx'
|
|
@@ -15,8 +18,11 @@ module Tcat
|
|
|
15
18
|
|
|
16
19
|
class RequestError < StandardError; end
|
|
17
20
|
|
|
21
|
+
attr_reader :cookies
|
|
22
|
+
|
|
18
23
|
def initialize(timeout: 30)
|
|
19
24
|
@timeout = timeout
|
|
25
|
+
@cookies = {}
|
|
20
26
|
end
|
|
21
27
|
|
|
22
28
|
def post(params)
|
|
@@ -25,9 +31,13 @@ module Tcat
|
|
|
25
31
|
|
|
26
32
|
request = Net::HTTP::Post.new(uri)
|
|
27
33
|
DEFAULT_HEADERS.each { |key, value| request[key] = value }
|
|
34
|
+
request['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'
|
|
35
|
+
request['Cookie'] = build_cookie_header if @cookies.any?
|
|
28
36
|
request.body = URI.encode_www_form(params)
|
|
29
37
|
|
|
30
|
-
|
|
38
|
+
response = http.request(request)
|
|
39
|
+
extract_cookies(response)
|
|
40
|
+
handle_response(response)
|
|
31
41
|
rescue Net::ReadTimeout, Net::OpenTimeout => e
|
|
32
42
|
raise RequestError, "Request timeout: #{e.message}"
|
|
33
43
|
rescue SocketError, Net::HTTPError => e
|
|
@@ -36,11 +46,29 @@ module Tcat
|
|
|
36
46
|
raise RequestError, "Unexpected error: #{e.message}"
|
|
37
47
|
end
|
|
38
48
|
|
|
49
|
+
def initialize_session(secret)
|
|
50
|
+
params = {
|
|
51
|
+
f: 18,
|
|
52
|
+
secret: secret,
|
|
53
|
+
SVC: 'TCATAPP'
|
|
54
|
+
}
|
|
55
|
+
post(params)
|
|
56
|
+
end
|
|
57
|
+
|
|
39
58
|
private
|
|
40
59
|
|
|
41
60
|
def setup_http_client(uri)
|
|
42
61
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
43
62
|
http.use_ssl = true
|
|
63
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
64
|
+
|
|
65
|
+
# Setup certificate store without CRL checking
|
|
66
|
+
# This verifies the certificate chain but skips CRL validation
|
|
67
|
+
store = OpenSSL::X509::Store.new
|
|
68
|
+
store.set_default_paths
|
|
69
|
+
# Explicitly do not set V_FLAG_CRL_CHECK or V_FLAG_CRL_CHECK_ALL
|
|
70
|
+
http.cert_store = store
|
|
71
|
+
|
|
44
72
|
http.read_timeout = @timeout
|
|
45
73
|
http.open_timeout = @timeout
|
|
46
74
|
http
|
|
@@ -56,5 +84,20 @@ module Tcat
|
|
|
56
84
|
raise RequestError, "HTTP #{response.code}: #{response.message}"
|
|
57
85
|
end
|
|
58
86
|
end
|
|
87
|
+
|
|
88
|
+
def extract_cookies(response)
|
|
89
|
+
return unless response['Set-Cookie']
|
|
90
|
+
|
|
91
|
+
response.get_fields('Set-Cookie').each do |cookie_string|
|
|
92
|
+
cookie_string.split(';').first.split(',').each do |pair|
|
|
93
|
+
name, value = pair.strip.split('=', 2)
|
|
94
|
+
@cookies[name] = value if name && value
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def build_cookie_header
|
|
100
|
+
@cookies.map { |name, value| "#{name}=#{value}" }.join('; ')
|
|
101
|
+
end
|
|
59
102
|
end
|
|
60
103
|
end
|
data/lib/tcat/query.rb
CHANGED
|
@@ -19,6 +19,9 @@ module Tcat
|
|
|
19
19
|
@tracking_number = tracking_number
|
|
20
20
|
@http_client = HttpClient.new
|
|
21
21
|
@encryption_service = EncryptionService.new(@secret_key)
|
|
22
|
+
|
|
23
|
+
# Initialize session to get cookies
|
|
24
|
+
initialize_session
|
|
22
25
|
end
|
|
23
26
|
|
|
24
27
|
# Get current delivery status code
|
|
@@ -41,7 +44,7 @@ module Tcat
|
|
|
41
44
|
extract_delivery_history(result)
|
|
42
45
|
end
|
|
43
46
|
rescue StandardError => e
|
|
44
|
-
|
|
47
|
+
warn "Error getting delivery history: #{e.message}" if $DEBUG
|
|
45
48
|
[]
|
|
46
49
|
end
|
|
47
50
|
|
|
@@ -60,6 +63,18 @@ module Tcat
|
|
|
60
63
|
raise ArgumentError, 'SECRET_KEY must be configured' if @secret_key.nil? || @secret_key.empty?
|
|
61
64
|
end
|
|
62
65
|
|
|
66
|
+
def initialize_session
|
|
67
|
+
secret = generate_secret
|
|
68
|
+
@http_client.initialize_session(secret)
|
|
69
|
+
warn "Session initialized, cookies: #{@http_client.cookies.inspect}" if $DEBUG
|
|
70
|
+
rescue HttpClient::RequestError => e
|
|
71
|
+
warn "Failed to initialize session: #{e.message}"
|
|
72
|
+
warn e.backtrace.first(5).join("\n") if $DEBUG
|
|
73
|
+
rescue StandardError => e
|
|
74
|
+
warn "Unexpected error during session initialization: #{e.class} - #{e.message}"
|
|
75
|
+
warn e.backtrace.first(5).join("\n") if $DEBUG
|
|
76
|
+
end
|
|
77
|
+
|
|
63
78
|
def data
|
|
64
79
|
{
|
|
65
80
|
ConsignmentNo: @tracking_number,
|
|
@@ -99,7 +114,7 @@ module Tcat
|
|
|
99
114
|
|
|
100
115
|
parse_status_message(delivery_statuses.uniq)
|
|
101
116
|
rescue StandardError => e
|
|
102
|
-
|
|
117
|
+
warn "Error parsing T-Cat response: #{e.message}" if $DEBUG
|
|
103
118
|
:error
|
|
104
119
|
end
|
|
105
120
|
end
|
|
@@ -115,7 +130,7 @@ module Tcat
|
|
|
115
130
|
[]
|
|
116
131
|
end.compact.sort_by(&:time).reverse
|
|
117
132
|
rescue StandardError => e
|
|
118
|
-
|
|
133
|
+
warn "Error parsing delivery history: #{e.message}" if $DEBUG
|
|
119
134
|
[]
|
|
120
135
|
end
|
|
121
136
|
|
|
@@ -165,6 +180,8 @@ module Tcat
|
|
|
165
180
|
'轉運中' => :in_transit,
|
|
166
181
|
'退貨完成' => :returned,
|
|
167
182
|
'暫置營業所保管中' => :held,
|
|
183
|
+
'暫置營業所' => :held,
|
|
184
|
+
'另約時間' => :rescheduled,
|
|
168
185
|
'轉寄配送中' => :forwarding,
|
|
169
186
|
'搬家(調查處理中)' => :investigation,
|
|
170
187
|
'拒收(調查處理中)' => :investigation,
|
data/lib/tcat/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tcat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Zac
|
|
@@ -9,6 +9,20 @@ bindir: exe
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: base64
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.3'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0.3'
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: ox
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -78,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
78
92
|
- !ruby/object:Gem::Version
|
|
79
93
|
version: '0'
|
|
80
94
|
requirements: []
|
|
81
|
-
rubygems_version: 3.6.
|
|
95
|
+
rubygems_version: 3.6.9
|
|
82
96
|
specification_version: 4
|
|
83
97
|
summary: A Ruby gem for tracking packages using the Tcat system.
|
|
84
98
|
test_files: []
|