marauder 0.1.1.1 → 0.1.1.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.
- data/README.rdoc +7 -7
- data/Rakefile +1 -1
- data/lib/marauder.rb +30 -23
- data/marauder.gemspec +2 -2
- metadata +4 -4
data/README.rdoc
CHANGED
|
@@ -5,21 +5,21 @@ Wrapper for the Google Base product search API.
|
|
|
5
5
|
|
|
6
6
|
== Install
|
|
7
7
|
|
|
8
|
-
gem install
|
|
9
|
-
|
|
10
|
-
If you're using rails, create a file named marauder_config.yml the config directory, including the following:
|
|
11
|
-
|
|
12
|
-
api_key: YOUR GOOGLE BASE KEY
|
|
13
|
-
|
|
14
|
-
If not, create the config file anyway, and edit line 7 of marauder.rb to point to your config file.
|
|
8
|
+
gem install marauder
|
|
15
9
|
|
|
16
10
|
|
|
17
11
|
== Getting Started
|
|
18
12
|
|
|
13
|
+
Check out the Google Base API Documentation for more info: http://code.google.com/apis/base/
|
|
14
|
+
|
|
19
15
|
require 'Marauder'
|
|
20
16
|
|
|
21
17
|
Marauder.search(query)
|
|
22
18
|
|
|
23
19
|
Returns an array of OpenStruct objects with getters for all data provided by the Google Base.
|
|
20
|
+
|
|
21
|
+
Marauder.find_by_google_id(google_id)
|
|
22
|
+
|
|
23
|
+
Returns OpenStruct object of object.
|
|
24
24
|
|
|
25
25
|
|
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.2') 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
|
@@ -3,11 +3,35 @@ module Marauder
|
|
|
3
3
|
require 'rexml/document'
|
|
4
4
|
require 'ostruct'
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
def self.search(query)
|
|
7
8
|
formatted_query = query.gsub(/[ ]/, '+')
|
|
8
9
|
url = "http://www.google.com/base/feeds/snippets?bq=#{formatted_query}"
|
|
9
10
|
xml_data = Net::HTTP.get_response(URI.parse(url)).body
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
self.process_xml(xml_data)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.search_by_attribute(query, attribute, value)
|
|
16
|
+
formatted_query = query.gsub(/[ ]/, '+')
|
|
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)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.find_by_google_id(google_id)
|
|
24
|
+
xml_data = Net::HTTP.get_response(URI.parse(google_id)).body
|
|
25
|
+
doc = REXML::Document.new(xml_data)
|
|
26
|
+
|
|
27
|
+
entry = doc.elements['entry']
|
|
28
|
+
|
|
29
|
+
self.create_ostruct(entry)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def self.process_xml(xml_data)
|
|
11
35
|
doc = REXML::Document.new(xml_data)
|
|
12
36
|
|
|
13
37
|
entries = []
|
|
@@ -15,45 +39,28 @@ module Marauder
|
|
|
15
39
|
|
|
16
40
|
results = []
|
|
17
41
|
entries.each do |entry|
|
|
18
|
-
r =
|
|
19
|
-
entry.elements.each do |element|
|
|
20
|
-
if element.name == 'id'
|
|
21
|
-
r.google_id = entry.elements['id'].text
|
|
22
|
-
elsif element.name.gsub(/g:/,'') == 'author'
|
|
23
|
-
r.author_name = entry.elements['author'].elements['name'].text
|
|
24
|
-
else
|
|
25
|
-
m = element.name.gsub(/g:/,'').to_s
|
|
26
|
-
method = m + "="
|
|
27
|
-
r.send method.to_sym, element.text
|
|
28
|
-
end
|
|
29
|
-
end
|
|
42
|
+
r = self.create_ostruct(entry)
|
|
30
43
|
results << r
|
|
31
44
|
end
|
|
32
45
|
|
|
33
46
|
return results
|
|
34
47
|
end
|
|
35
48
|
|
|
36
|
-
def self.
|
|
37
|
-
xml_data = Net::HTTP.get_response(URI.parse(google_id)).body
|
|
38
|
-
doc = REXML::Document.new(xml_data)
|
|
39
|
-
|
|
49
|
+
def self.create_ostruct(entry)
|
|
40
50
|
r = OpenStruct.new
|
|
41
|
-
|
|
42
|
-
entry = doc.elements['entry']
|
|
43
|
-
|
|
44
51
|
entry.elements.each do |element|
|
|
45
52
|
if element.name == 'id'
|
|
46
53
|
r.google_id = entry.elements['id'].text
|
|
47
54
|
elsif element.name.gsub(/g:/,'') == 'author'
|
|
48
|
-
r.author_name =
|
|
55
|
+
r.author_name = entry.elements['author'].elements['name'].text
|
|
49
56
|
else
|
|
50
57
|
m = element.name.gsub(/g:/,'').to_s
|
|
51
58
|
method = m + "="
|
|
52
59
|
r.send method.to_sym, element.text
|
|
53
60
|
end
|
|
54
61
|
end
|
|
55
|
-
|
|
62
|
+
|
|
56
63
|
return r
|
|
57
64
|
end
|
|
58
|
-
|
|
65
|
+
|
|
59
66
|
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.2"
|
|
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-22}
|
|
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: 71
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 1
|
|
9
9
|
- 1
|
|
10
|
-
-
|
|
11
|
-
version: 0.1.1.
|
|
10
|
+
- 2
|
|
11
|
+
version: 0.1.1.2
|
|
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-22 00:00:00 +01:00
|
|
20
20
|
default_executable:
|
|
21
21
|
dependencies: []
|
|
22
22
|
|