robodash 0.1.0 → 0.2.0
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/lib/robodash/version.rb +1 -1
- data/lib/robodash.rb +75 -26
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65059c95fa5cea36a3ea54ee951bb94e3ff334a1fb5eeab87ce21ac415da9916
|
4
|
+
data.tar.gz: 3907f86684c81227d4c1a0f531ddd947057c65460f2fcedcdc7f7d81b5f94edd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e8b1a4e239ddd79ac6153338bc16dad795055c1b7b571644efbcddc6f43445f4018654bf26d9dc8e9806895b5562c1b399404903c0bf1ebbfd745cb320aeaac
|
7
|
+
data.tar.gz: a2126467af0fc8216e6436e1c9baa1c47fc47c78fe16da0cb547e0edf31df4028681c84b1dda6f6e2ab412cb110a73ce690ff7fefa51e8ae49f573c5468ca4c0
|
data/lib/robodash/version.rb
CHANGED
data/lib/robodash.rb
CHANGED
@@ -1,46 +1,95 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "robodash/version"
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
6
|
+
require "json"
|
4
7
|
|
5
8
|
module Robodash
|
6
|
-
|
9
|
+
# Defaults
|
10
|
+
DEFAULT_HOST = "https://robodash.app"
|
11
|
+
OPEN_TIMEOUT = 2
|
12
|
+
READ_TIMEOUT = 5
|
7
13
|
|
8
14
|
class << self
|
9
|
-
attr_accessor :api_token
|
15
|
+
attr_accessor :api_token, :host, :enabled
|
10
16
|
|
11
|
-
def
|
12
|
-
|
17
|
+
def enabled?
|
18
|
+
return true if @enabled.nil?
|
19
|
+
@enabled
|
20
|
+
end
|
21
|
+
|
22
|
+
# Possible schedules:
|
23
|
+
# - minutely
|
24
|
+
# - hourly
|
25
|
+
# - daily
|
26
|
+
# - weekly
|
27
|
+
# - monthly
|
28
|
+
# - yearly
|
29
|
+
def ping(name, schedule_number = 1, schedule_period = "day", grace_period: 1.minute)
|
30
|
+
fire_and_forget("ping", {
|
31
|
+
name: name,
|
32
|
+
schedule_number: schedule_number,
|
33
|
+
schedule_period: schedule_period,
|
34
|
+
grace_period: grace_period.to_i
|
35
|
+
})
|
13
36
|
end
|
14
37
|
|
15
38
|
# Count should always be an integer
|
16
|
-
def count(name, count)
|
17
|
-
|
39
|
+
def count(name, count, range = nil)
|
40
|
+
fire_and_forget("count", {name: name, count: count.to_i})
|
18
41
|
end
|
19
42
|
|
20
43
|
private
|
21
44
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
34
|
-
http.open_timeout = 5
|
35
|
-
http.read_timeout = 10
|
36
|
-
http.request(request)
|
37
|
-
end
|
45
|
+
def fire_and_forget(endpoint, body)
|
46
|
+
return false unless enabled?
|
47
|
+
return false unless api_token
|
48
|
+
|
49
|
+
Thread.new do
|
50
|
+
Thread.current.abort_on_exception = false
|
51
|
+
|
52
|
+
begin
|
53
|
+
send_api_request(endpoint, body)
|
54
|
+
rescue => e
|
55
|
+
warn_safely("Robodash request failed: #{e.class} - #{e.message}")
|
38
56
|
end
|
39
|
-
true
|
40
|
-
rescue StandardError => e
|
41
|
-
warn "Failed to ping Robodash: #{e.message}"
|
42
|
-
false
|
43
57
|
end
|
58
|
+
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
def send_api_request(endpoint, body)
|
63
|
+
uri = URI("#{host}/api/#{endpoint}.json")
|
64
|
+
|
65
|
+
request = Net::HTTP::Post.new(uri)
|
66
|
+
request["Authorization"] = "dashboard-token #{api_token}"
|
67
|
+
request["Content-Type"] = "application/json"
|
68
|
+
request.body = body.to_json
|
69
|
+
|
70
|
+
# Use aggressive timeouts for fire-and-forget
|
71
|
+
Net::HTTP.start(uri.hostname, uri.port,
|
72
|
+
use_ssl: uri.scheme == "https",
|
73
|
+
open_timeout: OPEN_TIMEOUT,
|
74
|
+
read_timeout: READ_TIMEOUT,
|
75
|
+
ssl_timeout: OPEN_TIMEOUT) do |http|
|
76
|
+
http.request(request)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Only warn if we're in a context where it's safe to do so
|
81
|
+
def warn_safely(message)
|
82
|
+
if defined?(Rails) && Rails.logger
|
83
|
+
Rails.logger.warn("[Robodash] #{message}")
|
84
|
+
elsif $stderr && !$stderr.closed?
|
85
|
+
$stderr.puts("[Robodash] #{message}")
|
86
|
+
end
|
87
|
+
rescue
|
88
|
+
# If even logging fails, just silently continue
|
89
|
+
end
|
90
|
+
|
91
|
+
def host
|
92
|
+
@host || DEFAULT_HOST
|
44
93
|
end
|
45
94
|
|
46
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robodash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bram Jetten
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Robodash is a lightweight Ruby gem for sending POST requests to Robodash's
|
14
14
|
API. It is designed to be simple to use, with support for API tokens and background
|
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
requirements: []
|
47
|
-
rubygems_version: 3.5.
|
47
|
+
rubygems_version: 3.5.16
|
48
48
|
signing_key:
|
49
49
|
specification_version: 4
|
50
50
|
summary: A simple gem to send asynchronous POST requests to Robodash.
|