yandex_image_moderation 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef3579e7512a9cd9cfa60837f38badb5ec7e380d
4
- data.tar.gz: b23f32d78f39be6df41ef40d363e0f26b5269e11
3
+ metadata.gz: 977b9fffdd34e001a55781b81075420928d2034e
4
+ data.tar.gz: f547314d0ab0edbbc45af907b7740dfbfd0264b9
5
5
  SHA512:
6
- metadata.gz: 20ea97770c8d5796cf943c6e668e23d48a9b5ee2be9d62e3592d38d7a44baeaed225658a96e57d4f36c3295bb2ca7ba5f7397709cd73cb260a68b284f2488157
7
- data.tar.gz: c0527d5796968f9f9d56877f87648984d68eecac14a3dfe8afc9d17bb226671bba6d1bb8f46fbd724bc8c6dbcf045490687723d1dcf108c834eee36f0d232748
6
+ metadata.gz: 93aa3c8c35059c7cfc409945f98f0f3e1a0113fbd1e44781a0805610f22aee166bdd55e8d78c306c8038895644d12f24726f32bf94cf9a9a71f83d4a27dde2a0
7
+ data.tar.gz: cd2e679417341e90acba517692986c09d63029afef98927549bef3f7c302dd2a795258ac7c18017c37bf6bc9813ffdefb1d2b91d17c83eb0ff267e675eafa11f
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'multipart-post'
3
+ gem 'httpclient'
4
4
 
5
5
  gemspec
@@ -0,0 +1,20 @@
1
+ require 'httpclient'
2
+
3
+ # YandexImageModeration module part for HTTP Client
4
+ module YandexImageModeration
5
+ # @!visibility private
6
+ # A basic HTTP Client that handles requests to Yandex.
7
+ #
8
+ class Client
9
+ def initialize(config)
10
+ raise(::YandexImageModeration::Error::InvalidConfig, 'missing url') if config.url.to_s.empty?
11
+ @http = ::HTTPClient.new base_url: config.url
12
+ @http.connect_timeout = config.open_timeout || config.connect_timeout || 60
13
+ @http.receive_timeout = config.read_timeout || config.receive_timeout || 60
14
+ end
15
+
16
+ def post(url, params)
17
+ @http.post(url, params)
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module YandexImageModeration
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
  require 'yandex_image_moderation/version'
3
3
  require 'yandex_image_moderation/config'
4
- require 'yandex_image_moderation/http_client'
4
+ require 'yandex_image_moderation/client'
5
5
  require 'yandex_image_moderation/result'
6
6
 
7
7
  # YandexImageModeration gem code
@@ -11,7 +11,7 @@ module YandexImageModeration
11
11
  #
12
12
  # @return [#post] an instance of a request handler
13
13
  def client
14
- @client ||= ::YandexImageModeration::NetHTTPClient.new(config)
14
+ @client ||= ::YandexImageModeration::Client.new(config)
15
15
  end
16
16
 
17
17
  # Send a request for moderation
@@ -21,21 +21,21 @@ module YandexImageModeration
21
21
  return if file.nil? || !File.exist?(file)
22
22
 
23
23
  url = "#{config.url}?models=moderation,gender,pornography,ad"
24
- parse_response client.post(url, prepare_body(file), {})
24
+ parse_response client.post(url, prepare_body(file))
25
25
  end
26
26
 
27
27
  protected
28
28
 
29
29
  def parse_response(response)
30
- return unless response.code.to_i == 200
31
- raise(::YandexImageModeration::Error::InvalidResult, 'empty response') if response.body.nil?
32
- ::YandexImageModeration::Result.new JSON.parse(response.body)
30
+ return unless response.status == 200
31
+ raise(::YandexImageModeration::Error::InvalidResult, 'empty response') if response.content.nil?
32
+ ::YandexImageModeration::Result.new JSON.parse(response.content)
33
33
  end
34
34
 
35
35
  def prepare_body(file)
36
36
  {
37
- 'file' => UploadIO.new(file, 'image/jpeg', File.basename(file)),
38
- 'token' => @options.config.token
37
+ file: File.open(file, 'r'),
38
+ token: @options.config.token
39
39
  }
40
40
  end
41
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yandex_image_moderation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Tsvetkov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-14 00:00:00.000000000 Z
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -81,9 +81,9 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - lib/yandex_image_moderation.rb
84
+ - lib/yandex_image_moderation/client.rb
84
85
  - lib/yandex_image_moderation/config.rb
85
86
  - lib/yandex_image_moderation/error.rb
86
- - lib/yandex_image_moderation/http_client.rb
87
87
  - lib/yandex_image_moderation/result.rb
88
88
  - lib/yandex_image_moderation/version.rb
89
89
  - yandex_image_moderation.gemspec
@@ -110,5 +110,5 @@ rubyforge_project:
110
110
  rubygems_version: 2.4.5
111
111
  signing_key:
112
112
  specification_version: 4
113
- summary: yandex_image_moderation-0.1.1
113
+ summary: yandex_image_moderation-0.2.0
114
114
  test_files: []
@@ -1,32 +0,0 @@
1
- require 'uri'
2
- require 'net/http'
3
- require 'net/http/post/multipart'
4
-
5
- # YandexImageModeration module part for HTTP Client
6
- module YandexImageModeration
7
- # @!visibility private
8
- # A basic HTTP Client that handles requests to Yandex.
9
- #
10
- class NetHTTPClient
11
- def initialize(config)
12
- uri = parse_url config
13
- @http = Net::HTTP.new(uri.host, uri.port)
14
- @http.open_timeout = config.open_timeout || 10
15
- @http.read_timeout = config.read_timeout || 30
16
- @http.use_ssl = !(config.url =~ /^https/i).nil?
17
- end
18
-
19
- def post(url, body, headers)
20
- request = Net::HTTP::Post::Multipart.new(url, body)
21
- headers.each { |k, v| request[k.to_s] = v } unless headers.nil? || !headers.is_a?(Hash)
22
- @http.request(request)
23
- end
24
-
25
- protected
26
-
27
- def parse_url(config)
28
- raise(::YandexImageModeration::Error::InvalidConfig, 'missing url') if config.url.to_s.empty?
29
- URI.parse(config.url)
30
- end
31
- end
32
- end