oodle 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -2
- data/lib/oodle.rb +20 -20
- metadata +3 -3
data/README.markdown
CHANGED
@@ -25,9 +25,9 @@ key](http://developer.oodle.com/request-api-key) to get started.
|
|
25
25
|
oodle.num = '15'
|
26
26
|
oodle.sort = 'ctime_reverse'
|
27
27
|
results = oodle.fetch_listings
|
28
|
-
num = results['
|
28
|
+
num = results['meta']['returned']
|
29
29
|
listings = results['listings']
|
30
|
-
(
|
30
|
+
0.upto(num - 1) { |i| p listings[i]['title'] }
|
31
31
|
|
32
32
|
## Dependencies
|
33
33
|
|
data/lib/oodle.rb
CHANGED
@@ -16,11 +16,7 @@ module Oodle
|
|
16
16
|
VERSION_URLS = {:v2=>"http://api.oodle.com/api/v2/listings"}
|
17
17
|
RESPONSE_FORMATS = {
|
18
18
|
:xml=>'xml', # - output is formatted in plain old XML
|
19
|
-
:json=>'json'
|
20
|
-
:php_serial=>'php_serial', # - output structure formatted in serialized PHP
|
21
|
-
:php_export=>'php_export', # - output structure formatted as valid PHP
|
22
|
-
:dump=>'dump', # - output is dumped with no formatting
|
23
|
-
:rss2=>'rss2' # - listing information returned in RSS 2.0 format
|
19
|
+
:json=>'json' # - output is formatted in JSON (JavaScript Object Notation)
|
24
20
|
}
|
25
21
|
|
26
22
|
SORT_VALUES = {
|
@@ -62,6 +58,22 @@ module Oodle
|
|
62
58
|
# Requires version be set
|
63
59
|
# Build the url from the state of the current self
|
64
60
|
def build_url
|
61
|
+
unless key && key.length > 0
|
62
|
+
raise ArgumentError, 'Missing API key parameter. Visit http://developer.oodle.com/request-api-key/ to get one.'
|
63
|
+
end
|
64
|
+
|
65
|
+
unless region && region.length > 0
|
66
|
+
raise ArgumentError, 'Missing region paramter. Visit http://developer.oodle.com/regions-list/ for possible regions.'
|
67
|
+
end
|
68
|
+
|
69
|
+
unless (category && category.length > 0) || (q && q.length > 0)
|
70
|
+
raise ArgumentError, 'You must supply a category or query parameter. Visit http://developer.oodle.com/categories-list/ for possible categories.'
|
71
|
+
end
|
72
|
+
|
73
|
+
unless num.to_i >= 1 && num.to_i <= 50
|
74
|
+
warn "num parameter is #{num.to_i} but should be between 1 and 50"
|
75
|
+
end
|
76
|
+
|
65
77
|
url = VERSION_URLS[self.version]
|
66
78
|
url += "?" unless url && url[-1] == '?'
|
67
79
|
# must CGI escape each param value
|
@@ -71,9 +83,9 @@ module Oodle
|
|
71
83
|
url = "#{url}&q=#{CGI::escape(self.q)}" if self.q
|
72
84
|
url = "#{url}&attributes=#{CGI::escape(self.attributes_as_string)}" if self.attributes.size > 0
|
73
85
|
url = "#{url}&location=#{CGI::escape(self.location)}" if self.location
|
74
|
-
url = "#{url}&radius=#{CGI::escape(self.radius)}" if self.radius
|
75
|
-
url = "#{url}&start=#{CGI::escape(self.start)}" if self.start
|
76
|
-
url = "#{url}&num=#{CGI::escape(self.num)}" if self.num
|
86
|
+
url = "#{url}&radius=#{CGI::escape(self.radius.to_s)}" if self.radius
|
87
|
+
url = "#{url}&start=#{CGI::escape(self.start.to_s)}" if self.start
|
88
|
+
url = "#{url}&num=#{CGI::escape(self.num.to_s)}" if self.num
|
77
89
|
url = "#{url}&sort=#{CGI::escape(self.sort)}" if self.sort
|
78
90
|
url = "#{url}&refinements=#{CGI::escape(self.refinements_as_string)}" if self.refinements.size > 0
|
79
91
|
url = "#{url}&ctime_low=#{CGI::escape(self.ctime_low)}" if self.ctime_low
|
@@ -107,10 +119,6 @@ module Oodle
|
|
107
119
|
=begin
|
108
120
|
xml - output is formatted in plain old XML
|
109
121
|
json - output is fromatted in JSON (JavaScript Object Notation)
|
110
|
-
php_serial - output structure formatted in serialized PHP
|
111
|
-
php_export - output structure formatted as valid PHP
|
112
|
-
dump - output is dumped with no formatting
|
113
|
-
rss2 - listing information returned in RSS 2.0 format
|
114
122
|
=end
|
115
123
|
def fetch_raw(format=nil)
|
116
124
|
@format = RESPONSE_FORMATS[format] if format
|
@@ -128,14 +136,6 @@ module Oodle
|
|
128
136
|
result = XmlSimple.xml_in raw, { 'ForceArray' => false, 'AttrPrefix' => true }
|
129
137
|
when 'json'
|
130
138
|
result = JSON.parse(raw)
|
131
|
-
when 'php_serial'
|
132
|
-
# return raw
|
133
|
-
when 'php_export'
|
134
|
-
# return raw
|
135
|
-
when 'dump'
|
136
|
-
# return raw
|
137
|
-
when 'rss2'
|
138
|
-
# TODO parse rss2 raw
|
139
139
|
end
|
140
140
|
result = raw unless result
|
141
141
|
result
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
8
|
+
- 4
|
9
|
+
version: 1.1.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristan 'Krispy' Uccello
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-04-
|
18
|
+
date: 2010-04-10 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|