tinplate 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 4e646b162936b034d5e402b3c47957942019644a844c40ce643ce8606355b366
4
- data.tar.gz: fb30461669218584c80330b21b1de6f0abb88686d687c2fef151a3bcbe573e66
2
+ SHA1:
3
+ metadata.gz: cd4d09eedc78227f59705e1178ce27d024270fe2
4
+ data.tar.gz: ac0c1b55d669aad4ca94b24cfec7802aae73ed33
5
5
  SHA512:
6
- metadata.gz: 20a758012a6f63ad26b536f5f8fe3b9efd96bf43febc8f9ee11dec11c2f66245ec6280e6989549fca37521a8ac69087cebb4b10dad6198018d27e6f9143a93ac
7
- data.tar.gz: da05c621d15de702343f62173df7f96e874b0ca3dfc0fa951403ec30648cf0d8d3f976335aa8b4f39a90ba63c95fa561f799f4a764b0e8c11d2af4a0bfdc67b4
6
+ metadata.gz: 87de49e77f7b78d21a613390a47443e1b6b44602b64f0faf2fb6dd8dacb184e91b0dc5319f9e47eb4c2dd0f4ce1c76ddf13f08a3927a82652a2684830abf5184
7
+ data.tar.gz: e1496130dcde0c1484a2adba0f989fe6a6cf087be4c915aaa59ca81d474d7ca3c07bb67c938a9a3773f86b87ee32d5b55056735b5c6a17e927288359ebf82d37
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
- source 'https://rubygems.org'
2
- ruby '2.1.6'
1
+ source "https://rubygems.org"
2
+ ruby "2.7.2"
3
3
 
4
4
  # Specify your gem's dependencies in tinplate.gemspec
5
5
  gemspec
data/README.md CHANGED
@@ -12,11 +12,15 @@ gem 'tinplate'
12
12
 
13
13
  And then execute:
14
14
 
15
- $ bundle
15
+ ```bash
16
+ $ bundle
17
+ ```
16
18
 
17
19
  Or install it yourself as:
18
20
 
19
- $ gem install tinplate
21
+ ```bash
22
+ $ gem install tinplate
23
+ ```
20
24
 
21
25
  ## Configuration
22
26
 
@@ -24,7 +28,6 @@ First you've got to let Tinplate know what your TinEye API keys are. In a Rails
24
28
 
