tinplate 1.1.0 → 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
2
  SHA1:
3
- metadata.gz: ba23118a45b0d10c153fc40b6b3e65c600a4854e
4
- data.tar.gz: 5be87df8bd610dc667f30d81bbe2248ec881aec9
3
+ metadata.gz: cd4d09eedc78227f59705e1178ce27d024270fe2
4
+ data.tar.gz: ac0c1b55d669aad4ca94b24cfec7802aae73ed33
5
5
  SHA512:
6
- metadata.gz: e4e3cf73996b52331ff949cd81527dc6b337c4d0ab2a2efc5848201ad681adf34803680ef12b822fcb48e23a8bc5589ebfda4137e5406bae45fb9819b34fb31f
7
- data.tar.gz: 0cec435914711cb5fba98aa01fd42682e794700faaa425970e0d104a0eb5ae531e7631199bf26563847e20e1f5d470519daed3f6f617dc6c3290d6cfa93db789
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
@@ -49,9 +52,9 @@ There are only three API actions available: `search`, `remaining_searches` (to c
49
52
  tineye = Tinplate::TinEye.new
50
53
  results = tineye.search(image_url: "http://example.com/photo.jpg")
51
54
 
52
- results.total_results # => 2
53
- results.total_backlinks # => 3
54
- results.matches # => an Array of matched images (see below)
55
+ results.stats.total_results # => 2
56
+ results.stats.total_backlinks # => 3
57
+ results.matches # => an Array of matched images (see below)
55
58
 
56
59
  results.matches.each do |match|
57
60
  # Do what you like with this matched image. The world is your oyster.
@@ -77,9 +80,14 @@ results = tineye.search(image_path: "/home/alice/example.jpg")
77
80
  An `OpenStruct` object with the following attributes (/w example values):
78
81
 
79
82
  ```ruby
83
+ domain: "ucsb.edu",
84
+ top_level_domain: "ucsb.edu",
80
85
  width: 400
81
86
  height: 300
82
- size: 50734
87
+ size: 50734,
88
+ filesize: 195840,
89
+ score: 88.9,
90
+ tags: ["collection"],
83
91
  image_url: "http://images.tineye.com/result/0f1e84b7b7538e8e7de048f4d45eb8f579e3e999941b3341ed9a754eb447ebb1",
84
92
  format: "JPEG",
85
93
  contributor: true,
@@ -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
@@ -1,9 +1,8 @@
1
1
  module Tinplate
2
2
  class SearchResults < OpenStruct
3
3
  def initialize(data)
4
- super total_backlinks: data["total_backlinks"],
5
- total_results: data["total_results"],
6
- matches: parsed_matches(data["matches"])
4
+ super stats: OpenStruct.new(data["stats"]),
5
+ matches: parsed_matches(data["results"]["matches"])
7
6
  end
8
7
 
9
8
  private
@@ -18,14 +18,19 @@ module Tinplate
18
18
 
19
19
  response = request("search", options.merge(img))
20
20
 
21
- Tinplate::SearchResults.new(response["results"])
21
+ Tinplate::SearchResults.new(response)
22
22
  end
23
23
 
24
24
  def remaining_searches
25
25
  results = request("remaining_searches")["results"]
26
- OpenStruct.new(remaining_searches: results["remaining_searches"],
27
- start_date: DateTime.parse(results["start_date"]),
28
- expire_date: DateTime.parse(results["expire_date"]))
26
+
27
+ bundles = results["bundles"].map do |bundle|
28
+ OpenStruct.new(remaining_searches: bundle["remaining_searches"],
29
+ start_date: Time.parse(bundle["start_date"]),
30
+ expire_date: Time.parse(bundle["expire_date"]))
31
+ end
32
+
33
+ OpenStruct.new(total_remaining_searches: results["total_remaining_searches"], bundles: bundles)
29
34
  end
30
35
 
31
36
  def image_count
@@ -42,12 +47,12 @@ module Tinplate
42
47
  Faraday::UploadIO.new(params.delete(:image_path), "image/jpeg")
43
48
  end
44
49
 
45
- auth = Tinplate::RequestAuthenticator.new(action, params, upload && upload.original_filename)
46
- params.merge!(auth.params)
47
-
48
50
  params.merge!(image_upload: upload) if upload
49
51
 
50
- 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)
51
56
 
52
57
  if response["code"] != 200
53
58
  raise Tinplate::Error.from_response(response["code"], response["messages"][0], response["messages"][1])
@@ -58,9 +63,9 @@ module Tinplate
58
63
 
59
64
  def connection
60
65
  @conn ||= Faraday.new(url: "https://api.tineye.com/rest/") do |faraday|
61
- faraday.request :multipart
62
- faraday.request :url_encoded
63
- faraday.adapter Faraday.default_adapter
66
+ faraday.request :multipart
67
+ faraday.request :url_encoded
68
+ faraday.adapter Faraday.default_adapter
64
69
  end
65
70
  end
66
71
 
@@ -1,3 +1,3 @@
1
1
  module Tinplate
2
- VERSION = "1.1.0"
2
+ VERSION = "2.1.0"
3
3
  end
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", "~> 0.9.2"
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,57 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Klaassen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-03 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
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: '1.10'
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: '1.10'
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: '10.0'
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: '10.0'
60
+ version: 12.3.3
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rspec
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -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("sha1"),
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