tineye 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/library/tineye.rb +16 -0
  2. data/library/tineye/client.rb +35 -0
  3. metadata +67 -0
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ require 'net/http'
4
+ require 'nokogiri'
5
+ require 'tineye/client'
6
+
7
+ module TinEye
8
+ class << Version = [1,0]
9
+ def to_s; join ?. end
10
+ end
11
+
12
+ module_function
13
+
14
+ def search *args; client.search *args end
15
+ def client; @instance ||= Client.new end
16
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ module TinEye
4
+ class Client
5
+ SearchURI = URI 'http://www.tineye.com/search'
6
+
7
+ def initialize
8
+ # …
9
+ end
10
+
11
+ def search image_url
12
+ response = Net::HTTP.post_form SearchURI, url: image_url
13
+
14
+ case response
15
+ when Net::HTTPRedirection
16
+ extract_images Net::HTTP.get URI response['location']
17
+ else
18
+ raise "Malformed result"
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def extract_images response
25
+ document = Nokogiri::HTML response
26
+
27
+ document.xpath('//div[@class="result-match-details"]').map do |element|
28
+ location = element.xpath('div/span/strong')[0].text
29
+ links = element.xpath 'div/p/a'
30
+
31
+ { host: location, direct: links[0]['href'], url: links[1]['href'] }
32
+ end
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tineye
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Mikkel Kroman
13
+ autorequire:
14
+ bindir: executables
15
+ cert_chain: []
16
+
17
+ date: 2010-11-26 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email: mk@maero.dk
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - library/tineye.rb
31
+ - library/tineye/client.rb
32
+ has_rdoc: true
33
+ homepage:
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - library
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ segments:
47
+ - 1
48
+ - 9
49
+ - 1
50
+ version: 1.9.1
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.7
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Tiny library to search for online images on tineye.com.
66
+ test_files: []
67
+