bing_images 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/bing_images.rb +4 -20
  2. metadata +3 -3
@@ -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
- xml = issue_request(url)
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
- photos = BingImages.search(query, false, 0)
87
- puts photos
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.1
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-04 00:00:00.000000000 Z
12
+ date: 2012-07-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: A Ruby gem wrapper around Bing's image search.
14
+ description: A wrapper around Bing's image search.
15
15
  email: brainix@gmail.com
16
16
  executables: []
17
17
  extensions: []