tinplate 2.0.0 → 2.1.1
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 +5 -5
- data/Gemfile +2 -2
- data/README.md +6 -3
- data/lib/tinplate/configuration.rb +1 -7
- data/lib/tinplate/tineye.rb +9 -9
- data/lib/tinplate/version.rb +1 -1
- data/lib/tinplate.rb +0 -1
- data/tinplate.gemspec +3 -3
- metadata +23 -19
- data/lib/tinplate/request_authenticator.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 01e93f8f4d2f05ea8d7ae8cdfa3e002a49d6cf84c2bdb91dfcaa1a8daaa64bc4
|
4
|
+
data.tar.gz: 84ef0144e226efb3bf0ec58ce3727651e6a165de6a0b29dc69e508c830e3bd24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6c9ebfcedf2ad635f866db6425e8501eb07a9f2ece2051b8ebe31d5752f31def2ac0c91343d4c89a225e93c6cc76a610946fec88758fda17ce1704f20e78d9c
|
7
|
+
data.tar.gz: abfddee5e25022fb25129e24a288a236b9c77aeeb09a978f1d7d02a4faa4abe1d7f6524f4794aa6d2521f151c35819710ae0248f7195aad86cdf712d134f3a2e
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -12,11 +12,15 @@ gem 'tinplate'
|
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
15
|
-
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
16
18
|
|
17
19
|
Or install it yourself as:
|
18
20
|
|
19
|
-
|
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
|
data/lib/tinplate/tineye.rb
CHANGED
@@ -26,8 +26,8 @@ module Tinplate
|
|
26
26
|
|
27
27
|
bundles = results["bundles"].map do |bundle|
|
28
28
|
OpenStruct.new(remaining_searches: bundle["remaining_searches"],
|
29
|
-
start_date:
|
30
|
-
expire_date:
|
29
|
+
start_date: Time.parse(bundle["start_date"]),
|
30
|
+
expire_date: Time.parse(bundle["expire_date"]))
|
31
31
|
end
|
32
32
|
|
33
33
|
OpenStruct.new(total_remaining_searches: results["total_remaining_searches"], bundles: bundles)
|
@@ -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
|
-
|
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
|
67
|
-
faraday.request
|
68
|
-
faraday.adapter
|
66
|
+
faraday.request :multipart
|
67
|
+
faraday.request :url_encoded
|
68
|
+
faraday.adapter Faraday.default_adapter
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
data/lib/tinplate/version.rb
CHANGED
data/lib/tinplate.rb
CHANGED
data/tinplate.gemspec
CHANGED
@@ -19,10 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "faraday", "
|
22
|
+
spec.add_dependency "faraday", [">= 0.9.2", "< 2.0.0"]
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "
|
25
|
-
spec.add_development_dependency "rake", "
|
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,57 +1,63 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tinplate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.1
|
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:
|
11
|
+
date: 2021-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.9.2
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 0.9.2
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- - "
|
37
|
+
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
39
|
+
version: 2.2.10
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
|
-
- - "
|
44
|
+
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: 2.2.10
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: rake
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- - "
|
51
|
+
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
53
|
+
version: 12.3.3
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- - "
|
58
|
+
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
60
|
+
version: 12.3.3
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rspec
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +86,7 @@ dependencies:
|
|
80
86
|
- - ">="
|
81
87
|
- !ruby/object:Gem::Version
|
82
88
|
version: '0'
|
83
|
-
description:
|
89
|
+
description:
|
84
90
|
email:
|
85
91
|
- aaron@unsplash.com
|
86
92
|
executables: []
|
@@ -99,7 +105,6 @@ files:
|
|
99
105
|
- lib/tinplate.rb
|
100
106
|
- lib/tinplate/configuration.rb
|
101
107
|
- lib/tinplate/errors.rb
|
102
|
-
- lib/tinplate/request_authenticator.rb
|
103
108
|
- lib/tinplate/search_results.rb
|
104
109
|
- lib/tinplate/tineye.rb
|
105
110
|
- lib/tinplate/version.rb
|
@@ -108,7 +113,7 @@ homepage: https://github.com/unsplash/tinplate
|
|
108
113
|
licenses:
|
109
114
|
- MIT
|
110
115
|
metadata: {}
|
111
|
-
post_install_message:
|
116
|
+
post_install_message:
|
112
117
|
rdoc_options: []
|
113
118
|
require_paths:
|
114
119
|
- lib
|
@@ -123,9 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
128
|
- !ruby/object:Gem::Version
|
124
129
|
version: '0'
|
125
130
|
requirements: []
|
126
|
-
|
127
|
-
|
128
|
-
signing_key:
|
131
|
+
rubygems_version: 3.1.4
|
132
|
+
signing_key:
|
129
133
|
specification_version: 4
|
130
134
|
summary: A wrapper around the TinEye API.
|
131
135
|
test_files: []
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# https://services.tineye.com/developers/tineyeapi/authentication.html
|
2
|
-
|
3
|
-
require "securerandom"
|
4
|
-
require "uri"
|
5
|
-
|
6
|
-
module Tinplate
|
7
|
-
class RequestAuthenticator
|
8
|
-
|
9
|
-
def initialize(action, params = {}, image_name = "")
|
10
|
-
@action = action
|
11
|
-
@params = params
|
12
|
-
@image_name = image_name || ""
|
13
|
-
@nonce = SecureRandom.hex
|
14
|
-
@date = Time.now.to_i
|
15
|
-
end
|
16
|
-
|
17
|
-
def params
|
18
|
-
{
|
19
|
-
api_key: Tinplate.configuration.public_key,
|
20
|
-
api_sig: signature,
|
21
|
-
nonce: @nonce,
|
22
|
-
date: @date
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
def verb
|
27
|
-
@image_name.empty? ? "GET" : "POST"
|
28
|
-
end
|
29
|
-
|
30
|
-
def content_type
|
31
|
-
verb == "GET" ? "" : "multipart/form-data; boundary=-----------RubyMultipartPost"
|
32
|
-
end
|
33
|
-
|
34
|
-
def signature_components
|
35
|
-
[
|
36
|
-
Tinplate.configuration.private_key,
|
37
|
-
verb,
|
38
|
-
content_type,
|
39
|
-
URI.encode_www_form_component(@image_name).downcase,
|
40
|
-
@date.to_i,
|
41
|
-
@nonce,
|
42
|
-
"https://api.tineye.com/rest/#{@action}/",
|
43
|
-
hash_to_sorted_query_string(@params),
|
44
|
-
]
|
45
|
-
end
|
46
|
-
|
47
|
-
def signature
|
48
|
-
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"),
|
49
|
-
Tinplate.configuration.private_key,
|
50
|
-
signature_components.join)
|
51
|
-
end
|
52
|
-
|
53
|
-
def hash_to_sorted_query_string(params)
|
54
|
-
Hash[params.sort].map do |key, value|
|
55
|
-
"#{key}=#{URI.encode_www_form_component(value)}"
|
56
|
-
end.join("&")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|