aliyun_intelligent_captcha 0.1.1 → 0.1.3

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: 439870b8fbbf4efa1096f018d4a6da7c16e94c37ad69d9004ac1184343ac5723
4
- data.tar.gz: 9c3ff9d33936d52d0fc8a1146a6b33f183e9f664db6dbcaf51312955a5413831
3
+ metadata.gz: 26a561b0a86a449d4ab75f8f0705bdc10a0b6c62f35545ce088d2708aee26236
4
+ data.tar.gz: 56ce891e98ef0f5304ada858170834b467087cee347318786ca345f85bbce1b3
5
5
  SHA512:
6
- metadata.gz: e8c947510d890025ac956b903b12bfc80f7446418aa869a9a2751c0b756e418ae88e696dbf73daf24a0e2825c8712351f01d9262cc7ea1e1e2f6164e698eee8d
7
- data.tar.gz: af45e038d8cc9a4f278fb6436000ac3b06e2a5b0c41034fed5f91e335370629bc4192a9ed2d76d88b7954f6e57fb4d7f436ad600c2cdcd4b6bf90458aa91c01c
6
+ metadata.gz: 68d4155f0b9ed5d8e56a0b95f1a0f704d6662c9f331ac35dfad9fd060cc0fdf8ff929086d717a55782bb662e3501abca41d98dd175d47a97ff9130a75b254dbf
7
+ data.tar.gz: c13e6bc3ee2f65d03982c91e3e390c659d2dd6e44cec4de1214117c9888df334d73c76c8d949711aabaa3089fdfef01e2be8b61b3aef5ea2113cfdd3ab1250c1
data/README.md CHANGED
@@ -4,6 +4,15 @@ Ruby gem for verifying Alibaba Cloud intelligent captcha tokens with the `Verify
4
4
 
5
5
  It has no runtime dependency on the Alibaba Cloud SDK. The client signs requests with Alibaba Cloud ACS3-HMAC-SHA256 and uses Ruby's standard `Net::HTTP`.
6
6
 
7
+ ## Changelog
8
+
9
+ See [CHANGELOG.md](CHANGELOG.md) for version history and release notes.
10
+
11
+ ## Latest Release
12
+
13
+ - `0.1.1`
14
+ - Fix railtie inheritance to use top-level `::Rails::Railtie`, preventing constant lookup conflicts in Rails apps.
15
+
7
16
  ## Installation
8
17
 
9
18
  Add this line to your application's Gemfile:
@@ -15,7 +15,7 @@ require_relative "result"
15
15
  module AliyunIntelligentCaptcha
16
16
  class Client
17
17
  ACTION = "VerifyIntelligentCaptcha"
18
- CONTENT_TYPE = "application/json; charset=utf-8"
18
+ CONTENT_TYPE = "application/x-www-form-urlencoded"
19
19
  SIGNATURE_ALGORITHM = "ACS3-HMAC-SHA256"
20
20
 
21
21
  def initialize(access_key_id:,
@@ -57,12 +57,15 @@ module AliyunIntelligentCaptcha
57
57
 
58
58
  def perform_request(payload)
59
59
  uri = URI::HTTPS.build(host: @endpoint, path: "/")
60
- body = JSON.generate(payload)
60
+ body = URI.encode_www_form(payload)
61
61
  request = Net::HTTP::Post.new(uri)
62
62
  request.body = body
63
63
  signed_headers(body).each { |key, value| request[key] = value }
64
+ @logger&.info("[aliyun_intelligent_captcha] request: POST https://#{@endpoint}/ body=#{body.inspect}")
64
65
 
65
66
  response = @http_client ? @http_client.call(request, uri) : net_http_request(uri, request)
67
+ @logger&.info("[aliyun_intelligent_captcha] response: status=#{response.code} body=#{response.body}")
68
+
66
69
  validate_response!(response)
67
70
  response
68
71
  rescue Timeout::Error, SocketError, SystemCallError, OpenSSL::SSL::SSLError => error
@@ -12,7 +12,7 @@ module AliyunIntelligentCaptcha
12
12
  def passed?
13
13
  truthy?(fetch_value("VerifyResult")) ||
14
14
  truthy?(fetch_value("Passed")) ||
15
- truthy?(fetch_value("Result")) ||
15
+ verify_result_from_result_hash? ||
16
16
  success_code?
17
17
  end
18
18
 
@@ -45,5 +45,12 @@ module AliyunIntelligentCaptcha
45
45
  def truthy?(value)
46
46
  value == true || value.to_s.casecmp("true").zero? || value.to_s == "1"
47
47
  end
48
+
49
+ def verify_result_from_result_hash?
50
+ result = fetch_value("Result")
51
+ return false unless result.is_a?(Hash)
52
+
53
+ truthy?(result["VerifyResult"]) || (result["VerifyCode"] == "T001")
54
+ end
48
55
  end
49
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AliyunIntelligentCaptcha
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliyun_intelligent_captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ming