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 +4 -4
- data/README.md +5 -1
- data/lib/closeyourit/transport.rb +24 -1
- data/lib/closeyourit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b015462d6b0e563ef202410b5f2bc33b11ee10f985d984ac84a874836f67c82e
|
|
4
|
+
data.tar.gz: 41f3e3ca878dbfbfd818cd4963b238d1d78400344e0e8bbb95cfd025853ebf82
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 =
|
|
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
|
data/lib/closeyourit/version.rb
CHANGED