tinplate 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +10 -3
- data/lib/tinplate/request_authenticator.rb +13 -5
- data/lib/tinplate/tineye.rb +26 -9
- data/lib/tinplate/version.rb +1 -1
- data/tinplate.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba23118a45b0d10c153fc40b6b3e65c600a4854e
|
4
|
+
data.tar.gz: 5be87df8bd610dc667f30d81bbe2248ec881aec9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4e3cf73996b52331ff949cd81527dc6b337c4d0ab2a2efc5848201ad681adf34803680ef12b822fcb48e23a8bc5589ebfda4137e5406bae45fb9819b34fb31f
|
7
|
+
data.tar.gz: 0cec435914711cb5fba98aa01fd42682e794700faaa425970e0d104a0eb5ae531e7631199bf26563847e20e1f5d470519daed3f6f617dc6c3290d6cfa93db789
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -41,9 +41,9 @@ There are only three API actions available: `search`, `remaining_searches` (to c
|
|
41
41
|
|
42
42
|
`image_count` returns a plain old integer.
|
43
43
|
|
44
|
-
### Search
|
44
|
+
### Search examples
|
45
45
|
|
46
|
-
|
46
|
+
#### Search by URL
|
47
47
|
|
48
48
|
```ruby
|
49
49
|
tineye = Tinplate::TinEye.new
|
@@ -58,6 +58,13 @@ results.matches.each do |match|
|
|
58
58
|
end
|
59
59
|
```
|
60
60
|
|
61
|
+
#### Search by upload
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
tineye = Tinplate::TinEye.new
|
65
|
+
results = tineye.search(image_path: "/home/alice/example.jpg")
|
66
|
+
```
|
67
|
+
|
61
68
|
#### Optional search parameters
|
62
69
|
|
63
70
|
`offset`: Default 0
|
@@ -78,7 +85,7 @@ format: "JPEG",
|
|
78
85
|
contributor: true,
|
79
86
|
overlay: "overlay/507bb6bf9a397284e2330be7c0671aadc7319b4b/0f1e84b7b7538e8e7de048f4d45eb8f579e3e999941b3341ed9a754eb447ebb1?m21=-9.06952e-05&m22=0.999975&m23=0.0295591&m11=0.999975&m13=-0.0171177&m12=9.06952e-05",
|
80
87
|
backlinks:
|
81
|
-
# These are also
|
88
|
+
# These are also OpenStruct objects, not Hashes.
|
82
89
|
[
|
83
90
|
{
|
84
91
|
url: "http://example-copier.com/photo.jpg",
|
@@ -9,7 +9,7 @@ module Tinplate
|
|
9
9
|
def initialize(action, params = {}, image_name = "")
|
10
10
|
@action = action
|
11
11
|
@params = params
|
12
|
-
@image_name = image_name
|
12
|
+
@image_name = image_name || ""
|
13
13
|
@nonce = SecureRandom.hex
|
14
14
|
@date = Time.now.to_i
|
15
15
|
end
|
@@ -23,15 +23,23 @@ module Tinplate
|
|
23
23
|
}
|
24
24
|
end
|
25
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
|
+
|
26
34
|
def signature_components
|
27
35
|
[
|
28
36
|
Tinplate.configuration.private_key,
|
29
|
-
|
30
|
-
|
31
|
-
URI.
|
37
|
+
verb,
|
38
|
+
content_type,
|
39
|
+
URI.encode_www_form_component(@image_name).downcase,
|
32
40
|
@date.to_i,
|
33
41
|
@nonce,
|
34
|
-
"
|
42
|
+
"https://api.tineye.com/rest/#{@action}/",
|
35
43
|
hash_to_sorted_query_string(@params),
|
36
44
|
]
|
37
45
|
end
|
data/lib/tinplate/tineye.rb
CHANGED
@@ -3,12 +3,21 @@ module Tinplate
|
|
3
3
|
SORTS = ["score", "size", "crawl_date"]
|
4
4
|
ORDERS = ["asc", "desc"]
|
5
5
|
|
6
|
-
def search(image_url: nil, offset: 0, limit: 100, sort: "score", order: "desc")
|
7
|
-
raise ArgumentError.new("You must supply an image_url") if !image_url
|
6
|
+
def search(image_path: nil, image_url: nil, offset: 0, limit: 100, sort: "score", order: "desc")
|
7
|
+
raise ArgumentError.new("You must supply an image or image_url") if !image_url && !image_path
|
8
8
|
raise ArgumentError.new("sort must be one of #{SORTS.join(', ')}") if !SORTS.include?(sort)
|
9
9
|
raise ArgumentError.new("order must be one of #{ORDERS.join(', ')}") if !ORDERS.include?(order)
|
10
10
|
|
11
|
-
|
11
|
+
options = {
|
12
|
+
offset: offset.to_s,
|
13
|
+
limit: limit.to_s,
|
14
|
+
sort: sort,
|
15
|
+
order: order
|
16
|
+
}
|
17
|
+
img = image_url ? { image_url: image_url } : { image_path: image_path }
|
18
|
+
|
19
|
+
response = request("search", options.merge(img))
|
20
|
+
|
12
21
|
Tinplate::SearchResults.new(response["results"])
|
13
22
|
end
|
14
23
|
|
@@ -23,14 +32,22 @@ module Tinplate
|
|
23
32
|
request("image_count")["results"]
|
24
33
|
end
|
25
34
|
|
26
|
-
|
27
35
|
private
|
28
36
|
|
29
37
|
def request(action, params = {})
|
30
|
-
|
38
|
+
http_verb = :get
|
39
|
+
|
40
|
+
upload = if params[:image_path]
|
41
|
+
http_verb = :post
|
42
|
+
Faraday::UploadIO.new(params.delete(:image_path), "image/jpeg")
|
43
|
+
end
|
44
|
+
|
45
|
+
auth = Tinplate::RequestAuthenticator.new(action, params, upload && upload.original_filename)
|
31
46
|
params.merge!(auth.params)
|
32
47
|
|
33
|
-
|
48
|
+
params.merge!(image_upload: upload) if upload
|
49
|
+
|
50
|
+
response = ::JSON.parse(connection.send(http_verb, "#{action}/", params).body)
|
34
51
|
|
35
52
|
if response["code"] != 200
|
36
53
|
raise Tinplate::Error.from_response(response["code"], response["messages"][0], response["messages"][1])
|
@@ -40,13 +57,13 @@ module Tinplate
|
|
40
57
|
end
|
41
58
|
|
42
59
|
def connection
|
43
|
-
@conn ||= Faraday.new(url: "
|
60
|
+
@conn ||= Faraday.new(url: "https://api.tineye.com/rest/") do |faraday|
|
61
|
+
faraday.request :multipart
|
44
62
|
faraday.request :url_encoded
|
45
|
-
faraday.response :logger
|
46
63
|
faraday.adapter Faraday.default_adapter
|
47
64
|
end
|
48
65
|
end
|
49
66
|
|
50
67
|
end
|
51
68
|
|
52
|
-
end
|
69
|
+
end
|
data/lib/tinplate/version.rb
CHANGED
data/tinplate.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "tinplate"
|
8
8
|
spec.version = Tinplate::VERSION
|
9
9
|
spec.authors = ["Aaron Klaassen"]
|
10
|
-
spec.email = ["aaron@
|
10
|
+
spec.email = ["aaron@unsplash.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{A wrapper around the TinEye API.}
|
13
13
|
spec.homepage = "https://github.com/unsplash/tinplate"
|
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: 1.0
|
4
|
+
version: 1.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:
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
version: '0'
|
83
83
|
description:
|
84
84
|
email:
|
85
|
-
- aaron@
|
85
|
+
- aaron@unsplash.com
|
86
86
|
executables: []
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|