sprites-ruby 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/LICENSE +21 -0
- data/README.md +20 -0
- data/lib/sprites/client.rb +78 -0
- data/lib/sprites/collection.rb +17 -0
- data/lib/sprites/configuration.rb +11 -0
- data/lib/sprites/resources/checkpoints.rb +27 -0
- data/lib/sprites/resources/policies.rb +19 -0
- data/lib/sprites/resources/sprites.rb +25 -0
- data/lib/sprites/sprite.rb +24 -0
- data/lib/sprites/version.rb +5 -0
- data/lib/sprites.rb +28 -0
- metadata +68 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 696d67a3d2015a55e8eb2e5b6179e37b2594eecbd49c4f355000fc246e45827b
|
|
4
|
+
data.tar.gz: db6806ee207f88f94a251af9a5681d6c68b2910aa9b5f54d2db627f07bc55209
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fcd1a087a9373e8c3a4d2cd82f2acd6070e5a78645c8b0e893310f2913585f805f0f4486d9a6475d1a3e4cd2dc271893af8b3b175deddb0a4bea15a12ae8d897
|
|
7
|
+
data.tar.gz: 1507c816cf3081bd407e391ab067160d04e4dd35cfd25a637a4e80ac7bad0bfecb880bb6f690f5058b4c2782980e99ad90644e87db5eb191039d11aff86d2a74
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ara Hacopian
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "faraday"
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
module Sprites
|
|
7
|
+
class Client
|
|
8
|
+
def initialize(token: nil, base_url: nil)
|
|
9
|
+
@token = token || Sprites.configuration.token
|
|
10
|
+
@base_url = base_url || Sprites.configuration.base_url
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def sprites
|
|
14
|
+
Resources::Sprites.new(self)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def checkpoints
|
|
18
|
+
Resources::Checkpoints.new(self)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def policies
|
|
22
|
+
Resources::Policies.new(self)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def get(path) = handle_response(connection.get(path))
|
|
26
|
+
|
|
27
|
+
def post(path, body) = handle_response(connection.post(path, body.to_json, "Content-Type" => "application/json"))
|
|
28
|
+
|
|
29
|
+
def put(path, body) = handle_response(connection.put(path, body.to_json, "Content-Type" => "application/json"))
|
|
30
|
+
|
|
31
|
+
def delete(path) = handle_response(connection.delete(path))
|
|
32
|
+
|
|
33
|
+
def post_stream(path, body, &block)
|
|
34
|
+
response = connection.post(path, body.to_json, "Content-Type" => "application/json")
|
|
35
|
+
|
|
36
|
+
raise_error(response.body) unless response.success?
|
|
37
|
+
|
|
38
|
+
events = parse_ndjson(response.body)
|
|
39
|
+
|
|
40
|
+
if (error_event = events.find { |e| e[:type] == "error" })
|
|
41
|
+
raise Error, error_event[:error]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
block_given? ? events.each(&block) : events
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def handle_response(response)
|
|
50
|
+
case response.status
|
|
51
|
+
in 204
|
|
52
|
+
nil
|
|
53
|
+
in 200..299
|
|
54
|
+
parse_json(response.body)
|
|
55
|
+
else
|
|
56
|
+
raise_error(response.body)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def raise_error(body)
|
|
61
|
+
parsed = parse_json(body)
|
|
62
|
+
message = parsed[:error] || parsed[:errors]&.join(", ") || "Unknown error"
|
|
63
|
+
raise Error, message
|
|
64
|
+
rescue JSON::ParserError
|
|
65
|
+
raise Error, body.strip
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def parse_json(json) = JSON.parse(json, symbolize_names: true)
|
|
69
|
+
|
|
70
|
+
def parse_ndjson(body) = body.each_line.map { parse_json(it) }
|
|
71
|
+
|
|
72
|
+
def connection
|
|
73
|
+
@connection ||= Faraday.new(url: @base_url) do |f|
|
|
74
|
+
f.request :authorization, "Bearer", @token
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sprites
|
|
4
|
+
class Collection
|
|
5
|
+
attr_reader :sprites, :next_continuation_token
|
|
6
|
+
|
|
7
|
+
def initialize(sprites:, has_more:, next_continuation_token:)
|
|
8
|
+
@sprites = sprites
|
|
9
|
+
@has_more = has_more
|
|
10
|
+
@next_continuation_token = next_continuation_token
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def has_more?
|
|
14
|
+
@has_more && !@next_continuation_token.nil?
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sprites
|
|
4
|
+
module Resources
|
|
5
|
+
class Checkpoints
|
|
6
|
+
def initialize(client)
|
|
7
|
+
@client = client
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def list(sprite_name)
|
|
11
|
+
@client.get("/v1/sprites/#{sprite_name}/checkpoints")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def retrieve(sprite_name, checkpoint_id)
|
|
15
|
+
@client.get("/v1/sprites/#{sprite_name}/checkpoints/#{checkpoint_id}")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def create(sprite_name, comment: nil, &block)
|
|
19
|
+
@client.post_stream("/v1/sprites/#{sprite_name}/checkpoint", { comment: }, &block)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def restore(sprite_name, checkpoint_id, &block)
|
|
23
|
+
@client.post_stream("/v1/sprites/#{sprite_name}/checkpoints/#{checkpoint_id}/restore", {}, &block)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sprites
|
|
4
|
+
module Resources
|
|
5
|
+
class Policies
|
|
6
|
+
def initialize(client)
|
|
7
|
+
@client = client
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def retrieve(sprite_name)
|
|
11
|
+
@client.get("/v1/sprites/#{sprite_name}/policies")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def update(sprite_name, **attrs)
|
|
15
|
+
@client.post("/v1/sprites/#{sprite_name}/policies", attrs)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sprites
|
|
4
|
+
module Resources
|
|
5
|
+
class Sprites
|
|
6
|
+
def initialize(client)
|
|
7
|
+
@client = client
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def list
|
|
11
|
+
@client.get("/v1/sprites") => { sprites:, has_more:, next_continuation_token: }
|
|
12
|
+
sprites = sprites.map(&Sprite)
|
|
13
|
+
Collection.new(sprites:, has_more:, next_continuation_token:)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def retrieve(name) = @client.get("/v1/sprites/#{name}").then(&Sprite)
|
|
17
|
+
|
|
18
|
+
def create(name:) = @client.post("/v1/sprites", { name: }).then(&Sprite)
|
|
19
|
+
|
|
20
|
+
def update(name, **attrs) = @client.put("/v1/sprites/#{name}", attrs).then(&Sprite)
|
|
21
|
+
|
|
22
|
+
def delete(name) = @client.delete("/v1/sprites/#{name}")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sprites
|
|
4
|
+
class Sprite
|
|
5
|
+
def self.to_proc = ->(attrs) { new(**attrs) }
|
|
6
|
+
|
|
7
|
+
attr_reader :id, :name, :status, :version, :url, :created_at, :updated_at,
|
|
8
|
+
:organization, :url_settings, :environment_version
|
|
9
|
+
|
|
10
|
+
def initialize(id:, name:, status:, version:, url:, created_at:, updated_at:,
|
|
11
|
+
organization:, url_settings:, environment_version:)
|
|
12
|
+
@id = id
|
|
13
|
+
@name = name
|
|
14
|
+
@status = status
|
|
15
|
+
@version = version
|
|
16
|
+
@url = url
|
|
17
|
+
@created_at = created_at
|
|
18
|
+
@updated_at = updated_at
|
|
19
|
+
@organization = organization
|
|
20
|
+
@url_settings = url_settings
|
|
21
|
+
@environment_version = environment_version
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/sprites.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "sprites/version"
|
|
4
|
+
require_relative "sprites/configuration"
|
|
5
|
+
require_relative "sprites/collection"
|
|
6
|
+
require_relative "sprites/sprite"
|
|
7
|
+
require_relative "sprites/resources/sprites"
|
|
8
|
+
require_relative "sprites/resources/checkpoints"
|
|
9
|
+
require_relative "sprites/resources/policies"
|
|
10
|
+
require_relative "sprites/client"
|
|
11
|
+
|
|
12
|
+
module Sprites
|
|
13
|
+
class Error < StandardError; end
|
|
14
|
+
|
|
15
|
+
class << self
|
|
16
|
+
def configuration
|
|
17
|
+
@configuration ||= Configuration.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def configure
|
|
21
|
+
yield(configuration)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def reset_configuration
|
|
25
|
+
@configuration = Configuration.new
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sprites-ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ara Hacopian
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: faraday
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.0'
|
|
26
|
+
description: Ruby client for the Sprites API - stateful sandbox environments
|
|
27
|
+
email:
|
|
28
|
+
- ara@hacopian.de
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- LICENSE
|
|
34
|
+
- README.md
|
|
35
|
+
- lib/sprites.rb
|
|
36
|
+
- lib/sprites/client.rb
|
|
37
|
+
- lib/sprites/collection.rb
|
|
38
|
+
- lib/sprites/configuration.rb
|
|
39
|
+
- lib/sprites/resources/checkpoints.rb
|
|
40
|
+
- lib/sprites/resources/policies.rb
|
|
41
|
+
- lib/sprites/resources/sprites.rb
|
|
42
|
+
- lib/sprites/sprite.rb
|
|
43
|
+
- lib/sprites/version.rb
|
|
44
|
+
homepage: https://github.com/ahacop/sprites-ruby
|
|
45
|
+
licenses:
|
|
46
|
+
- MIT
|
|
47
|
+
metadata:
|
|
48
|
+
homepage_uri: https://github.com/ahacop/sprites-ruby
|
|
49
|
+
source_code_uri: https://github.com/ahacop/sprites-ruby
|
|
50
|
+
changelog_uri: https://github.com/ahacop/sprites-ruby/blob/main/CHANGELOG.md
|
|
51
|
+
rdoc_options: []
|
|
52
|
+
require_paths:
|
|
53
|
+
- lib
|
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: 3.2.0
|
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '0'
|
|
64
|
+
requirements: []
|
|
65
|
+
rubygems_version: 4.0.3
|
|
66
|
+
specification_version: 4
|
|
67
|
+
summary: Ruby client for the Sprites API
|
|
68
|
+
test_files: []
|