sightengine-rb 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f3292075bd36340a245fe9b2f560c403b10763231e4e780b3b5ffc6642f83320
4
+ data.tar.gz: e1149781d1782cbb1cd3cf7dd45e3dec89c633947c1301c8ad29974d7d57253d
5
+ SHA512:
6
+ metadata.gz: 58207c39ad23e78d215059437c9447dd0f8f135e935891d2205a8e1b57d9b9d4566ac68e74c5b2263cf773bc03bdeb4b2cf796b7302296125499a02c597ccf78
7
+ data.tar.gz: f330afdc8e11989bbb91ff4360770c75578de37d98c300cf5f380724d7beb1f24076c72ed055561965f697cd35c256f472858cf47e302d813ee0ff56b4affea0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Sergey Pustovalov
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,56 @@
1
+ # SightengineRb
2
+
3
+ This gem provides a convenient way to interact with the [Sightengine API](https://sightengine.com/) for content moderation.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sightengine-rb'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sightengine-rb
20
+
21
+ ## Usage
22
+
23
+ First, configure the client with your API user and secret. You can do this in an initializer file (e.g., `config/initializers/sightengine.rb`):
24
+
25
+ ```ruby
26
+ SightengineRb.configure do |config|
27
+ config.api_user = 'YOUR_API_USER'
28
+ config.api_secret = 'YOUR_API_SECRET'
29
+ end
30
+ ```
31
+
32
+ Then, you can create a client instance:
33
+
34
+ ```ruby
35
+ client = SightengineRb::Client.new
36
+ ```
37
+
38
+ And make requests to the API. For example, to check an image for nudity:
39
+
40
+ ```ruby
41
+ # Check a remote image
42
+ response = client.check('nudity', image_url: 'https://example.com/image.jpg')
43
+
44
+ # Check a local image
45
+ response = client.check('nudity', file: 'path/to/image.jpg')
46
+ ```
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pustserg/sightengine_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/pustserg/sightengine_ruby/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+
5
+ module SightengineRb
6
+ class Client
7
+ class BaseRequest
8
+ include HTTParty
9
+ base_uri "https://api.sightengine.com/1.0"
10
+
11
+ def initialize(api_user, api_secret)
12
+ @api_user = api_user
13
+ @api_secret = api_secret
14
+ end
15
+
16
+ def post(path, params = {})
17
+ if params[:file]
18
+ params[:media] = params.delete(:file)
19
+ self.class.post(path, body: params.merge(api_user: @api_user, api_secret: @api_secret))
20
+ else
21
+ self.class.post(path, query: params.merge(api_user: @api_user, api_secret: @api_secret))
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SightengineRb
4
+ class Client
5
+ class CheckRequest < BaseRequest
6
+ def post(models, image_url: nil, file: nil)
7
+ params = { models: models }
8
+ params[:url] = image_url if image_url
9
+ params[:file] = File.open(file) if file
10
+
11
+ super("/check.json", params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SightengineRb
4
+ class Client
5
+ class SetCelebrityRequest < BaseRequest
6
+ def post(celebrity_id, image_url: nil, file: nil)
7
+ params = { id: celebrity_id }
8
+ params[:url] = image_url if image_url
9
+ params[:file] = File.open(file) if file
10
+
11
+ super("/celebrities.json", params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "client/base_request"
4
+ require_relative "client/check_request"
5
+ require_relative "client/set_celebrity_request"
6
+
7
+ module SightengineRb
8
+ class Client
9
+ attr_reader :api_user, :api_secret
10
+
11
+ def initialize
12
+ @api_user = SightengineRb.config.api_user
13
+ @api_secret = SightengineRb.config.api_secret
14
+ end
15
+
16
+ def check(models, image_url: nil, file: nil)
17
+ CheckRequest.new(api_user, api_secret).post(models, image_url: image_url, file: file)
18
+ end
19
+
20
+ def set_celebrity(celebrity_id, image_url: nil, file: nil)
21
+ SetCelebrityRequest.new(api_user, api_secret).post(celebrity_id, image_url: image_url, file: file)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "anyway_config"
4
+
5
+ module SightengineRb
6
+ class Config < Anyway::Config
7
+ config_name :sightengine
8
+ attr_config :api_user, :api_secret
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SightengineRb
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sightengine-rb/version"
4
+ require_relative "sightengine-rb/client"
5
+ require_relative "sightengine-rb/config"
6
+
7
+ module SightengineRb
8
+ class << self
9
+ def config
10
+ @config ||= Config.new
11
+ end
12
+
13
+ def configure
14
+ yield config
15
+ end
16
+ end
17
+
18
+ class Error < StandardError; end
19
+ end
@@ -0,0 +1,4 @@
1
+ module SightengineRuby
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sightengine-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Pustovalov
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: httparty
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.21'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.21'
26
+ - !ruby/object:Gem::Dependency
27
+ name: anyway_config
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.4'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.4'
40
+ - !ruby/object:Gem::Dependency
41
+ name: webmock
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.18'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.18'
54
+ description: This gem provides a convenient way to interact with the Sightengine API
55
+ for content moderation.
56
+ email:
57
+ - sergey@pustovalov.me
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - README.md
64
+ - Rakefile
65
+ - lib/sightengine-rb.rb
66
+ - lib/sightengine-rb/client.rb
67
+ - lib/sightengine-rb/client/base_request.rb
68
+ - lib/sightengine-rb/client/check_request.rb
69
+ - lib/sightengine-rb/client/set_celebrity_request.rb
70
+ - lib/sightengine-rb/config.rb
71
+ - lib/sightengine-rb/version.rb
72
+ - sig/sightengine_ruby.rbs
73
+ homepage: https://github.com/pustserg/sightengine_ruby
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ allowed_push_host: https://rubygems.org
78
+ homepage_uri: https://github.com/pustserg/sightengine_ruby
79
+ source_code_uri: https://github.com/pustserg/sightengine_ruby
80
+ changelog_uri: https://github.com/pustserg/sightengine_ruby/blob/master/CHANGELOG.md
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 3.1.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.6.9
96
+ specification_version: 4
97
+ summary: A Ruby wrapper for the Sightengine API.
98
+ test_files: []