andyshearer-lonely_planet 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +7 -0
- data/README.txt +47 -0
- data/Rakefile +12 -0
- data/lib/lonely_planet.rb +295 -0
- data/test/test_lonely_planet.rb +0 -0
- metadata +70 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= LonelyPlanet
|
2
|
+
|
3
|
+
mibly.com
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
|
20
|
+
== INSTALL:
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
== LICENSE:
|
25
|
+
|
26
|
+
(The MIT License)
|
27
|
+
|
28
|
+
Copyright (c) 2008 FIX
|
29
|
+
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
31
|
+
a copy of this software and associated documentation files (the
|
32
|
+
'Software'), to deal in the Software without restriction, including
|
33
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
34
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
35
|
+
permit persons to whom the Software is furnished to do so, subject to
|
36
|
+
the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be
|
39
|
+
included in all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
43
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
44
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
45
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
46
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
47
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
#
|
3
|
+
#require 'rubygems'
|
4
|
+
#require 'hoe'
|
5
|
+
#require './lib/lonely_planet.rb'
|
6
|
+
#
|
7
|
+
#Hoe.new('LonelyPlanet', LonelyPlanet::VERSION) do |p|
|
8
|
+
# # p.rubyforge_name = 'LonelyPlanetx' # if different than lowercase project name
|
9
|
+
# # p.developer('FIX', 'FIX@example.com')
|
10
|
+
#end
|
11
|
+
|
12
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,295 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/http'
|
3
|
+
require 'cgi'
|
4
|
+
require 'xmlsimple'
|
5
|
+
|
6
|
+
|
7
|
+
module Lonelyplanet
|
8
|
+
# the default hostname at which the LonelyPlanet API is hosted
|
9
|
+
DEFAULT_HOST = 'http://api.lonelyplanet.com'
|
10
|
+
# the default api path to the LonelyPlanet API
|
11
|
+
DEFAULT_API_PATH = '/services/get/'
|
12
|
+
VERSION = '1.0.0'
|
13
|
+
|
14
|
+
# Main client class managing all interaction with the YouTube server.
|
15
|
+
# Server communication is handled via method_missing() emulating an
|
16
|
+
# RPC-like call and performing all of the work to send out the HTTP
|
17
|
+
# request and retrieve the XML response. Inspired by the Flickr
|
18
|
+
# interface by Scott Raymond <http://redgreenblu.com/flickr/>.
|
19
|
+
# This in turn was insperation from the youtube gem by Shane Vitarana
|
20
|
+
|
21
|
+
class Client
|
22
|
+
def initialize(dev_id = nil, host = DEFAULT_HOST, api_path = DEFAULT_API_PATH)
|
23
|
+
raise "developer id required" unless dev_id
|
24
|
+
@dev_id = dev_id
|
25
|
+
@host = host
|
26
|
+
@api_path = api_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def geotree(destination = nil, language = 'eng', hide_empty = 'false', id_type = 'description')
|
30
|
+
raise "destination string required" unless destination
|
31
|
+
response = geotree_api(destination, language, hide_empty, id_type)
|
32
|
+
_parse_geotaxonomy_response(response)
|
33
|
+
end
|
34
|
+
|
35
|
+
def destination(destination = nil, language = 'eng', erm = 'false')
|
36
|
+
raise "destination string required" unless destination
|
37
|
+
response = destination_api(destination, language, erm)
|
38
|
+
_parse_destination_response(response)
|
39
|
+
# puts "http://api.lonelyplanet.com/services/get/lps.destination/xml/#{@dev_id}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def destination_pois(destination = nil, activity = '*', language = 'eng', count = 5)
|
43
|
+
raise "destination string required" unless destination
|
44
|
+
response = destination_pois_api(destination, activity, language, count)
|
45
|
+
_parse_pois_response(response)
|
46
|
+
end
|
47
|
+
|
48
|
+
def tagged_pois(destination = nil, tag = nil, language = 'eng', count = 5)
|
49
|
+
raise "destination string and tag required" unless destination and tag
|
50
|
+
response = tagged_pois_api(destination, tag, language, count)
|
51
|
+
_parse_pois_response(response)
|
52
|
+
end
|
53
|
+
|
54
|
+
def proximity_pois(latitude = nil, longitude = nil, poi = '*', activity = 'see', radius = '5', language = 'eng', count = 5)
|
55
|
+
response = proximity_pois_api(latitude, longitude, poi, activity, radius, language, count)
|
56
|
+
_parse_proximity_pois_response(response)
|
57
|
+
end
|
58
|
+
|
59
|
+
def poi(poi_id = nil, language = 'eng')
|
60
|
+
raise "poi_id required" unless poi_id
|
61
|
+
response = poi_api(poi_id, language)
|
62
|
+
_parse_poi_response(response)
|
63
|
+
end
|
64
|
+
|
65
|
+
def bluelists(keyword = nil, language = 'eng', count = 15, order = 'popular')
|
66
|
+
raise "keyword string required" unless keyword
|
67
|
+
response = bluelists_api(keyword, language, count, order)
|
68
|
+
_parse_bluelist_response(response)
|
69
|
+
end
|
70
|
+
|
71
|
+
def bluelist_items(bluelist_id = nil, language = 'eng', count = 5, order = 'popular' )
|
72
|
+
raise "bluelist_id required" unless bluelist_id
|
73
|
+
response = bluelist_items_api(bluelist_id, language, count, order)
|
74
|
+
|
75
|
+
# TODO, not fully implemented due to a rubbish example
|
76
|
+
end
|
77
|
+
|
78
|
+
def keyword_images(keyword = nil, language = 'eng', count = 5, order = 'title')
|
79
|
+
raise "keyword string required" unless keyword
|
80
|
+
response = images_api(keyword, language, count, order)
|
81
|
+
_parse_images_response(response)
|
82
|
+
end
|
83
|
+
|
84
|
+
def search(keyword = nil, types = '*', mode = 'mixed', language = 'eng', count = 5, order = 'popular')
|
85
|
+
raise "keyword string required" unless keyword
|
86
|
+
response = search_api(keyword, types, mode, language, count, order)
|
87
|
+
_parse_search_response(response)
|
88
|
+
end
|
89
|
+
|
90
|
+
def lpi(photographer = '*', location = '*', count = 5, keywords = nil, andor = nil)
|
91
|
+
response = search_api(photographer, location, count, keywords, andor)
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
# All API methods are implemented with this method. This method is
|
96
|
+
# like a remote method call, it encapsulates the request/response
|
97
|
+
# cycle to the remote host. It extracts the remote method API name
|
98
|
+
# based on the ruby method name.
|
99
|
+
def method_missing(method_id, *params)
|
100
|
+
_request(method_id.to_s.sub('_api', ''), *params)
|
101
|
+
end
|
102
|
+
|
103
|
+
def _request(method, *params)
|
104
|
+
url = _request_url(method, *params)
|
105
|
+
response = XmlSimple.xml_in(_http_get(url)) #, { 'ForceArray' => [ 'video', 'friend' ] }
|
106
|
+
# raise response['error']['description'] + " : url=#{url}" unless response['status'] == 'ok'
|
107
|
+
response
|
108
|
+
end
|
109
|
+
|
110
|
+
def _request_url(method, *params)
|
111
|
+
param_list = String.new
|
112
|
+
unless params.empty?
|
113
|
+
|
114
|
+
params.each { |v|
|
115
|
+
if v != nil # this technically isn't correct, as if some are nill, the order will mess up
|
116
|
+
param_list << "#{CGI.escape(v.to_s)}/"
|
117
|
+
end
|
118
|
+
}
|
119
|
+
end
|
120
|
+
url = "#{@host}#{@api_path}lps.#{method}/xml/#{@dev_id}/#{param_list}"
|
121
|
+
end
|
122
|
+
|
123
|
+
def _http_get(url)
|
124
|
+
Net::HTTP.get_response(URI.parse(url)).body.to_s
|
125
|
+
end
|
126
|
+
|
127
|
+
def _parse_destination_response(response)
|
128
|
+
Destination.new(response)
|
129
|
+
end
|
130
|
+
|
131
|
+
def _parse_proximity_pois_response(response)
|
132
|
+
pois = response['proximity_pois'][0]['poi']
|
133
|
+
pois.is_a?(Array)? pois.compact.map { |poi| Poi.new(poi) } : nil
|
134
|
+
end
|
135
|
+
|
136
|
+
def _parse_pois_response(response)
|
137
|
+
pois = response['destination_pois'][0]['poi']
|
138
|
+
pois.is_a?(Array)? pois.compact.map { |poi| Poi.new(poi) } : nil
|
139
|
+
end
|
140
|
+
|
141
|
+
def _parse_poi_response(response)
|
142
|
+
Poi.new(response)
|
143
|
+
end
|
144
|
+
|
145
|
+
def _parse_images_response(response)
|
146
|
+
images = response['images'][0]['image']
|
147
|
+
images.is_a?(Array)? images.compact.map { |image| Image.new(image) } : nil
|
148
|
+
end
|
149
|
+
|
150
|
+
def _parse_geotaxonomy_response(response)
|
151
|
+
# puts response.to_yaml
|
152
|
+
Geotaxonomy.new(response)
|
153
|
+
end
|
154
|
+
|
155
|
+
def _parse_bluelist_response(response)
|
156
|
+
bluelists = response['bluelists'][0]['bluelist']
|
157
|
+
bluelists.is_a?(Array)? bluelists.compact.map { |bluelist| Bluelist.new(bluelist) } : nil
|
158
|
+
end
|
159
|
+
|
160
|
+
def _parse_search_response(response)
|
161
|
+
items = response['all'][0]['item']
|
162
|
+
items.is_a?(Array)? items.compact.map { |item| Result.new(item) } : nil
|
163
|
+
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
class Geotaxonomy
|
168
|
+
attr_reader :name
|
169
|
+
attr_reader :destination_id
|
170
|
+
attr_reader :language
|
171
|
+
attr_reader :parents
|
172
|
+
|
173
|
+
def initialize(payload)
|
174
|
+
@name = payload['term'][0]['name'].to_s
|
175
|
+
@destination_id = payload['term'][0]['destination_id'].to_s
|
176
|
+
@language = payload['language'].to_s
|
177
|
+
@parents = payload['parents'][0]['parent'].compact.map { |parent| Parent.new(parent) }
|
178
|
+
end
|
179
|
+
|
180
|
+
class Parent
|
181
|
+
attr_reader :name
|
182
|
+
attr_reader :tid
|
183
|
+
def initialize(payload)
|
184
|
+
@name = payload['name'].to_s
|
185
|
+
@tid = payload['tid'].to_s
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
class Bluelist
|
191
|
+
attr_reader :title
|
192
|
+
attr_reader :votes
|
193
|
+
|
194
|
+
def initialize(payload)
|
195
|
+
@title = payload['title'].to_s
|
196
|
+
@votes = payload['votes'].to_i rescue 0 # they never write 0 for some reason.
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
class Destination
|
202
|
+
attr_reader :title
|
203
|
+
attr_reader :intro_mini
|
204
|
+
attr_reader :intro_short
|
205
|
+
attr_reader :intro_medium
|
206
|
+
attr_reader :history_modern
|
207
|
+
attr_reader :history_pre_c20
|
208
|
+
attr_reader :history_recent
|
209
|
+
attr_reader :weather
|
210
|
+
attr_reader :latitude
|
211
|
+
attr_reader :longitude
|
212
|
+
attr_reader :node_id
|
213
|
+
attr_reader :sleep
|
214
|
+
attr_reader :night
|
215
|
+
attr_reader :shop
|
216
|
+
attr_reader :see
|
217
|
+
attr_reader :eat
|
218
|
+
|
219
|
+
def initialize(payload)
|
220
|
+
@title = payload['title'].to_s
|
221
|
+
@intro_mini = payload['intro_mini'].to_s
|
222
|
+
@intro_short = payload['into_short'].to_s
|
223
|
+
@intro_medium = payload['intro_medium'].to_s
|
224
|
+
@history_modern = payload['history_modern'].to_s
|
225
|
+
@history_pre_c20 = payload['history_pre_c20'].to_s
|
226
|
+
@history_recent = payload['history_recent'].to_s
|
227
|
+
@weather = payload['weather'].to_s
|
228
|
+
@latitude = payload['latitude'].to_s
|
229
|
+
@longitude = payload['longitude'].to_s
|
230
|
+
@node_id = payload['node_id'].to_s
|
231
|
+
@sleep = payload['sleep'][0]
|
232
|
+
@night = payload['night'][0]
|
233
|
+
@shop = payload['shop'][0]
|
234
|
+
@see = payload['see'][0]
|
235
|
+
@eat = payload['eat'][0]
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
class Poi
|
240
|
+
attr_reader :title
|
241
|
+
attr_reader :address
|
242
|
+
attr_reader :neighbourhood
|
243
|
+
attr_reader :tags
|
244
|
+
attr_reader :node_id
|
245
|
+
attr_reader :distance
|
246
|
+
attr_reader :latitude
|
247
|
+
attr_reader :longitude
|
248
|
+
attr_reader :transport
|
249
|
+
|
250
|
+
def initialize(payload)
|
251
|
+
@title = payload['title'].to_s
|
252
|
+
@address = payload['address'].to_s
|
253
|
+
@neighbourhood = payload['neighbourhood'].to_s
|
254
|
+
@tags = payload['tags'].to_s
|
255
|
+
@node_id = payload['node_id'].to_s
|
256
|
+
@distance = payload['distance']
|
257
|
+
@latitude = payload['latitude']
|
258
|
+
@longitude = payload['longitude']
|
259
|
+
@transport = payload['transport']
|
260
|
+
@email = payload['email']
|
261
|
+
@website = payload['website']
|
262
|
+
@review_summary = payload['review_summary']
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
class Image
|
267
|
+
attr_reader :title
|
268
|
+
attr_reader :thumbnail
|
269
|
+
attr_reader :filepath
|
270
|
+
attr_reader :node_id
|
271
|
+
|
272
|
+
def initialize(payload)
|
273
|
+
@title = payload['title'].to_s
|
274
|
+
@thumbnail = payload['thumbnail'].to_s
|
275
|
+
@filepath = payload['filepath'].to_s
|
276
|
+
@node_id = payload['node_id'].to_s
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
class Result
|
281
|
+
attr_reader :title
|
282
|
+
attr_reader :destination_id
|
283
|
+
attr_reader :content_type
|
284
|
+
attr_reader :sub_type
|
285
|
+
attr_reader :node_id
|
286
|
+
def initialize(payload)
|
287
|
+
@title = payload['title'].to_s
|
288
|
+
@destination_id = payload['destination_id'].to_s.to_i
|
289
|
+
@content_type = payload['content_type'].to_s
|
290
|
+
@sub_type = payload['sub_type'].to_s
|
291
|
+
@node_id = payload['node_id'].to_i
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: andyshearer-lonely_planet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andy Shearer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-25 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: xml-simple
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
version:
|
24
|
+
description: A Ruby object-oriented interface to the Lonely Planet REST API.
|
25
|
+
email: andy@mibly.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- README.txt
|
38
|
+
- Rakefile
|
39
|
+
- lonelyplanet.gemspec
|
40
|
+
- ./lib/lonely_planet.rb
|
41
|
+
- ./test/test_lonely_planet.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://mibly.com
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --main
|
47
|
+
- README.txt
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.2.0
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: A Ruby object-oriented interface to the Lonely Planet REST API.
|
69
|
+
test_files:
|
70
|
+
- test/test_lonely_planet.rb
|