skink-sdk 0.1.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 +7 -0
- data/lib/skink.rb +93 -0
- metadata +43 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e365da613e60c986c16faeaca3cad943ff957b8ee29cd7b53f817355ba478974
|
|
4
|
+
data.tar.gz: bc66b3016edcc0eaffcd5d526d307aa13c7f757ed9466f1514912c265b8af5a3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1fd79a34a16e6c274c45079221a1208de3fb2cbd09802db49855fdaadaf02fdfa56312dd428656316a0296a7aff272fa4f3e685967d55657b377329fc4f97663
|
|
7
|
+
data.tar.gz: 11e697c84e11d2635ec4245419140aa24f8bb7ed3d34df701d2aba0f1e2fe3278ac63dbde5e7436f902b318be4fe5427e65c7ae4b1fc67db882f83575ecce9c7
|
data/lib/skink.rb
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
require "net/http"
|
|
2
|
+
require "json"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Skink
|
|
6
|
+
class Error < StandardError
|
|
7
|
+
attr_reader :status, :code
|
|
8
|
+
|
|
9
|
+
def initialize(status, code, message)
|
|
10
|
+
super(message)
|
|
11
|
+
@status = status
|
|
12
|
+
@code = code
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Official server-side client for the skink email verification API.
|
|
17
|
+
#
|
|
18
|
+
# Never use this in code that ships to a browser or mobile app — the API
|
|
19
|
+
# key is a secret credential. Load it from a server-side environment
|
|
20
|
+
# variable (ENV["SKINK_API_KEY"]), never a literal string in source.
|
|
21
|
+
class Client
|
|
22
|
+
def initialize(api_key, base_url: "https://api.skink.dev", timeout: 30)
|
|
23
|
+
raise ArgumentError, "Client requires an api_key (from a server-side env var, not a literal)." if api_key.nil? || api_key.empty?
|
|
24
|
+
|
|
25
|
+
@api_key = api_key
|
|
26
|
+
@base_url = base_url.chomp("/")
|
|
27
|
+
@timeout = timeout
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def verify(email, timeout_ms: nil, idempotency_key: nil)
|
|
31
|
+
body = { email: email }
|
|
32
|
+
body[:timeout_ms] = timeout_ms if timeout_ms
|
|
33
|
+
headers = idempotency_key ? { "Idempotency-Key" => idempotency_key } : {}
|
|
34
|
+
request(:post, "/v1/verify", body: body.to_json, headers: headers)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def upload_file(csv_bytes)
|
|
38
|
+
request(:post, "/v1/files", body: csv_bytes, content_type: "text/csv")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def bulk_create(emails: nil, file_id: nil, callback_url: nil)
|
|
42
|
+
source = {}
|
|
43
|
+
source[:emails] = emails if emails
|
|
44
|
+
source[:file_id] = file_id if file_id
|
|
45
|
+
body = { source: source }
|
|
46
|
+
body[:callback_url] = callback_url if callback_url
|
|
47
|
+
request(:post, "/v1/bulk", body: body.to_json)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def bulk_list
|
|
51
|
+
request(:get, "/v1/bulk")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def bulk_status(job_id)
|
|
55
|
+
request(:get, "/v1/bulk/#{URI::DEFAULT_PARSER.escape(job_id)}")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def bulk_results(job_id)
|
|
59
|
+
request(:get, "/v1/bulk/#{URI::DEFAULT_PARSER.escape(job_id)}/results")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
protected
|
|
63
|
+
|
|
64
|
+
def request(method, path, body: nil, content_type: "application/json", headers: {})
|
|
65
|
+
uri = URI("#{@base_url}#{path}")
|
|
66
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
67
|
+
http.use_ssl = uri.scheme == "https"
|
|
68
|
+
http.open_timeout = @timeout
|
|
69
|
+
http.read_timeout = @timeout
|
|
70
|
+
|
|
71
|
+
req_class = method == :post ? Net::HTTP::Post : Net::HTTP::Get
|
|
72
|
+
req = req_class.new(uri)
|
|
73
|
+
req["Authorization"] = "Bearer #{@api_key}"
|
|
74
|
+
req["Content-Type"] = content_type
|
|
75
|
+
headers.each { |k, v| req[k] = v }
|
|
76
|
+
req.body = body if body
|
|
77
|
+
|
|
78
|
+
res = http.request(req)
|
|
79
|
+
begin
|
|
80
|
+
parsed = res.body && !res.body.empty? ? JSON.parse(res.body) : {}
|
|
81
|
+
rescue JSON::ParserError
|
|
82
|
+
raise if res.is_a?(Net::HTTPSuccess)
|
|
83
|
+
parsed = {}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
unless res.is_a?(Net::HTTPSuccess)
|
|
87
|
+
raise Error.new(res.code.to_i, parsed["error"] || "unknown_error", parsed["message"] || res.message)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
parsed
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: skink-sdk
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- skink
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-09-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/skink.rb
|
|
20
|
+
homepage: https://skink.dev
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '3.0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubygems_version: 3.0.3.1
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: Official server-side Ruby client for the skink email verification API
|
|
43
|
+
test_files: []
|