closeyourit-ruby 0.2.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d841fba2147566f662dce067e2d41c44d44cf6d402fb929fc3c73eb9a6af4a1
4
- data.tar.gz: cf7b435c2c9a336f107930ded5fc2ad197032a5d62eeca07f25594775a111bcc
3
+ metadata.gz: b015462d6b0e563ef202410b5f2bc33b11ee10f985d984ac84a874836f67c82e
4
+ data.tar.gz: 41f3e3ca878dbfbfd818cd4963b238d1d78400344e0e8bbb95cfd025853ebf82
5
5
  SHA512:
6
- metadata.gz: a5172771940399ca5f3f2706e35d3c72d16942b79e0b2bbb89f0dfa184e4a66d45f7644704d45b6fb8f62f645b01bc84e75d7abe1d8a08ae0fced77e87781dcf
7
- data.tar.gz: dc9b5cc1387ecfb81b70a58815c0f79f7e68f1aeda98c2d3af14d0862f2dd28878a6803a1193e2737c4d8990b833c2aadf0d4461b393a26810957a1b6f0749d0
6
+ metadata.gz: 16d70f8ef7436397d881a8f67664f24aaabfe3ae976d5b23276149242bf8f539d1c5dc1d27f9d7c8a2c72a080ab42b2b56c11ec8af1e0fae108e06f5bf8cfbdc
7
+ data.tar.gz: '02853ab18aad59772dd4aa0cc497c32983e4e49f2926d2b42d28654552dabad1c0f9dacd589fc0423c920cbb1ea903457a35767365130777dc4d0317282e7225'
data/README.md CHANGED
@@ -45,7 +45,7 @@ In CloseYourIt, area **Member → Project → tokens**, crea un token: ottieni i
45
45
  ```ruby
46
46
  # config/initializers/closeyourit.rb
47
47
  CloseYourIt.init do |c|
48
- c.endpoint_url = ENV["CLOSEYOURIT_ENDPOINT_URL"] # es. https://closeyour.it
48
+ c.endpoint_url = ENV["CLOSEYOURIT_ENDPOINT_URL"] # es. https://www.closeyour.it (host canonico)
49
49
  c.token = ENV["CLOSEYOURIT_TOKEN"] # Bearer secret del Projects::Token
50
50
  c.project_id = ENV["CLOSEYOURIT_PROJECT_ID"] # UUID del progetto su CloseYourIt
51
51
  c.environment = Rails.env
@@ -55,6 +55,10 @@ end
55
55
  **Senza `endpoint_url` / `token` / `project_id` la gemma è no-op** (nessun invio, nessun overhead). In
56
56
  `production` un `endpoint_url` `http://` viene rifiutato (no-op + warning): il token viaggerebbe in chiaro.
57
57
 
58
+ > **Endpoint:** usa l'host canonico **`https://www.closeyour.it`**. La gemma segue fino a 2 redirect su POST
59
+ > (preservando metodo e body), quindi anche l'apex `https://closeyour.it` (301 → www) funziona — ma puntare
60
+ > direttamente a www risparmia un hop per ogni evento.
61
+
58
62
  ### Opzioni
59
63
 
60
64
  | Opzione | Default | Descrizione |
@@ -10,6 +10,9 @@ module CloseYourIt
10
10
  class Transport
11
11
  OPEN_TIMEOUT = 2
12
12
  READ_TIMEOUT = 3
13
+ # Net::HTTP non segue i redirect da solo. L'host canonico può rispondere 301 (es. apex → www):
14
+ # ri-POSTiamo a Location preservando metodo + body, così l'evento non si perde in silenzio.
15
+ MAX_REDIRECTS = 2
13
16
 
14
17
  def initialize(configuration)
15
18
  @configuration = configuration
@@ -25,7 +28,21 @@ module CloseYourIt
25
28
  private
26
29
 
27
30
  def post(payload, path)
31
+ body = JSON.generate(payload)
28
32
  uri = URI.parse("#{base_url}#{path}")
33
+ redirects = 0
34
+
35
+ loop do
36
+ response = post_once(uri, body)
37
+ location = response["location"] if response.is_a?(Net::HTTPRedirection)
38
+ return response unless location && redirects < MAX_REDIRECTS
39
+
40
+ redirects += 1
41
+ uri = redirect_uri(uri, location)
42
+ end
43
+ end
44
+
45
+ def post_once(uri, body)
29
46
  http = Net::HTTP.new(uri.host, uri.port)
30
47
  http.use_ssl = uri.scheme == "https"
31
48
  http.open_timeout = OPEN_TIMEOUT
@@ -35,11 +52,17 @@ module CloseYourIt
35
52
  request["Authorization"] = "Bearer #{@configuration.token}"
36
53
  request["Content-Type"] = "application/json"
37
54
  request["User-Agent"] = "closeyourit-ruby/#{VERSION}"
38
- request.body = JSON.generate(payload)
55
+ request.body = body
39
56
 
40
57
  http.request(request)
41
58
  end
42
59
 
60
+ # Location può essere assoluto (https://www.…) o relativo (/api/…): risolvilo sull'URI corrente.
61
+ def redirect_uri(current, location)
62
+ target = URI.parse(location)
63
+ target.relative? ? current + target : target
64
+ end
65
+
43
66
  def base_url
44
67
  @configuration.endpoint_url.to_s.chomp("/")
45
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloseYourIt
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: closeyourit-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessio Bussolari