atlas_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in atlas_client.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "atlas_client/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "atlas_client"
7
+ s.version = AtlasClient::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Chris Aitchison"]
10
+ s.email = ["chris.aitchison@lonelyplanet.com.au"]
11
+ s.homepage = "http://www.lonelyplanet.com"
12
+ s.summary = %q{A client for the Atlas API}
13
+ s.description = %q{A client for the Atlas API}
14
+
15
+ s.rubyforge_project = "atlas_client"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,11 @@
1
+ require 'atlas_client/json_object'
2
+ require 'atlas_client/reviews'
3
+ require 'atlas_client/telephone'
4
+ require 'atlas_client/practicalities'
5
+ require 'atlas_client/property'
6
+ require 'atlas_client/address'
7
+ require 'atlas_client/place'
8
+ require 'atlas_client/poi'
9
+ require 'atlas_client/finder'
10
+ require 'atlas_client/place_finder'
11
+ require 'atlas_client/poi_finder'
@@ -0,0 +1,4 @@
1
+ module AtlasClient
2
+ class Address < JsonObject
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module AtlasClient
2
+ class Finder
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ def self.get_json url
7
+ response = Net::HTTP.get URI.parse(url)
8
+ JSON.parse response
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module AtlasClient
2
+ class JsonObject
3
+ def initialize json
4
+ json = json.to_json if json.class == Hash
5
+ json = JSON.parse json if json.class == String
6
+ @json = json
7
+ end
8
+
9
+ def method_missing(name, *args, &block)
10
+ @json[name.to_s]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module AtlasClient
2
+ class Place
3
+ require 'json'
4
+
5
+ def initialize json
6
+ @json = json
7
+ end
8
+
9
+ def method_missing(name, *args, &block)
10
+ @json[name.to_s]
11
+ end
12
+
13
+ def pois
14
+ @pois ||= PoiFinder.find_by_place_id id
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module AtlasClient
2
+ class PlaceFinder < Finder
3
+ require 'json'
4
+
5
+ @places_url = "http://lposfusion.load.lpo/places?"
6
+
7
+ def self.find_by_id id
8
+ query("where[id]=#{id}").first
9
+ end
10
+
11
+ def self.query query_string
12
+ json = get_json @places_url+query_string+"&limit=999999"
13
+ places = []
14
+ json['places'].collect do |place_json|
15
+ Place.new(place_json)
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,40 @@
1
+ module AtlasClient
2
+ class POI < JsonObject
3
+
4
+ def reviews
5
+ @reviews ||= Reviews.new @json['reviews'][0]
6
+ end
7
+
8
+ def telephones
9
+ return @telephones if @telephones
10
+ @telephones = @json['telephones'].collect do |telephone|
11
+ Telephone.new telephone
12
+ end
13
+ end
14
+
15
+ def properties
16
+ return @properties if @properties
17
+ @properties = @json['properties'].collect do |property|
18
+ Property.new property
19
+ end
20
+ end
21
+
22
+ def addresses
23
+ return @addresses if @addresses
24
+ @addresses = @json['addresses'].collect do |address|
25
+ Address.new address
26
+ end
27
+ end
28
+
29
+ def practicalities
30
+ @practicalities ||= Practicalities.new @json['practicalities'][0]
31
+ end
32
+
33
+ def place
34
+ return @place if @place
35
+ place_id = place_ancestry_ids.split("~").last
36
+ @place = PlaceFinder.find_by_id place_id
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+ module AtlasClient
2
+ class PoiFinder < Finder
3
+ require 'json'
4
+
5
+ @pois_url = "http://lposfusion.load.lpo/pois?"
6
+
7
+ def self.find_by_place_id place_id
8
+ query "where[place]=#{place_id}"
9
+ end
10
+
11
+ def self.find_by_id id
12
+ query("where[id]=#{id}").first
13
+ end
14
+
15
+ def self.query query_string
16
+ json = get_json @pois_url+query_string+"&limit=999999"
17
+ pois = []
18
+ json['pois'].collect do |poi_json|
19
+ POI.new(poi_json)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ module AtlasClient
2
+ class Practicalities < JsonObject
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module AtlasClient
2
+ class Property < JsonObject
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ module AtlasClient
2
+ class Reviews < JsonObject
3
+
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module AtlasClient
2
+ class Telephone < JsonObject
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module AtlasClient
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atlas_client
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Chris Aitchison
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-27 00:00:00 +10:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: A client for the Atlas API
18
+ email:
19
+ - chris.aitchison@lonelyplanet.com.au
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - Gemfile
29
+ - Rakefile
30
+ - atlas_client.gemspec
31
+ - lib/atlas_client.rb
32
+ - lib/atlas_client/address.rb
33
+ - lib/atlas_client/finder.rb
34
+ - lib/atlas_client/json_object.rb
35
+ - lib/atlas_client/place.rb
36
+ - lib/atlas_client/place_finder.rb
37
+ - lib/atlas_client/poi.rb
38
+ - lib/atlas_client/poi_finder.rb
39
+ - lib/atlas_client/practicalities.rb
40
+ - lib/atlas_client/property.rb
41
+ - lib/atlas_client/reviews.rb
42
+ - lib/atlas_client/telephone.rb
43
+ - lib/atlas_client/version.rb
44
+ has_rdoc: true
45
+ homepage: http://www.lonelyplanet.com
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: atlas_client
68
+ rubygems_version: 1.5.0
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: A client for the Atlas API
72
+ test_files: []
73
+