pixmatch 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/lib/pixmatch/api.rb +15 -15
- data/lib/pixmatch/client.rb +11 -11
- data/lib/pixmatch/configuration.rb +45 -45
- data/lib/pixmatch/request.rb +20 -20
- data/lib/pixmatch/utils.rb +2 -2
- data/lib/pixmatch/version.rb +1 -1
- data/lib/pixmatch.rb +19 -19
- metadata +28 -66
- data/spec/pixmatch_spec.rb +0 -87
- data/spec/spec_helper.rb +0 -11
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Pixmatch
|
2
2
|
|
3
|
-
Pixmatch REST API client library for
|
3
|
+
Pixmatch REST API client library for Pixmatch[http://ideeinc.com/products/pixmatch/], automated image matching API by Idee[http://ideeinc.com]. Given an image to look for, it locates identical or modified images within or between large scale image collections.
|
4
4
|
|
5
5
|
== Using
|
6
6
|
|
@@ -55,7 +55,7 @@ Pixmatch REST API client library for TinEye[http://www.tineye.com/] reverse-imag
|
|
55
55
|
<<: *settings
|
56
56
|
username: '<your username>'
|
57
57
|
password: '<your password>'
|
58
|
-
endpoint: '
|
58
|
+
endpoint: '<your url>.tineye.com'
|
59
59
|
* Run 'bundle install'
|
60
60
|
* Test with 'rspec spec'
|
61
61
|
* Send pull requests.
|
data/lib/pixmatch/api.rb
CHANGED
@@ -3,19 +3,19 @@ require File.expand_path('../request', __FILE__)
|
|
3
3
|
# Adapted from the Ruby Twitter gem.
|
4
4
|
# @see https://github.com/jnunemaker/twitter
|
5
5
|
module Pixmatch
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
# @private
|
7
|
+
class API
|
8
|
+
# @private
|
9
|
+
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
10
|
+
|
11
|
+
# Creates a new API
|
12
|
+
def initialize(options = {})
|
13
|
+
options = Pixmatch.options.merge(options)
|
14
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
15
|
+
send("#{key}=", options[key])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
include Request
|
20
|
+
end
|
21
21
|
end
|
data/lib/pixmatch/client.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Adapted from the Ruby Twitter gem.
|
2
2
|
# @see https://github.com/jnunemaker/twitter
|
3
3
|
module Pixmatch
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
# Wrapper for the Pixmatch REST API
|
5
|
+
class Client < API
|
6
|
+
Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
|
7
|
+
|
8
|
+
include Pixmatch::Client::Ping
|
9
|
+
include Pixmatch::Client::Count
|
10
|
+
include Pixmatch::Client::Add
|
11
|
+
include Pixmatch::Client::List
|
12
|
+
include Pixmatch::Client::Delete
|
13
|
+
include Pixmatch::Client::Search
|
14
|
+
end
|
15
15
|
end
|
@@ -1,49 +1,49 @@
|
|
1
1
|
# Adapted from the Ruby Twitter gem.
|
2
2
|
# @see https://github.com/jnunemaker/twitter
|
3
3
|
module Pixmatch
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
4
|
+
# Defines constants and methods related to configuration.
|
5
|
+
module Configuration
|
6
|
+
# An array of valid keys in the options hash when configuring a {Flixated::API}.
|
7
|
+
VALID_OPTIONS_KEYS = [
|
8
|
+
:username,
|
9
|
+
:password,
|
10
|
+
:endpoint
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
# By default, don't set a username.
|
14
|
+
DEFAULT_USERNAME = nil.freeze
|
15
|
+
|
16
|
+
# By default, don't set a password.
|
17
|
+
DEFAULT_PASSWORD = nil.freeze
|
18
|
+
|
19
|
+
# The endpoint that will be used to connect if none is set.
|
20
|
+
DEFAULT_ENDPOINT = 'https://api.tineye.com'.freeze
|
21
|
+
|
22
|
+
# @private
|
23
|
+
attr_accessor(*VALID_OPTIONS_KEYS)
|
24
|
+
|
25
|
+
# When this module is extended, set all configuration options to their default values.
|
26
|
+
def self.extended(base)
|
27
|
+
base.reset
|
28
|
+
end
|
29
|
+
|
30
|
+
# Convenience method to allow configuration options to be set in a block.
|
31
|
+
def configure
|
32
|
+
yield self
|
33
|
+
end
|
34
|
+
|
35
|
+
# Create a hash of options and their values.
|
36
|
+
def options
|
37
|
+
VALID_OPTIONS_KEYS.inject({}) do |option,key|
|
38
|
+
option.merge!(key => send(key))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Reset all configuration options to default.
|
43
|
+
def reset
|
44
|
+
self.username = DEFAULT_USERNAME
|
45
|
+
self.password = DEFAULT_PASSWORD
|
46
|
+
self.endpoint = DEFAULT_ENDPOINT
|
47
|
+
end
|
48
|
+
end
|
49
49
|
end
|
data/lib/pixmatch/request.rb
CHANGED
@@ -2,27 +2,27 @@ require 'uri'
|
|
2
2
|
require 'rest_client'
|
3
3
|
|
4
4
|
module Pixmatch
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
5
|
+
module Request
|
6
|
+
private
|
7
|
+
|
8
|
+
def request(http_method, path, query_params = {}, data_params = {})
|
9
|
+
capture RestClient::Request.new({
|
10
|
+
method: http_method,
|
11
|
+
url: "#{endpoint}/#{paramify(path, query_params)}",
|
12
|
+
user: username,
|
13
|
+
password: password
|
14
|
+
}.merge(data_params)).execute
|
15
|
+
end
|
16
|
+
|
17
|
+
def capture(response)
|
18
|
+
json = Utils.parse_json(response)
|
19
|
+
Utils.handle_error(json)
|
20
|
+
json
|
21
|
+
end
|
22
|
+
|
23
|
+
def paramify(path, params)
|
24
24
|
URI.encode("#{path}/?#{params.map { |k,v| "#{k}=#{v}" }.join('&')}")
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
end
|
28
28
|
end
|
data/lib/pixmatch/utils.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'hashie'
|
2
|
-
require '
|
2
|
+
require 'json'
|
3
3
|
|
4
4
|
module Pixmatch
|
5
5
|
# @private
|
@@ -11,7 +11,7 @@ module Pixmatch
|
|
11
11
|
|
12
12
|
# Parses JSON and returns a Hashie::Mash
|
13
13
|
def self.parse_json(json)
|
14
|
-
Hashie::Mash.new(
|
14
|
+
Hashie::Mash.new(JSON.parse(json))
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/pixmatch/version.rb
CHANGED
data/lib/pixmatch.rb
CHANGED
@@ -8,23 +8,23 @@ require File.expand_path('../pixmatch/client', __FILE__)
|
|
8
8
|
# Adapted from the Ruby Twitter gem.
|
9
9
|
# @see https://github.com/jnunemaker/twitter
|
10
10
|
module Pixmatch
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
11
|
+
extend Configuration
|
12
|
+
|
13
|
+
# Alias for pixmatch::Client.new
|
14
|
+
#
|
15
|
+
# @return {pixmatch::Client}
|
16
|
+
def self.client(options = {})
|
17
|
+
Pixmatch::Client.new(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Delegate to pixmatch::Client
|
21
|
+
def self.method_missing(method, *args, &block)
|
22
|
+
return super unless client.respond_to?(method)
|
23
|
+
client.send(method, *args, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Delegate to pixmatch::Client
|
27
|
+
def self.respond_to?(method)
|
28
|
+
return client.respond_to?(method) || super
|
29
|
+
end
|
30
30
|
end
|
metadata
CHANGED
@@ -1,126 +1,94 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixmatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
prerelease: false
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Daniel Doubrovkine
|
13
|
-
autorequire:
|
9
|
+
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
date: 2011-
|
17
|
-
default_executable:
|
12
|
+
date: 2011-06-02 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
18
14
|
dependencies:
|
19
15
|
- !ruby/object:Gem::Dependency
|
20
16
|
name: rest-client
|
21
|
-
requirement: &
|
17
|
+
requirement: &73142630 !ruby/object:Gem::Requirement
|
22
18
|
none: false
|
23
19
|
requirements:
|
24
20
|
- - ~>
|
25
21
|
- !ruby/object:Gem::Version
|
26
22
|
version: 1.6.1
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 6
|
30
|
-
- 1
|
31
23
|
type: :runtime
|
32
24
|
prerelease: false
|
33
|
-
version_requirements: *
|
25
|
+
version_requirements: *73142630
|
34
26
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
36
|
-
requirement: &
|
27
|
+
name: json
|
28
|
+
requirement: &73142020 !ruby/object:Gem::Requirement
|
37
29
|
none: false
|
38
30
|
requirements:
|
39
31
|
- - ~>
|
40
32
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
- 8
|
45
|
-
- 1
|
33
|
+
version: 1.5.1
|
46
34
|
type: :runtime
|
47
35
|
prerelease: false
|
48
|
-
version_requirements: *
|
36
|
+
version_requirements: *73142020
|
49
37
|
- !ruby/object:Gem::Dependency
|
50
38
|
name: hashie
|
51
|
-
requirement: &
|
39
|
+
requirement: &73141620 !ruby/object:Gem::Requirement
|
52
40
|
none: false
|
53
41
|
requirements:
|
54
42
|
- - ~>
|
55
43
|
- !ruby/object:Gem::Version
|
56
44
|
version: 1.0.0
|
57
|
-
segments:
|
58
|
-
- 1
|
59
|
-
- 0
|
60
|
-
- 0
|
61
45
|
type: :runtime
|
62
46
|
prerelease: false
|
63
|
-
version_requirements: *
|
47
|
+
version_requirements: *73141620
|
64
48
|
- !ruby/object:Gem::Dependency
|
65
49
|
name: rspec
|
66
|
-
requirement: &
|
50
|
+
requirement: &73141140 !ruby/object:Gem::Requirement
|
67
51
|
none: false
|
68
52
|
requirements:
|
69
53
|
- - ~>
|
70
54
|
- !ruby/object:Gem::Version
|
71
55
|
version: 2.5.0
|
72
|
-
segments:
|
73
|
-
- 2
|
74
|
-
- 5
|
75
|
-
- 0
|
76
56
|
type: :development
|
77
57
|
prerelease: false
|
78
|
-
version_requirements: *
|
58
|
+
version_requirements: *73141140
|
79
59
|
- !ruby/object:Gem::Dependency
|
80
60
|
name: bundler
|
81
|
-
requirement: &
|
61
|
+
requirement: &73140550 !ruby/object:Gem::Requirement
|
82
62
|
none: false
|
83
63
|
requirements:
|
84
64
|
- - ~>
|
85
65
|
- !ruby/object:Gem::Version
|
86
66
|
version: 1.0.10
|
87
|
-
segments:
|
88
|
-
- 1
|
89
|
-
- 0
|
90
|
-
- 10
|
91
67
|
type: :development
|
92
68
|
prerelease: false
|
93
|
-
version_requirements: *
|
69
|
+
version_requirements: *73140550
|
94
70
|
- !ruby/object:Gem::Dependency
|
95
71
|
name: jeweler
|
96
|
-
requirement: &
|
72
|
+
requirement: &73139280 !ruby/object:Gem::Requirement
|
97
73
|
none: false
|
98
74
|
requirements:
|
99
75
|
- - ~>
|
100
76
|
- !ruby/object:Gem::Version
|
101
|
-
version: 1.
|
102
|
-
segments:
|
103
|
-
- 1
|
104
|
-
- 5
|
105
|
-
- 2
|
77
|
+
version: 1.6.2
|
106
78
|
type: :development
|
107
79
|
prerelease: false
|
108
|
-
version_requirements: *
|
80
|
+
version_requirements: *73139280
|
109
81
|
- !ruby/object:Gem::Dependency
|
110
82
|
name: yard
|
111
|
-
requirement: &
|
83
|
+
requirement: &73138540 !ruby/object:Gem::Requirement
|
112
84
|
none: false
|
113
85
|
requirements:
|
114
86
|
- - ~>
|
115
87
|
- !ruby/object:Gem::Version
|
116
88
|
version: 0.6.4
|
117
|
-
segments:
|
118
|
-
- 0
|
119
|
-
- 6
|
120
|
-
- 4
|
121
89
|
type: :development
|
122
90
|
prerelease: false
|
123
|
-
version_requirements: *
|
91
|
+
version_requirements: *73138540
|
124
92
|
description: Pixmatch REST API client library for Ruby
|
125
93
|
email: dblock@dblock.org
|
126
94
|
executables: []
|
@@ -145,13 +113,11 @@ files:
|
|
145
113
|
- lib/pixmatch/version.rb
|
146
114
|
- LICENSE.txt
|
147
115
|
- README.rdoc
|
148
|
-
- spec/pixmatch_spec.rb
|
149
|
-
- spec/spec_helper.rb
|
150
116
|
has_rdoc: true
|
151
117
|
homepage: http://github.com/dblock/pixmatch
|
152
118
|
licenses:
|
153
119
|
- MIT
|
154
|
-
post_install_message:
|
120
|
+
post_install_message:
|
155
121
|
rdoc_options: []
|
156
122
|
require_paths:
|
157
123
|
- lib
|
@@ -163,21 +129,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
163
129
|
version: '0'
|
164
130
|
segments:
|
165
131
|
- 0
|
166
|
-
hash:
|
132
|
+
hash: 1011322973
|
167
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
134
|
none: false
|
169
135
|
requirements:
|
170
136
|
- - ! '>='
|
171
137
|
- !ruby/object:Gem::Version
|
172
138
|
version: '0'
|
173
|
-
segments:
|
174
|
-
- 0
|
175
139
|
requirements: []
|
176
|
-
rubyforge_project:
|
177
|
-
rubygems_version: 1.
|
178
|
-
signing_key:
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 1.6.2
|
142
|
+
signing_key:
|
179
143
|
specification_version: 3
|
180
144
|
summary: Pixmatch REST API client library for Ruby
|
181
|
-
test_files:
|
182
|
-
- spec/pixmatch_spec.rb
|
183
|
-
- spec/spec_helper.rb
|
145
|
+
test_files: []
|
data/spec/pixmatch_spec.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
|
-
|
5
|
-
describe "Pixmatch" do
|
6
|
-
before(:each) do
|
7
|
-
Pixmatch.configure do |config|
|
8
|
-
pixmatch_yml = File.join(File.dirname(__FILE__), '../config/pixmatch.yml')
|
9
|
-
pixmatch_yml = File.join(File.dirname(__FILE__), '../config/pixmatch.yml.default') if ! File.exists?(pixmatch_yml)
|
10
|
-
raise "missing config/pixmatch.yml" if ! File.exists?(pixmatch_yml)
|
11
|
-
pixmatch_config = YAML.load_file(pixmatch_yml)['test']
|
12
|
-
config.username = pixmatch_config['username']
|
13
|
-
config.password = pixmatch_config['password']
|
14
|
-
config.endpoint = pixmatch_config['endpoint']
|
15
|
-
end
|
16
|
-
end
|
17
|
-
describe "methods" do
|
18
|
-
it "ping" do
|
19
|
-
response = Pixmatch.ping()
|
20
|
-
response['status'].should == "ok"
|
21
|
-
response['method'].should == "ping"
|
22
|
-
end
|
23
|
-
it "count" do
|
24
|
-
count = Pixmatch.count()
|
25
|
-
count.is_a?(Integer).should be_true
|
26
|
-
count.should >= 0
|
27
|
-
end
|
28
|
-
it "add with one path" do
|
29
|
-
response = Pixmatch.add(File.join(File.dirname(__FILE__), 'assets/mona-lisa.jpg'))
|
30
|
-
response['status'].should == "ok"
|
31
|
-
response['method'].should == "add"
|
32
|
-
end
|
33
|
-
it "add with one path as an array" do
|
34
|
-
response = Pixmatch.add([ File.join(File.dirname(__FILE__), 'assets/mona-lisa.jpg') ])
|
35
|
-
response['status'].should == "ok"
|
36
|
-
response['method'].should == "add"
|
37
|
-
end
|
38
|
-
it "add with one File object" do
|
39
|
-
response = Pixmatch.add(File.new(File.join(File.dirname(__FILE__), 'assets/mona-lisa.jpg')))
|
40
|
-
response['status'].should == "ok"
|
41
|
-
response['method'].should == "add"
|
42
|
-
end
|
43
|
-
it "add with one File object as an array" do
|
44
|
-
response = Pixmatch.add([ File.new(File.join(File.dirname(__FILE__), 'assets/mona-lisa.jpg')) ])
|
45
|
-
response['status'].should == "ok"
|
46
|
-
response['method'].should == "add"
|
47
|
-
end
|
48
|
-
it "add with an array of File objects" do
|
49
|
-
response = Pixmatch.add(Dir.glob(File.join(File.dirname(__FILE__), 'assets/*.jpg')))
|
50
|
-
response['status'].should == "ok"
|
51
|
-
response['method'].should == "add"
|
52
|
-
end
|
53
|
-
it "list" do
|
54
|
-
result = Pixmatch.list()
|
55
|
-
result.is_a?(Array).should be_true
|
56
|
-
result.size.should >= 0
|
57
|
-
end
|
58
|
-
it "delete with one name" do
|
59
|
-
Pixmatch.add([ File.new(File.join(File.dirname(__FILE__), 'assets/mona-lisa.jpg')) ])
|
60
|
-
count = Pixmatch.count
|
61
|
-
response = Pixmatch.delete('mona-lisa.jpg')
|
62
|
-
response['status'].should == "ok"
|
63
|
-
response['method'].should == "delete"
|
64
|
-
Pixmatch.count.should == count - 1
|
65
|
-
end
|
66
|
-
it "delete an array of names" do
|
67
|
-
Pixmatch.add(Dir.glob(File.join(File.dirname(__FILE__), 'assets/*.jpg')))
|
68
|
-
count = Pixmatch.count
|
69
|
-
filenames = Dir.glob(File.join(File.dirname(__FILE__), 'assets/*.jpg')).map { |f| File.basename(f) }
|
70
|
-
response = Pixmatch.delete(filenames)
|
71
|
-
response['status'].should == "ok"
|
72
|
-
response['method'].should == "delete"
|
73
|
-
Pixmatch.count.should == count - filenames.size
|
74
|
-
end
|
75
|
-
it "search" do
|
76
|
-
Pixmatch.add(Dir.glob(File.join(File.dirname(__FILE__), 'assets/*.jpg')))
|
77
|
-
response = Pixmatch.search(File.join(File.dirname(__FILE__), 'assets/mona-lisa.jpg'))
|
78
|
-
response.is_a?(Array).should be_true
|
79
|
-
response.size.should >= 0
|
80
|
-
response.each { |result|
|
81
|
-
result.is_a?(Hash).should be_true
|
82
|
-
result.has_key?('score').should be_true
|
83
|
-
result.has_key?('filename').should be_true
|
84
|
-
}
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
|
4
|
-
require 'rspec'
|
5
|
-
require 'pixmatch'
|
6
|
-
|
7
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
8
|
-
|
9
|
-
RSpec.configure do |config|
|
10
|
-
|
11
|
-
end
|