iwannagothere 0.0.1
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.md +10 -0
- data/README.rdoc +0 -0
- data/examples/all_methods.rb +16 -0
- data/lib/core_ext/string.rb +9 -0
- data/lib/iwannagothere.rb +15 -0
- data/lib/iwannagothere/client.rb +39 -0
- data/lib/iwannagothere/element.rb +11 -0
- data/lib/iwannagothere/item.rb +13 -0
- data/lib/iwannagothere/item_route.rb +11 -0
- data/lib/iwannagothere/photo.rb +9 -0
- data/lib/iwannagothere/place.rb +22 -0
- data/lib/iwannagothere/urls.rb +28 -0
- data/lib/iwannagothere/user.rb +5 -0
- metadata +93 -0
data/README.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# iwannagothere #
|
2
|
+
Ruby wrapper for accessing places and guides information from the [iwannagothere](http://iwannagothere.com/ "iwannagothere") API.
|
3
|
+
|
4
|
+
## ToDo ##
|
5
|
+
* Problems whit single photo
|
6
|
+
* Implement some tests
|
7
|
+
* Make more DRY
|
8
|
+
|
9
|
+
## Copyright ##
|
10
|
+
Copyright (c) 2009 Jordi Villar, released under MIT license
|
data/README.rdoc
ADDED
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require '../lib/iwannagothere'
|
2
|
+
|
3
|
+
puts c = IWannaGoThere::Client.new('2a1d90dd2aafcae3a1ba3dd0a6cde6a8')
|
4
|
+
puts p = c.place_information('Barcelona')
|
5
|
+
puts p.items
|
6
|
+
puts p.photos
|
7
|
+
puts p.guides
|
8
|
+
|
9
|
+
puts c.user_information(1)
|
10
|
+
puts c.guide_information(120)
|
11
|
+
puts i = c.item_information(120)
|
12
|
+
r = c.item_information(6426)
|
13
|
+
puts r.photos
|
14
|
+
|
15
|
+
puts "Esto falla porque este item solo tiene una foto"
|
16
|
+
puts i.photos
|
@@ -0,0 +1,15 @@
|
|
1
|
+
%w{rubygems httparty}.each { |x| require x }
|
2
|
+
%w{string}.each{ |file| require File.join(File.dirname(__FILE__), 'core_ext', file) }
|
3
|
+
%w{element urls place photo item_route item user client}.each{ |file| require File.join(File.dirname(__FILE__), 'iwannagothere', file) }
|
4
|
+
|
5
|
+
module IWannaGoThere
|
6
|
+
def self.get(url, options = nil, new_options = nil)
|
7
|
+
options[:query].merge! new_options unless new_options.blank?
|
8
|
+
begin
|
9
|
+
HTTParty.get(url, options)
|
10
|
+
rescue Exception => e
|
11
|
+
puts e
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module IWannaGoThere
|
2
|
+
class Client
|
3
|
+
attr_reader :api_key, :urls, :options
|
4
|
+
|
5
|
+
def initialize(api_key)
|
6
|
+
@api_key = api_key
|
7
|
+
@urls = Urls.new
|
8
|
+
@options = { :query => { :key => @api_key } }
|
9
|
+
end
|
10
|
+
|
11
|
+
def user_information(id)
|
12
|
+
r = IWannaGoThere.get(@urls[:user_information].params({ :user_id => id }), @options)
|
13
|
+
User.new r['user'], @urls, @options
|
14
|
+
end
|
15
|
+
|
16
|
+
def place_information(q)
|
17
|
+
r = IWannaGoThere.get(@urls[:place_information].params({ :geoname_id => geoname_id(q) }), @options)
|
18
|
+
Place.new r['place'], @urls, @options
|
19
|
+
end
|
20
|
+
|
21
|
+
def item_information(id)
|
22
|
+
r = IWannaGoThere.get(@urls[:item_information].params({ :item_id => id }), @options)
|
23
|
+
Item.new r['item'], @urls, @options
|
24
|
+
end
|
25
|
+
|
26
|
+
def guide_information(id)
|
27
|
+
r = IWannaGoThere.get(@urls[:guide_information].params({ :route_id => id }), @options)
|
28
|
+
ItemRoute.new r['itemroute'], @urls, @options
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def geoname_id(q)
|
33
|
+
geo_options = { :query => { :name => q, :maxRows => "1" }}
|
34
|
+
r = IWannaGoThere.get(Urls::GEO_URL, geo_options)
|
35
|
+
r["geonames"]["geoname"]["geonameId"]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module IWannaGoThere
|
2
|
+
class Item < Element
|
3
|
+
attr_accessor :address, :created_at, :place_id, :popularity, :coolness, :delta, :title, :published,
|
4
|
+
:saved_count, :summercontest09, :updated_at, :highlighted_date, :url, :id, :reviewed,
|
5
|
+
:long_guid, :category_id, :user_id, :nicetitle, :description, :lat, :keywords, :long,
|
6
|
+
:map_id, :country_id, :itemroute_id, :item_id, :phone_number
|
7
|
+
|
8
|
+
def photos(size = 'square', limit = 10)
|
9
|
+
r = IWannaGoThere.get(@urls[:item_photos].params({ :item_id => @id || @item_id }), @options, { :limit => limit, :size => size })
|
10
|
+
r['pictures']['picture'].collect{ |p| Photo.new( p ) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module IWannaGoThere
|
2
|
+
class ItemRoute < Element
|
3
|
+
attr_accessor :name, :nicename, :items_count, :id, :description, :user_id,
|
4
|
+
:long_guid, :created_at, :updated_at, :delta, :from, :to, :meta
|
5
|
+
|
6
|
+
def items(limit = 10)
|
7
|
+
r = IWannaGoThere.get(@urls[:guide_items].params({ :route_id => @id }), @options, { :limit => limit })
|
8
|
+
r['items'].collect{ |p| Item.new( p, @urls, @options ) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module IWannaGoThere
|
2
|
+
class Place < Element
|
3
|
+
attr_accessor :country_id, :created_at, :delta, :geoname_id, :id, :items_count,
|
4
|
+
:lat, :long, :map_id, :name, :nicename, :updated_at, :long_guid,
|
5
|
+
:hierarchy, :alternative_names, :users_count, :meta
|
6
|
+
|
7
|
+
def photos(size = 'square', limit = 10)
|
8
|
+
r = IWannaGoThere.get(@urls[:place_photos].params({ :geoname_id => @geoname_id }), @options, { :limit => limit, :size => size })
|
9
|
+
r['pictures']['picture'].collect{ |p| Photo.new( p ) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def guides(limit = 10)
|
13
|
+
r = IWannaGoThere.get(@urls[:place_guides].params({ :geoname_id => @geoname_id }), @options, { :limit => limit })
|
14
|
+
r['itemroutes'].collect{ |p| ItemRoute.new( p, @urls, @options ) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def items(limit = 10)
|
18
|
+
r = IWannaGoThere.get(@urls[:place_items].params({ :geoname_id => @geoname_id }), @options, { :limit => limit })
|
19
|
+
r['items'].collect{ |p| Item.new( p, @urls, @options ) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module IWannaGoThere
|
2
|
+
class Urls
|
3
|
+
BASE_URL = "http://iwannagothere.com/api"
|
4
|
+
URLS = {
|
5
|
+
:categories => "/categories.xml",
|
6
|
+
:place_information => "/places/{{geoname_id}}",
|
7
|
+
:place_photos => "/places/{{geoname_id}}/get_photos",
|
8
|
+
:place_guides => "/places/{{geoname_id}}/get_routes",
|
9
|
+
:place_items => "/places/{{geoname_id}}/items",
|
10
|
+
:item_information => "/items/{{item_id}}",
|
11
|
+
:item_photos => "/items/{{item_id}}/get_photos",
|
12
|
+
:guide_information => "/routes/{{route_id}}",
|
13
|
+
:guide_items => "/routes/{{route_id}}/items",
|
14
|
+
:user_information => "/users/{{user_id}}"
|
15
|
+
}
|
16
|
+
GEO_URL = "http://ws.geonames.org/search"
|
17
|
+
|
18
|
+
attr_reader :urls
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@urls = URLS.inject({}){|object, (k,v)| object[k] = BASE_URL + v; object}
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](key)
|
25
|
+
@urls[key]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iwannagothere
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jordi Villar
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-20 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: httparty
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: "Ruby wrapper for iwannagothere API "
|
36
|
+
email: jrdi.villar@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.md
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- README.md
|
46
|
+
- examples/all_methods.rb
|
47
|
+
- lib/core_ext/string.rb
|
48
|
+
- lib/iwannagothere.rb
|
49
|
+
- lib/iwannagothere/client.rb
|
50
|
+
- lib/iwannagothere/element.rb
|
51
|
+
- lib/iwannagothere/item.rb
|
52
|
+
- lib/iwannagothere/item_route.rb
|
53
|
+
- lib/iwannagothere/photo.rb
|
54
|
+
- lib/iwannagothere/place.rb
|
55
|
+
- lib/iwannagothere/urls.rb
|
56
|
+
- lib/iwannagothere/user.rb
|
57
|
+
- README.rdoc
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: https://github.com/jrd/iwannagothere
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.7
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Ruby wrapper for iwannagothere API
|
92
|
+
test_files:
|
93
|
+
- examples/all_methods.rb
|