nyc_geo_client 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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +9 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE +22 -0
  6. data/README.md +81 -0
  7. data/Rakefile +30 -0
  8. data/lib/faraday/raise_http_exception.rb +26 -0
  9. data/lib/nyc_geo_client.rb +26 -0
  10. data/lib/nyc_geo_client/api.rb +21 -0
  11. data/lib/nyc_geo_client/client.rb +13 -0
  12. data/lib/nyc_geo_client/client/address.rb +34 -0
  13. data/lib/nyc_geo_client/client/bbl.rb +31 -0
  14. data/lib/nyc_geo_client/client/bin.rb +27 -0
  15. data/lib/nyc_geo_client/client/blockface.rb +37 -0
  16. data/lib/nyc_geo_client/client/intersection.rb +34 -0
  17. data/lib/nyc_geo_client/client/place.rb +29 -0
  18. data/lib/nyc_geo_client/configuration.rb +84 -0
  19. data/lib/nyc_geo_client/connection.rb +30 -0
  20. data/lib/nyc_geo_client/error.rb +12 -0
  21. data/lib/nyc_geo_client/request.rb +59 -0
  22. data/lib/nyc_geo_client/version.rb +3 -0
  23. data/nyc_geo_client.gemspec +28 -0
  24. data/spec/faraday/response_spec.rb +43 -0
  25. data/spec/fixtures/address.json +142 -0
  26. data/spec/fixtures/address.xml +142 -0
  27. data/spec/fixtures/authentication_failed +1 -0
  28. data/spec/fixtures/bbl.json +45 -0
  29. data/spec/fixtures/bbl.xml +45 -0
  30. data/spec/fixtures/bin.json +43 -0
  31. data/spec/fixtures/bin.xml +43 -0
  32. data/spec/fixtures/blockface.json +99 -0
  33. data/spec/fixtures/blockface.xml +99 -0
  34. data/spec/fixtures/intersection.json +69 -0
  35. data/spec/fixtures/intersection.xml +69 -0
  36. data/spec/fixtures/place.json +177 -0
  37. data/spec/fixtures/place.xml +177 -0
  38. data/spec/nyc_geo_client/api_spec.rb +67 -0
  39. data/spec/nyc_geo_client/client/address_spec.rb +45 -0
  40. data/spec/nyc_geo_client/client/bbl_spec.rb +45 -0
  41. data/spec/nyc_geo_client/client/bin_spec.rb +41 -0
  42. data/spec/nyc_geo_client/client/blockface_spec.rb +49 -0
  43. data/spec/nyc_geo_client/client/intersection_spec.rb +47 -0
  44. data/spec/nyc_geo_client/client/place_spec.rb +43 -0
  45. data/spec/nyc_geo_client/client_spec.rb +11 -0
  46. data/spec/nyc_geo_client_spec.rb +108 -0
  47. data/spec/spec_helper.rb +51 -0
  48. metadata +254 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 00aa43b9e742e2fd169a884a4acbc6d79f749d27
