marauder 0.1.1.2 → 0.1.1.3
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.
- data/README.rdoc +10 -2
- data/Rakefile +1 -1
- data/lib/marauder.rb +72 -47
- data/marauder.gemspec +2 -2
- metadata +4 -4
data/README.rdoc
CHANGED
|
@@ -16,10 +16,18 @@ Check out the Google Base API Documentation for more info: http://code.google.co
|
|
|
16
16
|
|
|
17
17
|
Marauder.search(query)
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Or:
|
|
20
|
+
|
|
21
|
+
Marauder::SearchRequest.new(query).process
|
|
22
|
+
|
|
23
|
+
Returns an array of Results containing all data provided by Google Base.
|
|
20
24
|
|
|
21
25
|
Marauder.find_by_google_id(google_id)
|
|
26
|
+
|
|
27
|
+
Or:
|
|
28
|
+
|
|
29
|
+
Marauder::ItemRequest.new(google_id).process
|
|
22
30
|
|
|
23
|
-
Returns
|
|
31
|
+
Returns Result.
|
|
24
32
|
|
|
25
33
|
|
data/Rakefile
CHANGED
|
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
|
2
2
|
require 'rake'
|
|
3
3
|
require 'echoe'
|
|
4
4
|
|
|
5
|
-
Echoe.new('marauder', '0.1.1.
|
|
5
|
+
Echoe.new('marauder', '0.1.1.3') do |p|
|
|
6
6
|
p.description = "Wrapper for the Google Base product search API."
|
|
7
7
|
p.url = "http://github.com/samueljamesbell/marauder"
|
|
8
8
|
p.author = "Sam Bell"
|
data/lib/marauder.rb
CHANGED
|
@@ -1,66 +1,91 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'rexml/document'
|
|
3
|
+
|
|
1
4
|
module Marauder
|
|
2
|
-
require 'net/http'
|
|
3
|
-
require 'rexml/document'
|
|
4
|
-
require 'ostruct'
|
|
5
|
-
|
|
6
5
|
|
|
7
|
-
def self.search(query)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
def self.search(query, params = {})
|
|
7
|
+
extra_params = []
|
|
8
|
+
unless params.nil?
|
|
9
|
+
params.each {|attribute, value| extra_params << "[#{attribute}:#{value}]"}
|
|
10
|
+
end
|
|
11
|
+
SearchRequest.new(query, extra_params).process
|
|
13
12
|
end
|
|
14
|
-
|
|
15
|
-
def self.
|
|
16
|
-
|
|
17
|
-
url = "http://www.google.com/base/feeds/snippets?q=#{formatted_query}&bq=[#{attribute}:#{value}]"
|
|
18
|
-
xml_data = Net::HTTP.get_response(URI.parse(url)).body
|
|
19
|
-
|
|
20
|
-
self.process_xml(xml_data)
|
|
13
|
+
|
|
14
|
+
def self.find_by_google_id(google_id)
|
|
15
|
+
ItemRequest.new(google_id).process
|
|
21
16
|
end
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
doc = REXML::Document.new(xml_data)
|
|
18
|
+
class ItemRequest
|
|
19
|
+
attr_accessor :url
|
|
26
20
|
|
|
27
|
-
|
|
21
|
+
def initialize(google_id)
|
|
22
|
+
self.url = google_id
|
|
23
|
+
end
|
|
28
24
|
|
|
29
|
-
|
|
25
|
+
def process
|
|
26
|
+
xml_data = Net::HTTP.get_response(URI.parse(url)).body
|
|
27
|
+
doc = REXML::Document.new(xml_data)
|
|
28
|
+
entry = doc.elements['entry']
|
|
29
|
+
|
|
30
|
+
Result.new(entry)
|
|
31
|
+
end
|
|
30
32
|
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
def self.process_xml(xml_data)
|
|
35
|
-
doc = REXML::Document.new(xml_data)
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
class SearchRequest
|
|
35
|
+
attr_accessor :url
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
def initialize(query, extra_params = [])
|
|
38
|
+
formatted_query = format_query(query)
|
|
39
|
+
if extra_params.empty?
|
|
40
|
+
self.url = "http://www.google.com/base/feeds/snippets?q=#{formatted_query}"
|
|
41
|
+
else
|
|
42
|
+
formatted_params = extra_params.join(",")
|
|
43
|
+
self.url = "http://www.google.com/base/feeds/snippets?q=#{formatted_query}&bq=#{formatted_params}"
|
|
44
|
+
end
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
def process
|
|
48
|
+
xml_data = Net::HTTP.get_response(URI.parse(url)).body
|
|
49
|
+
doc = REXML::Document.new(xml_data)
|
|
50
|
+
|
|
51
|
+
results = []
|
|
52
|
+
doc.elements.each("feed/entry") do |entry|
|
|
53
|
+
results << Result.new(entry)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
results
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def format_query(query)
|
|
62
|
+
return query.gsub(/[ ]/, '+')
|
|
63
|
+
end
|
|
64
|
+
|
|
47
65
|
end
|
|
48
66
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
class Result
|
|
68
|
+
attr_accessor :hash
|
|
69
|
+
|
|
70
|
+
def initialize(entry)
|
|
71
|
+
self.hash = {}
|
|
72
|
+
|
|
73
|
+
entry.elements.each do |element|
|
|
74
|
+
case element.name
|
|
75
|
+
when /id/
|
|
76
|
+
hash['google_id'] = entry.elements['id'].text
|
|
77
|
+
when 'g:author'
|
|
78
|
+
hash['author_name'] = entry.elements['author'].elements['name'].text
|
|
79
|
+
else
|
|
80
|
+
hash[element.name.gsub(/g:/, '')] = element.text
|
|
81
|
+
end
|
|
60
82
|
end
|
|
61
83
|
end
|
|
62
|
-
|
|
63
|
-
|
|
84
|
+
|
|
85
|
+
def method_missing(method, *args)
|
|
86
|
+
puts hash.inspect
|
|
87
|
+
hash.has_key?(method.to_s) ? hash[method.to_s] : super
|
|
88
|
+
end
|
|
64
89
|
end
|
|
65
90
|
|
|
66
91
|
end
|
data/marauder.gemspec
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{marauder}
|
|
5
|
-
s.version = "0.1.1.
|
|
5
|
+
s.version = "0.1.1.3"
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
8
|
s.authors = ["Sam Bell"]
|
|
9
|
-
s.date = %q{2010-07-
|
|
9
|
+
s.date = %q{2010-07-26}
|
|
10
10
|
s.description = %q{Wrapper for the Google Base product search API.}
|
|
11
11
|
s.email = %q{samueljamesbell@gmail.com}
|
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/marauder.rb"]
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: marauder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 69
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 1
|
|
9
9
|
- 1
|
|
10
|
-
-
|
|
11
|
-
version: 0.1.1.
|
|
10
|
+
- 3
|
|
11
|
+
version: 0.1.1.3
|
|
12
12
|
platform: ruby
|
|
13
13
|
authors:
|
|
14
14
|
- Sam Bell
|
|
@@ -16,7 +16,7 @@ autorequire:
|
|
|
16
16
|
bindir: bin
|
|
17
17
|
cert_chain: []
|
|
18
18
|
|
|
19
|
-
date: 2010-07-
|
|
19
|
+
date: 2010-07-26 00:00:00 +01:00
|
|
20
20
|
default_executable:
|
|
21
21
|
dependencies: []
|
|
22
22
|
|