oodle 1.0.0
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/Changelog +0 -0
- data/INSTALL +0 -0
- data/LICENSE +19 -0
- data/README.markdown +9 -0
- data/lib/oodle.rb +175 -0
- metadata +59 -0
data/Changelog
ADDED
File without changes
|
data/INSTALL
ADDED
File without changes
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2009 Kristan 'Krispy' Uccello, http://soldierofcode.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Oodle Ruby API (v1.0)
|
2
|
+
---
|
3
|
+
|
4
|
+
## This software is licensed using the MIT License (see LICENSE for details)
|
5
|
+
|
6
|
+
## Description of use
|
7
|
+
|
8
|
+
This is a wrapper api for the Oodle API (http://developer.oodle.com/). It follows very tightly against the documentation provided by oodle and it works like this:
|
9
|
+
|
data/lib/oodle.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
#
|
2
|
+
#
|
3
|
+
#
|
4
|
+
#
|
5
|
+
require 'net/http'
|
6
|
+
require 'xmlsimple'
|
7
|
+
require 'cgi'
|
8
|
+
|
9
|
+
# Oodle Module
|
10
|
+
module Oodle
|
11
|
+
|
12
|
+
REGIONS_URL = "http://developer.oodle.com/files/xml/oodle_regions.xml"
|
13
|
+
CATEGORIES_URL = "http://developer.oodle.com/files/xml/oodle_categories.xml"
|
14
|
+
|
15
|
+
VERSION_URLS = {:v2=>"http://api.oodle.com/api/v2/listings"}
|
16
|
+
RESPONSE_FORMATS = {
|
17
|
+
:xml=>'xml', # - output is formatted in plain old XML
|
18
|
+
:json=>'json', # - output is fromatted in JSON (JavaScript Object Notation)
|
19
|
+
:php_serial=>'php_serial', # - output structure formatted in serialized PHP
|
20
|
+
:php_export=>'php_export', # - output structure formatted as valid PHP
|
21
|
+
:dump=>'dump', # - output is dumped with no formatting
|
22
|
+
:rss2=>'rss2' # - listing information returned in RSS 2.0 format
|
23
|
+
}
|
24
|
+
|
25
|
+
SORT_VALUES = {
|
26
|
+
:ctime=>'ctime',# - by listing's creation time - oldest to newest
|
27
|
+
:ctime_reverse=>'ctime_reverse',# - by listing's creation time, reverse order - newest to oldest
|
28
|
+
:distance=>'distance',# - by distance from "location" value above - closest to farthest
|
29
|
+
:distance_reverse=>'distance_reverse',# - by distance from "location" parameter, reverse order - farthest to closest
|
30
|
+
:eventdate=>'eventdate',# - by date of event (e.g. tickets listings) - in chronological order
|
31
|
+
:eventdate_reverse=>'eventdate_reverse',# - by date of event - in reverse chronological order
|
32
|
+
:price=>'price',# - by listing's price - lowest to highest
|
33
|
+
:price_reverse=>'price_reverse' # - by listing's price, reverse order - highest to lowest
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
#
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# Oodle Class
|
41
|
+
#
|
42
|
+
class API
|
43
|
+
logger.debug "Oodle::API is loaded." if logger
|
44
|
+
|
45
|
+
attr_accessor :key, :region, :q, :category, :attributes, :location, :radius, :start, :num, :sort, :refinements, :ctime_low, :ctime_high, :exclude_sources, :assisted_search, :format, :jsoncallback, :fetched, :version
|
46
|
+
|
47
|
+
def initialize(key,version)
|
48
|
+
@key = key
|
49
|
+
@version = version if version
|
50
|
+
@version = :v2 unless version
|
51
|
+
@attributes = []
|
52
|
+
@refinements = []
|
53
|
+
@exclude_sources = []
|
54
|
+
@format = RESPONSE_FORMATS[:xml]
|
55
|
+
end
|
56
|
+
|
57
|
+
# A convience method to do actual http pulls
|
58
|
+
# Notice that there is not any exception trapping
|
59
|
+
def http_pull(dest_url)
|
60
|
+
logger.debug "Pulling from url: #{dest_url}" if logger
|
61
|
+
url = URI.parse(dest_url)
|
62
|
+
req = Net::HTTP::Get.new(url.path)
|
63
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
64
|
+
http.request(req)
|
65
|
+
}
|
66
|
+
self.fetched = res.body
|
67
|
+
return self.fetched
|
68
|
+
end
|
69
|
+
|
70
|
+
# Requires version be set
|
71
|
+
# Build the url from the state of the current self
|
72
|
+
def build_url
|
73
|
+
url = VERSION_URLS[self.version]
|
74
|
+
url += "?" unless url && url[-1] == '?'
|
75
|
+
# must CGI escape each param value
|
76
|
+
url = "#{url}key=#{CGI::escape(self.key)}"
|
77
|
+
url = "#{url}®ion=#{CGI::escape(self.region)}" if self.region
|
78
|
+
url = "#{url}&category=#{CGI::escape(self.category)}" if self.category
|
79
|
+
url = "#{url}&q=#{CGI::escape(self.q)}" if self.q
|
80
|
+
url = "#{url}&attributes=#{CGI::escape(self.attributes_as_string)}" if self.attributes.size > 0
|
81
|
+
url = "#{url}&location=#{CGI::escape(self.location)}" if self.location
|
82
|
+
url = "#{url}&radius=#{CGI::escape(self.radius)}" if self.radius
|
83
|
+
url = "#{url}&start=#{CGI::escape(self.start)}" if self.start
|
84
|
+
url = "#{url}&num=#{CGI::escape(self.num)}" if self.num
|
85
|
+
url = "#{url}&sort=#{CGI::escape(self.sort)}" if self.sort
|
86
|
+
url = "#{url}&refinements=#{CGI::escape(self.refinements_as_string)}" if self.refinements.size > 0
|
87
|
+
url = "#{url}&ctime_low=#{CGI::escape(self.ctime_low)}" if self.ctime_low
|
88
|
+
url = "#{url}&ctime_high=#{CGI::escape(self.ctime_high)}" if self.ctime_high
|
89
|
+
url = "#{url}&exclude_sources=#{CGI::escape(self.exclude_sources_as_string)}" if self.exclude_sources.size > 0
|
90
|
+
url = "#{url}&assisted_search=#{CGI::escape(self.assisted_search)}" if self.assisted_search
|
91
|
+
url = "#{url}&format=#{CGI::escape(self.format)}" if self.format
|
92
|
+
logger.debug "#{__FILE__}:#{__LINE__} [#{__method__}] -- URL CONSTRUCTED: #{url}" if logger
|
93
|
+
url
|
94
|
+
end
|
95
|
+
|
96
|
+
# THESE CAN BE REFACTORED INTO SOMETHING MORE META-LIKE
|
97
|
+
def exclude_sources_as_string
|
98
|
+
res = ""
|
99
|
+
res = self.exclude_sources.join(',') if self.exclude_sources.size > 0
|
100
|
+
res
|
101
|
+
end
|
102
|
+
|
103
|
+
def refinements_as_string
|
104
|
+
res = ""
|
105
|
+
res = self.refinements.join(',') if self.refinements.size > 0
|
106
|
+
res
|
107
|
+
end
|
108
|
+
|
109
|
+
def attributes_as_string
|
110
|
+
res = ""
|
111
|
+
res = self.attributes.join(',') if self.attributes.size > 0
|
112
|
+
res
|
113
|
+
end
|
114
|
+
# -----------------------
|
115
|
+
|
116
|
+
=begin
|
117
|
+
xml - output is formatted in plain old XML
|
118
|
+
json - output is fromatted in JSON (JavaScript Object Notation)
|
119
|
+
php_serial - output structure formatted in serialized PHP
|
120
|
+
php_export - output structure formatted as valid PHP
|
121
|
+
dump - output is dumped with no formatting
|
122
|
+
rss2 - listing information returned in RSS 2.0 format
|
123
|
+
=end
|
124
|
+
def fetch_raw(format=nil)
|
125
|
+
@format = RESPONSE_FORMATS[format] if format
|
126
|
+
http_pull(build_url)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Returns an array of listings based on the last fetch
|
130
|
+
# if fetch is empty then will trigger a fetch
|
131
|
+
def fetch_listings(format=nil)
|
132
|
+
result = nil
|
133
|
+
raw = fetch_raw(format)
|
134
|
+
case self.format
|
135
|
+
when 'xml'
|
136
|
+
# parse xml raw
|
137
|
+
result = XmlSimple.xml_in raw, { 'ForceArray' => false, 'AttrPrefix' => true }
|
138
|
+
when 'json'
|
139
|
+
# TODO parse json raw
|
140
|
+
when 'php_serial'
|
141
|
+
# return raw
|
142
|
+
when 'php_export'
|
143
|
+
# return raw
|
144
|
+
when 'dump'
|
145
|
+
# return raw
|
146
|
+
when 'rss2'
|
147
|
+
# TODO parse rss2 raw
|
148
|
+
end
|
149
|
+
result = raw unless result
|
150
|
+
result
|
151
|
+
end
|
152
|
+
|
153
|
+
def fetch_categories(raw=false)
|
154
|
+
xml = http_pull(CATEGORIES_URL)
|
155
|
+
if raw
|
156
|
+
xml
|
157
|
+
else
|
158
|
+
# parse into objects
|
159
|
+
XmlSimple.xml_in xml, { 'ForceArray' => false, 'AttrPrefix' => true }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def fetch_regions(raw=false)
|
164
|
+
xml = http_pull(REGIONS_URL)
|
165
|
+
if raw
|
166
|
+
xml
|
167
|
+
else
|
168
|
+
# parse into objects
|
169
|
+
XmlSimple.xml_in xml, { 'ForceArray' => false, 'AttrPrefix' => true }
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oodle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kristan 'Krispy' Uccello
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-06 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Provides a ruby wrapper around the Oodle api
|
17
|
+
email: kaptiankrispy@soldierofcode.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.markdown
|
26
|
+
- Changelog
|
27
|
+
- LICENSE
|
28
|
+
- lib/oodle.rb
|
29
|
+
- INSTALL
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://soldierofcode.com/projects/oodle-api
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.3.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: Provides a ruby wrapper around the Oodle api
|
58
|
+
test_files: []
|
59
|
+
|