sightengine-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c34cd83e2ec2fcef4c3eef13df2baa77abf9ae1e
4
+ data.tar.gz: 64b471adac0b2e2a108d92b08a9991893527a22b
5
+ SHA512:
6
+ metadata.gz: 5c45eb836fdaef31421ef35df9f74df59083918c4ddd6fa3b96089f325e670f7bdf885dfe2a42087590f880552ad09f4b71df375656cb7135f8742685ba77963
7
+ data.tar.gz: d7297480f0584fbea321d5a6dd1bcafd7f24d5824dc900dc5c23d6d0e7854c69bee0373c3b30ef7d25174d2261f1ed7cb4e6309eb3a8b0ecadcda7189169135e
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
5
+ notifications:
6
+ slack:
7
+ rooms:
8
+ secure: YmvTbKjuBF5i7p3dLF/n1CWuRyyeMwhPUx/lUYsTyiad9pAgHr4pnrxoYUV7WX3nDTEcFJqD0Ekfp8aoBsGU0o/OLb76/WGkh9Gqi0HyNUCCseNz2arbnJfZ68z2UE8S7Z0WNo8oPOkvDEYukPcj9Mi/0SGtNAZMk0/V4Vl1z7TKRTqlVQg0Hm5+Iiaiy09bP2kiaqLgmkRrHUwMllAmH51PshQveN6GpJPILggD4wQW6ecsgGH5RKerG3Vss2AsHrdSl0RdFevS/8/gktcsFU96RUnbwim3FakXsdTmYKV5bPcQXu8yhcalJSE4w5HboJ3vxjj4EMLR2XKBslLuBmDboASWLdRh2igjdfIphtFeCL7K8jh+mwsKDyCtiGF66HvRuuHRlcgGjZazbP/sSDHTbxwKVXOPWd7Uw9QSjuJVoXpnSQjBHAtsEYUn8DwSu/OrPP7Q6mYTkXAFZrG2hHDaUyfAn1Q+n7taUMGtbWyFOEQt72SHYWgWB7PiUQlmJlX5LDJpTKJZmGQvlaLJQ7LU0iKVt+hg24lUi+kyseLHr4aC+6fw168g/EvMLiYZpV+/n/POzY9HAqfD+Ihp2PYgyq6uDUfFKAZEUCn+qvhK5aE5vTQFsrQAszVtlHaA9LtKEYGn+3eFIJOudXJECYfmlX+9w5Q3JyLuby5UFA8=
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sightengine-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ <img src="http://d324imu86q1bqn.cloudfront.net/uploads/user/avatar/641/large_Ello.1000x1000.png" width="200px" height="200px" />
2
+
3
+ # Sightengine API Ruby Wrapper
4
+
5
+ This gem provides a ruby API to the [Sightengine image moderation service](https://sightengine.com/).
6
+
7
+ [![Build Status](https://travis-ci.org/ello/sightengine-ruby.svg?branch=master)](https://travis-ci.org/ello/sightengine-ruby)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'sightengine-ruby', github: 'ello/sightengine-ruby', require: 'sightengine'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+
22
+ ## Usage
23
+
24
+ Before making any calls, you'll need to set your credentials using the `SIGHTENGINE_API_USER` and `SIGHTENGINE_API_SECRET` environment variables.
25
+
26
+ The Sightengine API has one call - `moderate`, which [checks an image for nudity](https://sightengine.readme.io/docs/nudityjson) and returns an evaluation of it.
27
+
28
+ ```ruby
29
+ puts Sightengine.moderate('https://unsplash.it/200/300?random')
30
+ #<struct Sightengine::Response status="success", nudity_result=false, nudity_confidence=66>
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `rake` to run the tests.
36
+
37
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ If you're adding new calls to Sightengine, running tests may require a valid API user ID and secret as described above. Normal test runs are stubbed via VCR, and should not require credentials.
40
+
41
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ello/sightengine-ruby.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
51
+
52
+ ## Code of Conduct
53
+ Ello was created by idealists who believe that the essential nature of all human beings is to be kind, considerate, helpful, intelligent, responsible, and respectful of others. To that end, we will be enforcing [the Ello rules](https://ello.co/wtf/policies/rules/) within all of our open source projects. If you don’t follow the rules, you risk being ignored, banned, or reported for abuse.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sightengine"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module Sightengine
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,67 @@
1
+ require 'sightengine/version'
2
+
3
+ require 'net/http'
4
+ require 'json'
5
+ require 'forwardable'
6
+
7
+ module Sightengine
8
+ extend SingleForwardable
9
+
10
+ class << self
11
+ def client(service_url = 'https://api.sightengine.com/1.0',
12
+ api_user = ENV['SIGHTENGINE_API_USER'],
13
+ api_secret = ENV['SIGHTENGINE_API_SECRET'])
14
+ @client ||= Client.new(service_url, api_user, api_secret)
15
+ end
16
+
17
+ def client=(client)
18
+ @client = client
19
+ end
20
+ end
21
+
22
+ def_delegators :client, :moderate
23
+
24
+ Response = Struct.new(:status, :nudity_result, :nudity_confidence) do
25
+
26
+ def self.from_json(json)
27
+ new(json['status'],
28
+ json.dig('nudity', 'result'),
29
+ json.dig('nudity', 'confidence'))
30
+ end
31
+ end
32
+
33
+ class Client
34
+ def initialize(service_uri, user, secret)
35
+ @service_uri = service_uri
36
+ @user = user
37
+ @secret = secret
38
+ end
39
+
40
+ def moderate(url)
41
+ http_client(path: '/nudity.json', http_verb: 'GET', params: { url: url })
42
+ end
43
+
44
+ private
45
+
46
+ def http_client(path:, http_verb:, body: "", params: {})
47
+ uri = URI(@service_uri + "#{path}")
48
+ uri.query = URI.encode_www_form(params.merge(api_user: @user, api_secret: @secret))
49
+ http = Net::HTTP.new(uri.host, uri.port)
50
+ http.use_ssl = (uri.scheme == 'https')
51
+ request = create_request(http_verb).new(uri)
52
+ request.body = body
53
+ request.add_field 'Accept', 'application/json'
54
+ response = http.request(request)
55
+ Response.from_json(JSON.parse(response.body))
56
+ end
57
+
58
+ def create_request(verb)
59
+ case verb.downcase
60
+ when 'get'
61
+ Net::HTTP::Get
62
+ when 'post'
63
+ Net::HTTP::Post
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sightengine/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sightengine-ruby"
8
+ spec.version = Sightengine::VERSION
9
+ spec.authors = ["Jay Zeschin"]
10
+ spec.email = ["jay@ello.co"]
11
+
12
+ spec.summary = %q{Ruby wrapper for the SightEngine image moderation API}
13
+ spec.homepage = "https://github.com/ello/sightengine-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "dotenv"
26
+ spec.add_development_dependency "vcr"
27
+ spec.add_development_dependency "webmock"
28
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sightengine-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jay Zeschin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - jay@ello.co
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".ruby-version"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/sightengine.rb
129
+ - lib/sightengine/version.rb
130
+ - sightengine-ruby.gemspec
131
+ homepage: https://github.com/ello/sightengine-ruby
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.5.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Ruby wrapper for the SightEngine image moderation API
155
+ test_files: []