25
29
  ```ruby
26
30
  Tinplate.configure do |config|
27
- config.public_key = "YOUR PUBLIC API KEY"
28
31
  config.private_key = "YOUR PRIVATE API KEY"
29
32
  config.test = false
30
33
  end
@@ -2,10 +2,8 @@ module Tinplate # :nodoc:
2
2
  class Configuration # :nodoc:
3
3
 
4
4
  # https://services.tineye.com/developers/tineyeapi/sandbox.html
5
- SANDBOX_PUBLIC_KEY = "LCkn,2K7osVwkX95K4Oy"
6
5
  SANDBOX_PRIVATE_KEY = "6mm60lsCNIB,FwOWjJqA80QZHh9BMwc-ber4u=t^"
7
6
 
8
- attr_writer :public_key
9
7
  attr_writer :private_key
10
8
  attr_writer :test
11
9
 
@@ -17,13 +15,9 @@ module Tinplate # :nodoc:
17
15
  !!@test
18
16
  end
19
17
 
20
- def public_key
21
- test? ? SANDBOX_PUBLIC_KEY : @public_key
22
- end
23
-
24
18
  def private_key
25
19
  test? ? SANDBOX_PRIVATE_KEY : @private_key
26
20
  end
27
21
 
28
22
  end
29
- end
23
+ end
@@ -47,12 +47,12 @@ module Tinplate
47
47
  Faraday::UploadIO.new(params.delete(:image_path), "image/jpeg")
48
48
  end
49
49
 
50
- auth = Tinplate::RequestAuthenticator.new(action, params, upload && upload.original_filename)
51
- params.merge!(auth.params)
52
-
53
50
  params.merge!(image_upload: upload) if upload
54
51
 
55
- response = ::JSON.parse(connection.send(http_verb, "#{action}/", params).body)
52
+ headers = { "x-api-key" => Tinplate.configuration.private_key }
53
+
54
+ response = connection.send(http_verb, "#{action}/", params, headers)
55
+ response = ::JSON.parse(response.body)
56
56
 
57
57
  if response["code"] != 200
58
58
  raise Tinplate::Error.from_response(response["code"], response["messages"][0], response["messages"][1])
@@ -63,9 +63,9 @@ module Tinplate
63
63
 
64
64
  def connection
65
65
  @conn ||= Faraday.new(url: "https://api.tineye.com/rest/") do |faraday|
66
- faraday.request :multipart
67
- faraday.request :url_encoded
68
- faraday.adapter Faraday.default_adapter
66
+ faraday.request :multipart
67
+ faraday.request :url_encoded
68
+ faraday.adapter Faraday.default_adapter
69
69
  end
70
70
  end
71
71
 
@@ -1,3 +1,3 @@
1
1
  module Tinplate
2
- VERSION = "2.0.2"
2
+ VERSION = "2.1.0"
3
3
  end
data/tinplate.gemspec CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "faraday", [">= 0.9.2", "< 2.0.0"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.10"
25
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "bundler", ">= 2.2.10"
25
+ spec.add_development_dependency "rake", ">= 12.3.3"
26
26
  spec.add_development_dependency "rspec", "~> 3.4.0"
27
27
  spec.add_development_dependency "pry"
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Klaassen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-08 00:00:00.000000000 Z
11
+ date: 2021-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -34,30 +34,30 @@ dependencies:
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '1.10'
39
+ version: 2.2.10
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - "~>"
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '1.10'
46
+ version: 2.2.10
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '10.0'
53
+ version: 12.3.3
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - "~>"
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: '10.0'
60
+ version: 12.3.3
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -86,7 +86,7 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
- description:
89
+ description:
90
90
  email:
91
91
  - aaron@unsplash.com
92
92
  executables: []
@@ -105,7 +105,6 @@ files:
105
105
  - lib/tinplate.rb
106
106
  - lib/tinplate/configuration.rb
107
107
  - lib/tinplate/errors.rb
108
- - lib/tinplate/request_authenticator.rb
109
108
  - lib/tinplate/search_results.rb
110
109
  - lib/tinplate/tineye.rb
111
110
  - lib/tinplate/version.rb
@@ -114,7 +113,7 @@ homepage: https://github.com/unsplash/tinplate
114
113
  licenses:
115
114
  - MIT
116
115
  metadata: {}
117
- post_install_message:
116
+ post_install_message:
118
117
  rdoc_options: []
119
118
  require_paths:
120
119
  - lib
@@ -129,9 +128,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
128
  - !ruby/object:Gem::Version
130
129
  version: '0'
131
130
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.7.10
134
- signing_key:
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.8
133
+ signing_key:
135
134
  specification_version: 4
136
135
  summary: A wrapper around the TinEye API.
137
136
  test_files: []
@@ -1,60 +0,0 @@
1
- # https://services.tineye.com/developers/tineyeapi/authentication.html
2
-
3
- require "securerandom"
4
- require "uri"
5
- require "openssl"
6
-
7
- module Tinplate
8
- class RequestAuthenticator
9
-
10
- def initialize(action, params = {}, image_name = "")
11
- @action = action
12
- @params = params
13
- @image_name = image_name || ""
14
- @nonce = SecureRandom.hex
15
- @date = Time.now.to_i
16
- end
17
-
18
- def params
19
- {
20
- api_key: Tinplate.configuration.public_key,
21
- api_sig: signature,
22
- nonce: @nonce,
23
- date: @date
24
- }
25
- end
26
-
27
- def verb
28
- @image_name.empty? ? "GET" : "POST"
29
- end
30
-
31
- def content_type
32
- verb == "GET" ? "" : "multipart/form-data; boundary=-----------RubyMultipartPost"
33
- end
34
-
35
- def signature_components
36
- [
37
- Tinplate.configuration.private_key,
38
- verb,
39
- content_type,
40
- URI.encode_www_form_component(@image_name).downcase,
41
- @date.to_i,
42
- @nonce,
43
- "https://api.tineye.com/rest/#{@action}/",
44
- hash_to_sorted_query_string(@params),
45
- ]
46
- end
47
-
48
- def signature
49
- OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"),
50
- Tinplate.configuration.private_key,
51
- signature_components.join)
52
- end
53
-
54
- def hash_to_sorted_query_string(params)
55
- Hash[params.sort].map do |key, value|
56
- "#{key}=#{URI.encode_www_form_component(value)}"
57
- end.join("&")
58
- end
59
- end
60
- end