nestoria 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'json'
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.5.2"
14
+ gem "rcov", ">= 0"
15
+ end
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ json (1.4.6)
10
+ rake (0.8.7)
11
+ rcov (0.9.9)
12
+ shoulda (2.11.3)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.0.0)
19
+ jeweler (~> 1.5.2)
20
+ json
21
+ rcov
22
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Dan Wentworth
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,76 @@
1
+ Ruby Nestoria API Library
2
+ =========================
3
+
4
+ This is a simple library designed to facilitate the usage of the Nestoria API. The library supports all current Nestoria services, including:
5
+
6
+ * nestoria.com.au
7
+ * nestoria.com.br
8
+ * nestoria.de
9
+ * nestoria.es
10
+ * nestoria.fr
11
+ * nestoria.in
12
+ * nestoria.it
13
+ * nestoria.co.uk
14
+
15
+ Usage
16
+ =====
17
+
18
+ Initialize
19
+ ----------
20
+
21
+ To initialize the library call new with the TLD of Nestoria service you wish to use.
22
+
23
+ require 'nestoria/api'
24
+ Nestoria::Api.new(:uk)
25
+
26
+ Echo
27
+ ----
28
+
29
+ The echo command simply sends back any data you give it along with Nestoria's response headers:
30
+
31
+ Nestoria::Api.new(:uk).echo :foo => "bar"
32
+ # {"created_unix"=>1294588256, "encoding"=>"json", "action"=>"echo", "version"=>"1.19", "status_text"=>"OK", "status_code"=>"200", "foo"=>"bar", "sort"=>"nestoria_rank", "created_http"=>"Sun, 09 Jan 2011 15:50:56 GMT"}
33
+
34
+ Search
35
+ ------
36
+
37
+ To search Nestoria's property listings call Nestoria::Api#search along with a hash of parameters specifying the search values. The keys are the same as those listed on the Nestoria API site here: [http://www.nestoria.co.uk/help/api-search-listings](http://www.nestoria.co.uk/help/api-search-listings)
38
+
39
+ keywords and keywords\_exclude take an Array object instead of a comma separated list. updated\_min can take a Time object instead of a UNIX timestamp.
40
+
41
+ Nestoria::Api.new(:uk).search :listing_type => "buy", :place_name => "Wimborne", :keywords => ["off_street_parking", "unfurnished"]
42
+
43
+ You should receive a hash containing all the values in the Nestoria response, further details can be found on the link above.
44
+
45
+ Keywords
46
+ --------
47
+
48
+ For a list of valid keywords that can be used with the keywords and keywords\_exclude parameter in the search call Nestoria::Api#keywords. This will give you a set of keys and friendly names.
49
+
50
+ Nestoria::Api.new(:uk).keywords
51
+ # {"terrace"=>"Terrace", "studio"=>"Studio", "refurbished"=>"Refurbished", "patio"=>"Patio" ...
52
+
53
+ Metadata/Average House Prices
54
+ -----------------------------
55
+
56
+ There's also support for fetching the average house price information on an area, just use Nestoria::Api#metadata with a set of location parameters.
57
+
58
+ Nestoria::Api.new(:uk).metadata :south_west => [50.965, -5.504], :north_east => [50.156, -5.136]
59
+
60
+ Contributing to Nestoria API Library
61
+ ====================================
62
+
63
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
64
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
65
+ * Fork the project
66
+ * Start a feature/bugfix branch
67
+ * Commit and push until you are happy with your contribution
68
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
69
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
70
+
71
+ Copyright
72
+ =========
73
+
74
+ Copyright (c) 2011 Dan Wentworth. See LICENSE.txt for
75
+ further details.
76
+
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "nestoria"
16
+ gem.homepage = "http://github.com/darkphnx/nestoria"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{A simple library to interface with Nestoria's API}
19
+ gem.description = %Q{A simple library to interface with Nestoria's API, currently compatible with v1.19}
20
+ gem.email = "dan.wentworth@gmail.com"
21
+ gem.authors = ["Dan Wentworth"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ gem.add_runtime_dependency 'json'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "nestoria #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,123 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ # Easy url encoding of hashes
6
+ class Hash
7
+ def to_query
8
+ self.map{|k,v| "#{k}=#{v}"}.join("&")
9
+ end
10
+ end
11
+
12
+ module Nestoria
13
+
14
+ class BadLocation < StandardError; end
15
+ class InvalidRequest < StandardError; end
16
+ class InternalError < StandardError; end
17
+ class InvalidVersion < StandardError; end
18
+
19
+ class Api
20
+
21
+ API_VERSION = 1.19
22
+
23
+ # Valid search parameters - See http://www.nestoria.co.uk/help/api-search-listings for key/value details
24
+ LOCATION_KEYS = [ :place_name, :south_west, :north_east, :centre_point, :radius ]
25
+ SEARCH_KEYS = [ :guid, :listing_type, :property_type, :min_price, :max_price,
26
+ :bedroom_min, :bedroom_max, :room_min, :room_max, :bathroom_min, :bathroom_max,
27
+ :size_min, :size_max, :keywords, :keywords_exclude, :has_photo, :updated_min,
28
+ :number_of_results, :page, :sort ] + LOCATION_KEYS
29
+
30
+ def initialize(country)
31
+ @country = country
32
+ end
33
+
34
+ # Search nestoria property listings - See http://www.nestoria.co.uk/help/api-search-listings
35
+ def search(params)
36
+ invalid_keys = params.keys - SEARCH_KEYS
37
+ raise InvalidRequest.new "Invalid keys: #{invalid_keys.join(", ")}" unless invalid_keys.empty?
38
+
39
+ # Convert arrays into CSVs
40
+ [:keywords, :keywords_exclude].each do |key|
41
+ params[key] = params[key].join(",") unless params[key].nil?
42
+ end
43
+
44
+ # Convert any Time/DateTime objects to UNIX time integers
45
+ params[:updated_min] = params[:updated_min].to_i unless params[:updated_min].nil?
46
+
47
+ process_location! params
48
+
49
+ request :search_listings, params
50
+ end
51
+
52
+ # List of keywords that can be used in search - See http://www.nestoria.co.uk/help/api-keywords
53
+ def keywords
54
+ response = request :keywords
55
+ keywords = Hash.new
56
+ response["labels"].each do |label|
57
+ keywords[label["keyword"]] = label["content"]
58
+ end
59
+ keywords
60
+ end
61
+
62
+ # Average house price for an area - See http://www.nestoria.co.uk/help/api-metadata
63
+ def metadata(params)
64
+ invalid_keys = params.keys - LOCATION_KEYS
65
+ raise InvalidRequest.new "Invalid keys: #{invalid_keys.join(", ")}" unless invalid_keys.empty?
66
+
67
+ process_location! params
68
+
69
+ request :metadata, params
70
+ end
71
+
72
+ # Test URL request, returns whatever params you put in
73
+ def echo(params = {:foo => "bar"})
74
+ request :echo, params
75
+ end
76
+
77
+ private
78
+
79
+ def base_url
80
+ domains = {:au => "api.nestoria.com.au",
81
+ :br => "api.nestoria.com.br",
82
+ :de => "api.nestoria.de",
83
+ :es => "api.nestoria.es",
84
+ :fr => "api.nestoria.fr",
85
+ :in => "api.nestoria.in",
86
+ :it => "api.nestoria.it",
87
+ :uk => "api.nestoria.co.uk"}
88
+ "http://#{domains[@country]}/api"
89
+ end
90
+
91
+ def process_location!(params)
92
+ [:south_west, :north_east, :centre_point].each do |key|
93
+ params[key] = params[key].join(",") unless params[key].nil?
94
+ end
95
+ end
96
+
97
+ def request(action, params = {})
98
+ url = "#{base_url}?version=#{API_VERSION}&action=#{action}&encoding=json&#{params.to_query}"
99
+ puts url
100
+ res = Net::HTTP.get_response(URI.parse(url))
101
+ data = JSON.parse(res.body)
102
+
103
+ # Catch any errors returned from the API and raise an appropriate exception
104
+ if action.to_s == "search"
105
+ application_response_code = data["response"]["application_response_code"]
106
+ application_response_text = data["response"]["application_response_text"]
107
+ case application_response_code.to_i
108
+ when 200...299
109
+ raise BadLocation.new "#{application_response_code}, #{application_response_text}"
110
+ when 500
111
+ raise InternalError.new "#{application_response_code}, #{application_response_text}"
112
+ when 910...911
113
+ raise InvaidVersion.new "#{application_response_code}, #{application_response_text}"
114
+ when 900...999
115
+ raise InvalidRequest.new "#{application_response_code}, #{application_response_text}"
116
+ end
117
+ end
118
+
119
+ data["response"]
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{nestoria}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dan Wentworth"]
12
+ s.date = %q{2011-01-09}
13
+ s.description = %q{A simple library to interface with Nestoria's API, currently compatible with v1.19}
14
+ s.email = %q{dan.wentworth@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/nestoria/api.rb",
28
+ "nestoria.gemspec"
29
+ ]
30
+ s.homepage = %q{http://github.com/darkphnx/nestoria}
31
+ s.licenses = ["MIT"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.7}
34
+ s.summary = %q{A simple library to interface with Nestoria's API}
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<json>, [">= 0"])
42
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
43
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
44
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
45
+ s.add_development_dependency(%q<rcov>, [">= 0"])
46
+ s.add_runtime_dependency(%q<json>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<json>, [">= 0"])
49
+ s.add_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
52
+ s.add_dependency(%q<rcov>, [">= 0"])
53
+ s.add_dependency(%q<json>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<json>, [">= 0"])
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ s.add_dependency(%q<json>, [">= 0"])
62
+ end
63
+ end
64
+
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nestoria
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Dan Wentworth
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-09 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ name: json
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ type: :development
46
+ name: shoulda
47
+ prerelease: false
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ hash: 23
56
+ segments:
57
+ - 1
58
+ - 0
59
+ - 0
60
+ version: 1.0.0
61
+ type: :development
62
+ name: bundler
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ hash: 7
72
+ segments:
73
+ - 1
74
+ - 5
75
+ - 2
76
+ version: 1.5.2
77
+ type: :development
78
+ name: jeweler
79
+ prerelease: false
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :development
92
+ name: rcov
93
+ prerelease: false
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ type: :runtime
106
+ name: json
107
+ prerelease: false
108
+ version_requirements: *id006
109
+ description: A simple library to interface with Nestoria's API, currently compatible with v1.19
110
+ email: dan.wentworth@gmail.com
111
+ executables: []
112
+
113
+ extensions: []
114
+
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.md
118
+ files:
119
+ - .document
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - VERSION
126
+ - lib/nestoria/api.rb
127
+ - nestoria.gemspec
128
+ has_rdoc: true
129
+ homepage: http://github.com/darkphnx/nestoria
130
+ licenses:
131
+ - MIT
132
+ post_install_message:
133
+ rdoc_options: []
134
+
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ hash: 3
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ requirements: []
156
+
157
+ rubyforge_project:
158
+ rubygems_version: 1.3.7
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: A simple library to interface with Nestoria's API
162
+ test_files: []
163
+