Class: Lonelyplanet::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/lonely_planet.rb

Overview

Main client class managing all interaction with the YouTube server. Server communication is handled via method_missing() emulating an RPC-like call and performing all of the work to send out the HTTP request and retrieve the XML response. Inspired by the Flickr interface by Scott Raymond <redgreenblu.com/flickr/>. This in turn was insperation from the youtube gem by Shane Vitarana

Instance Method Summary collapse

Constructor Details

#initialize(dev_id = nil, host = DEFAULT_HOST, api_path = DEFAULT_API_PATH) ⇒ Client

Returns a new instance of Client.



22
23
24
25
26
27
# File 'lib/lonely_planet.rb', line 22

def initialize(dev_id = nil, host = DEFAULT_HOST, api_path = DEFAULT_API_PATH)
  raise "developer id required" unless dev_id
  @dev_id = dev_id
  @host = host
  @api_path = api_path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *params) ⇒ Object (private)

All API methods are implemented with this method. This method is like a remote method call, it encapsulates the request/response cycle to the remote host. It extracts the remote method API name based on the ruby method name.



99
100
101
# File 'lib/lonely_planet.rb', line 99

def method_missing(method_id, *params)
  _request(method_id.to_s.sub('_api', ''), *params)
end

Instance Method Details

#bluelist_items(bluelist_id = nil, language = 'eng', count = 5, order = 'popular') ⇒ Object



71
72
73
74
75
76
# File 'lib/lonely_planet.rb', line 71

def bluelist_items(bluelist_id = nil, language = 'eng', count = 5, order = 'popular' )
  raise "bluelist_id required" unless bluelist_id
  response = bluelist_items_api(bluelist_id, language, count, order)
  
  # TODO, not fully implemented due to a rubbish example
end

#bluelists(keyword = nil, language = 'eng', count = 15, order = 'popular') ⇒ Object



65
66
67
68
69
# File 'lib/lonely_planet.rb', line 65

def bluelists(keyword = nil, language = 'eng', count = 15, order = 'popular')
  raise "keyword string required" unless keyword
  response = bluelists_api(keyword, language, count, order)
  _parse_bluelist_response(response)
end

#destination(destination = nil, language = 'eng', erm = 'false') ⇒ Object



35
36
37
38
39
40
# File 'lib/lonely_planet.rb', line 35

def destination(destination = nil, language = 'eng', erm = 'false')
   raise "destination string required" unless destination
   response = destination_api(destination, language, erm)
    _parse_destination_response(response)
   # puts "http://api.lonelyplanet.com/services/get/lps.destination/xml/#{@dev_id}"
end

#destination_pois(destination = nil, activity = '*', language = 'eng', count = 5) ⇒ Object



42
43
44
45
46
# File 'lib/lonely_planet.rb', line 42

def destination_pois(destination = nil, activity = '*', language = 'eng', count = 5)
    raise "destination string required" unless destination
    response = destination_pois_api(destination, activity, language, count)
    _parse_pois_response(response)
end

#geotree(destination = nil, language = 'eng', hide_empty = 'false', id_type = 'description') ⇒ Object



29
30
31
32
33
# File 'lib/lonely_planet.rb', line 29

def geotree(destination = nil, language = 'eng', hide_empty = 'false', id_type = 'description')
  raise "destination string required" unless destination
    response = geotree_api(destination, language, hide_empty, id_type)
    _parse_geotaxonomy_response(response)
end

#keyword_images(keyword = nil, language = 'eng', count = 5, order = 'title') ⇒ Object



78
79
80
81
82
# File 'lib/lonely_planet.rb', line 78

def keyword_images(keyword = nil, language = 'eng', count = 5, order = 'title')
  raise "keyword string required" unless keyword
  response = images_api(keyword, language, count, order)
  _parse_images_response(response)
end

#lpi(photographer = '*', location = '*', count = 5, keywords = nil, andor = nil) ⇒ Object



90
91
92
# File 'lib/lonely_planet.rb', line 90

def lpi(photographer = '*', location = '*', count = 5, keywords = nil, andor = nil)
  response = search_api(photographer, location, count, keywords, andor)
end

#poi(poi_id = nil, language = 'eng') ⇒ Object



59
60
61
62
63
# File 'lib/lonely_planet.rb', line 59

def poi(poi_id = nil, language = 'eng')
    raise "poi_id required" unless poi_id
    response = poi_api(poi_id, language)
    _parse_poi_response(response)
end

#proximity_pois(latitude = nil, longitude = nil, poi = '*', activity = 'see', radius = '5', language = 'eng', count = 5) ⇒ Object



54
55
56
57
# File 'lib/lonely_planet.rb', line 54

def proximity_pois(latitude = nil, longitude = nil, poi = '*', activity = 'see', radius = '5', language = 'eng', count = 5)
    response = proximity_pois_api(latitude, longitude, poi, activity, radius, language, count)
    _parse_proximity_pois_response(response)
end

#search(keyword = nil, types = '*', mode = 'mixed', language = 'eng', count = 5, order = 'popular') ⇒ Object



84
85
86
87
88
# File 'lib/lonely_planet.rb', line 84

def search(keyword = nil, types = '*', mode = 'mixed', language = 'eng', count = 5, order = 'popular')
  raise "keyword string required" unless keyword
  response = search_api(keyword, types, mode, language, count, order)
  _parse_search_response(response)
end

#tagged_pois(destination = nil, tag = nil, language = 'eng', count = 5) ⇒ Object



48
49
50
51
52
# File 'lib/lonely_planet.rb', line 48

def tagged_pois(destination = nil, tag = nil, language = 'eng', count = 5)
    raise "destination string and tag required" unless destination and tag
    response = tagged_pois_api(destination, tag, language, count)
    _parse_pois_response(response)
end