bing_images 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bing_images.rb +4 -20
- metadata +3 -3
data/lib/bing_images.rb
CHANGED
@@ -23,8 +23,6 @@
|
|
23
23
|
|
24
24
|
require 'addressable/uri'
|
25
25
|
require 'net/http'
|
26
|
-
require 'net/https'
|
27
|
-
require 'rexml/document'
|
28
26
|
require 'URI'
|
29
27
|
|
30
28
|
|
@@ -39,9 +37,7 @@ module BingImages
|
|
39
37
|
def search(query, safe, offset)
|
40
38
|
query = build_query(query, safe, offset)
|
41
39
|
url = URL + '?' + query
|
42
|
-
|
43
|
-
results = parse_xml(xml)
|
44
|
-
results
|
40
|
+
json = issue_request(url)
|
45
41
|
end
|
46
42
|
|
47
43
|
def build_query(query, safe, offset)
|
@@ -49,6 +45,7 @@ module BingImages
|
|
49
45
|
uri.query_values = {
|
50
46
|
Query: "'" + query + "'",
|
51
47
|
Adult: "'" + (safe ? 'Moderate' : 'Off') + "'",
|
48
|
+
'$format' => 'json',
|
52
49
|
'$skip' => offset,
|
53
50
|
}
|
54
51
|
uri.query
|
@@ -64,25 +61,12 @@ module BingImages
|
|
64
61
|
response = http.request(request)
|
65
62
|
response.body
|
66
63
|
end
|
67
|
-
|
68
|
-
def parse_xml(xml)
|
69
|
-
doc = REXML::Document.new(xml)
|
70
|
-
results = []
|
71
|
-
doc.elements.each('feed/entry/content/m:properties') do |element|
|
72
|
-
result = {
|
73
|
-
thumbnail: (element.elements.each('d:Thumbnail/d:MediaUrl') {})[0].get_text,
|
74
|
-
full_size: (element.elements.each('d:MediaUrl') {})[0].get_text,
|
75
|
-
}
|
76
|
-
results << result
|
77
|
-
end
|
78
|
-
results
|
79
|
-
end
|
80
64
|
end
|
81
65
|
end
|
82
66
|
|
83
67
|
|
84
68
|
if __FILE__ == $0
|
85
69
|
query = ARGV.join(' ')
|
86
|
-
|
87
|
-
puts
|
70
|
+
json = BingImages.search(query, false, 0)
|
71
|
+
puts json
|
88
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bing_images
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: A
|
14
|
+
description: A wrapper around Bing's image search.
|
15
15
|
email: brainix@gmail.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|