4
+ data.tar.gz: 38a637417667ae915ec8bc510bcfd1d30d551956
5
+ SHA512:
6
+ metadata.gz: 97a2bf6058b91ff52f9ffbb33b520a20aedd375ebb3dbd6612a41fa055b8b0130ae1f8ccabe3587cc0651e44ec59ea7e716492f193bb0312d3771c1ee67a834a
7
+ data.tar.gz: 620488b63ee0dc625f267124be32347e407e4f516296c544a48c6a815b3634cf6ca48185d5efb687657598ed2d30893c87ceba8c31b4cd8272b96a50420804c4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .ruby-version
3
+ .ruby-gemset
4
+ Gemfile.lock
5
+ .DS_Store
6
+ # YARD artifacts
7
+ .yardoc
8
+ _yardoc
9
+ doc/
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ matrix:
3
+ allow_failures:
4
+ - rvm: ruby-head
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - 2.1.0
9
+ - ruby-head
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Edgar Gonzalez
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # NYCGeoClient [![Build Status](https://travis-ci.org/edgar/NYCGeoClient.png?branch=master)](https://travis-ci.org/edgar/NYCGeoClient)
2
+ A ruby gem for the NYC GeoClient API - https://developer.cityofnewyork.us/api/geoclient-api-beta
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'nyc_geo_client'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install nyc_geo_client
17
+
18
+
19
+ *NOTE:* You will need to register an application with the [NYC Developer Portal](https://developer.cityofnewyork.us/), and make sure that you check off access to the Geoclient API for the application. Take note of the Application's ID and key.
20
+
21
+ ## API Usage Examples
22
+
23
+ require "rubygems"
24
+ require "nyc_geo_client"
25
+
26
+ client = NYCGeoClient::Client.new(app_id: 'ID', app_key: 'KEY')
27
+
28
+ # get block and property level information about an address
29
+ client.address('13', 'crosby', 'manhattan')
30
+
31
+ # property level information about a tax lot
32
+ client.bbl('manhattan', '00233', '0004')
33
+
34
+ # get property level information about a building
35
+ client.bin('1003041')
36
+
37
+ # get information about a segment defined by an on street between two cross-streets
38
+ client.blockface('34 st', 'fifth ave', 'sixth ave', 'manhattan')
39
+
40
+ # get information about a point defined by two cross streets
41
+ client.intersection('34 st', 'fifth ave', 'manhattan')
42
+
43
+ # get address information using a well-known place name
44
+ client.place('empire state building', 'manhattan')
45
+
46
+
47
+ For more information about the data returned by every method please check the specs folder
48
+
49
+ ## Configuration
50
+
51
+ Because NYCGeoClient gem is based on [Faraday](https://github.com/lostisland/faraday), it supports the following adapters:
52
+
53
+ * Net::HTTP (default)
54
+ * [Excon](https://github.com/geemus/excon)
55
+ * [Typhoeus](https://github.com/typhoeus/typhoeus)
56
+ * [Patron](http://toland.github.com/patron/)
57
+ * [EventMachine](https://github.com/igrigorik/em-http-request)
58
+
59
+ Beside the adapter, you can change the following properties:
60
+
61
+ * endpoint
62
+ * format
63
+ * user_agent
64
+ * proxy
65
+ * debug
66
+
67
+ For instance:
68
+
69
+ require 'typhoeus/adapters/faraday' # You will need the typhoeus gem
70
+
71
+ client = NYCGeoClient.client(adapter: :typhoeus, user_agent: "foobar v1", debug: true, app_id: 'foo', app_key: 'bar')
72
+ client.address('13','crosby','manhattan')
73
+
74
+
75
+ ## Contributing
76
+
77
+ 1. Fork it
78
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
79
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
80
+ 4. Push to the branch (`git push origin my-new-feature`)
81
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
6
+ task :default => :spec
7
+ task :test => :spec
8
+
9
+ namespace :doc do
10
+ begin
11
+ require 'yard'
12
+ rescue LoadError
13
+ # ignore
14
+ else
15
+ YARD::Rake::YardocTask.new do |task|
16
+ task.files = ['lib/**/*.rb']
17
+ task.options = [
18
+ '--protected',
19
+ '--output-dir', 'doc/yard',
20
+ '--tag', 'format:Supported formats',
21
+ '--markup', 'markdown',
22
+ ]
23
+ end
24
+ end
25
+ end
26
+
27
+ desc "Open an irb session preloaded with this library"
28
+ task :console do
29
+ sh "irb -rubygems -I lib -r nyc_geo_client.rb"
30
+ end
@@ -0,0 +1,26 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module FaradayMiddleware
5
+ # @private
6
+ class RaiseHttpException < Faraday::Middleware
7
+ def call(env)
8
+ @app.call(env).on_complete do |response|
9
+ if [403, 500, 503].include? response[:status].to_i
10
+ raise NYCGeoClient::Error.new(error_message(response), response[:status].to_i)
11
+ end
12
+ end
13
+ end
14
+
15
+ def initialize(app)
16
+ super app
17
+ @parser = nil
18
+ end
19
+
20
+ private
21
+
22
+ def error_message(response)
23
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s, response[:body]].compact.join(': ')}"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../nyc_geo_client/error', __FILE__)
2
+ require File.expand_path('../nyc_geo_client/configuration', __FILE__)
3
+ require File.expand_path('../nyc_geo_client/api', __FILE__)
4
+ require File.expand_path('../nyc_geo_client/client', __FILE__)
5
+
6
+ module NYCGeoClient
7
+ extend Configuration
8
+
9
+ # Alias for NYCGeoClient::Client.new
10
+ #
11
+ # @return [NYCGeoClient::Client]
12
+ def self.client(options={})
13
+ NYCGeoClient::Client.new(options)
14
+ end
15
+
16
+ # Delegate to NYCGeoClient::Client
17
+ def self.method_missing(method, *args, &block)
18
+ return super unless client.respond_to?(method)
19
+ client.send(method, *args, &block)
20
+ end
21
+
22
+ # Delegate to NYCGeoClient::Client
23
+ def self.respond_to?(method)
24
+ return client.respond_to?(method) || super
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../connection', __FILE__)
2
+ require File.expand_path('../request', __FILE__)
3
+
4
+ module NYCGeoClient
5
+ # @private
6
+ class API
7
+ # @private
8
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
9
+
10
+ # Creates a new API
11
+ def initialize(options={})
12
+ options = NYCGeoClient.options.merge(options)
13
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
14
+ send("#{key}=", options[key])
15
+ end
16
+ end
17
+
18
+ include Connection
19
+ include Request
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module NYCGeoClient
2
+ class Client < API
3
+
4
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
5
+
6
+ include NYCGeoClient::Client::Address
7
+ include NYCGeoClient::Client::BBL
8
+ include NYCGeoClient::Client::BIN
9
+ include NYCGeoClient::Client::Blockface
10
+ include NYCGeoClient::Client::Intersection
11
+ include NYCGeoClient::Client::Place
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ module NYCGeoClient
2
+ class Client
3
+ # Defines methods related to branches
4
+ module Address
5
+
6
+ # Returns block and property level information about an address.
7
+ #
8
+ # Results will include X/Y coordinates, political, city service
9
+ # and property information as well as normalized street names and codes.
10
+ #
11
+ # @param house_number [String] The house number portion of the address
12
+ # @param street [String] The street portion of the address
13
+ # @param borough [String] The borough in which the address is located
14
+ # @return [Hashie::Mash]
15
+ # @example block and property level information about an address
16
+ # NYCGeoClient.address('13', 'crosby', 'manhattan')
17
+ # @format :json, :xml
18
+ def address(house_number, street, borough)
19
+ options = {
20
+ houseNumber: house_number,
21
+ street: street,
22
+ borough: borough
23
+ }
24
+ get(address_path, options)
25
+ end
26
+
27
+ protected
28
+
29
+ def address_path
30
+ "address"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ module NYCGeoClient
2
+ class Client
3
+ # Defines methods related to branches
4
+ module BBL
5
+
6
+ # Returns property level information about a tax lot.
7
+ #
8
+ # @param borough [String] The borough in which the address is located
9
+ # @param block [String] Tax block number
10
+ # @param lot [String] Tax lot number
11
+ # @return [Hashie::Mash]
12
+ # @example property level information about a tax lot
13
+ # NYCGeoClient.bbl('manhattan','00233', '0004')
14
+ # @format :json, :xml
15
+ def bbl(borough, block, lot)
16
+ options = {
17
+ block: block,
18
+ lot: lot,
19
+ borough: borough
20
+ }
21
+ get(bbl_path, options)
22
+ end
23
+
24
+ protected
25
+
26
+ def bbl_path
27
+ "bbl"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ module NYCGeoClient
2
+ class Client
3
+ # Defines methods related to branches
4
+ module BIN
5
+
6
+ # Returns property level information about a building.
7
+ #
8
+ # @param bin [String] The bin in which the address is located
9
+ # @return [Hashie::Mash]
10
+ # @example property level information about a building
11
+ # NYCGeoClient.bin('1003041')
12
+ # @format :json, :xml
13
+ def bin(bin)
14
+ options = {
15
+ bin: bin
16
+ }
17
+ get(bin_path, options)
18
+ end
19
+
20
+ protected
21
+
22
+ def bin_path
23
+ "bin"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ module NYCGeoClient
2
+ class Client
3
+ # Defines methods related to branches
4
+ module Blockface
5
+
6
+ # Returns information about a segment defined by an on street between two cross-streets.
7
+ #
8
+ # @param on_street [String] The street on which the segment is found
9
+ # @param cross_street_one [String] The first cross street
10
+ # @param cross_street_two [String] The second cross street
11
+ # @param borough [String] The borough in which the on_street is located
12
+ # @param extra [Hash] optional params:
13
+ # - boroughCrossStreetOne: The borough in which the cross_street_one is located if it differs from the borough parameter
14
+ # - boroughCrossStreetTwo: The borough in which the cross_street_two is located if it differs from the borough parameter
15
+ # - compassDirection: Used when requesting information about only one side of the street (north, south, west, east, n, s, w, e)
16
+ # @return [Hashie::Mash]
17
+ # @example information about a segment defined by an on street between two cross-streets
18
+ # NYCGeoClient.blockface('34 st', 'fifht ave', 'sixth ave', 'manhattan')
19
+ # @format :json, :xml
20
+ def blockface(on_street, cross_street_one, cross_street_two, borough, extra = {})
21
+ options = {
22
+ onStreet: on_street,
23
+ crossStreetOne: cross_street_one,
24
+ crossStreetTwo: cross_street_two,
25
+ borough: borough
26
+ }.merge(extra)
27
+ get(blockface_path, options)
28
+ end
29
+
30
+ protected
31
+
32
+ def blockface_path
33
+ "blockface"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,34 @@
1
+ module NYCGeoClient
2
+ class Client
3
+ # Defines methods related to branches
4
+ module Intersection
5
+
6
+ # Returns information about a point defined by two cross streets.
7
+ #
8
+ # @param cross_street_one [String] The first cross street
9
+ # @param cross_street_two [String] The second cross street
10
+ # @param borough [String] The borough in which the on_street is located
11
+ # @param extra [Hash] optional params:
12
+ # - boroughCrossStreetTwo: The borough in which the cross_street_two is located if it differs from the borough parameter
13
+ # - compassDirection: Used when requesting information about only one side of the street (north, south, west, east, n, s, w, e)
14
+ # @return [Hashie::Mash]
15
+ # @example information about a segment defined by an on street between two cross-streets
16
+ # NYCGeoClient.blockface('34 st', 'fifht ave', 'manhattan')
17
+ # @format :json, :xml
18
+ def intersection(cross_street_one, cross_street_two, borough, extra = {})
19
+ options = {
20
+ crossStreetOne: cross_street_one,
21
+ crossStreetTwo: cross_street_two,
22
+ borough: borough
23
+ }.merge(extra)
24
+ get(intersection_path, options)
25
+ end
26
+
27
+ protected
28
+
29
+ def intersection_path
30
+ "intersection"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ module NYCGeoClient
2
+ class Client
3
+ # Defines methods related to branches
4
+ module Place
5
+
6
+ # Returns address information using a well-known place name as input.
7
+ #
8
+ # @param name [String] A well-known New York City place name
9
+ # @param borough [String] The borough in which the place is located
10
+ # @return [Hashie::Mash]
11
+ # @example address information using a well-known place name
12
+ # NYCGeoClient.place('empire state building')
13
+ # @format :json, :xml
14
+ def place(name, borough)
15
+ options = {
16
+ name: name,
17
+ borough: borough
18
+ }
19
+ get(place_path, options)
20
+ end
21
+
22
+ protected
23
+
24
+ def place_path
25
+ "place"
26
+ end
27
+ end
28
+ end
29
+ end