nyc_geo_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe NYCGeoClient::Client do
4
+
5
+ NYCGeoClient::Configuration::VALID_FORMATS.each do |format|
6
+ context ".new(:format => '#{format}')" do
7
+
8
+ before do
9
+ @client = NYCGeoClient::Client.new(app_id: 'ID', app_key: 'KEY', format: format)
10
+ end
11
+
12
+ describe ".address" do
13
+ before do
14
+ stub_get("address.#{format}").
15
+ with(
16
+ query: {
17
+ app_id: @client.app_id,
18
+ app_key: @client.app_key,
19
+ houseNumber: '13',
20
+ street: 'crosby',
21
+ borough: 'manhattan'
22
+ }).
23
+ to_return(body: fixture("address.#{format}"), headers: {content_type: "application/#{format}; charset=utf-8"})
24
+ end
25
+
26
+ it "should get the correct resource" do
27
+ @client.address('13', 'crosby', 'manhattan')
28
+ a_get("address.#{format}").
29
+ with(query: {
30
+ app_id: @client.app_id,
31
+ app_key: @client.app_key,
32
+ houseNumber: '13',
33
+ street: 'crosby',
34
+ borough: 'manhattan'
35
+ }).should have_been_made
36
+ end
37
+
38
+ it "should return the address info" do
39
+ data = @client.address('13', 'crosby', 'manhattan')
40
+ data.keys.should be == ["address"]
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe NYCGeoClient::Client do
4
+
5
+ NYCGeoClient::Configuration::VALID_FORMATS.each do |format|
6
+ context ".new(:format => '#{format}')" do
7
+
8
+ before do
9
+ @client = NYCGeoClient::Client.new(app_id: 'ID', app_key: 'KEY', format: format)
10
+ end
11
+
12
+ describe ".bbl" do
13
+ before do
14
+ stub_get("bbl.#{format}").
15
+ with(
16
+ query: {
17
+ app_id: @client.app_id,
18
+ app_key: @client.app_key,
19
+ borough: 'manhattan',
20
+ block: '00233',
21
+ lot: '0004',
22
+ }).
23
+ to_return(body: fixture("bbl.#{format}"), headers: {content_type: "application/#{format}; charset=utf-8"})
24
+ end
25
+
26
+ it "should get the correct resource" do
27
+ @client.bbl('manhattan', '00233', '0004')
28
+ a_get("bbl.#{format}").
29
+ with(query: {
30
+ app_id: @client.app_id,
31
+ app_key: @client.app_key,
32
+ borough: 'manhattan',
33
+ block: '00233',
34
+ lot: '0004',
35
+ }).should have_been_made
36
+ end
37
+
38
+ it "should return the bbl info" do
39
+ data = @client.bbl('manhattan', '00233', '0004')
40
+ data.keys.should be == ["bbl"]
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe NYCGeoClient::Client do
4
+
5
+ NYCGeoClient::Configuration::VALID_FORMATS.each do |format|
6
+ context ".new(:format => '#{format}')" do
7
+
8
+ before do
9
+ @client = NYCGeoClient::Client.new(app_id: 'ID', app_key: 'KEY', format: format)
10
+ end
11
+
12
+ describe ".bin" do
13
+ before do
14
+ stub_get("bin.#{format}").
15
+ with(
16
+ query: {
17
+ app_id: @client.app_id,
18
+ app_key: @client.app_key,
19
+ bin: '1003041',
20
+ }).
21
+ to_return(body: fixture("bin.#{format}"), headers: {content_type: "application/#{format}; charset=utf-8"})
22
+ end
23
+
24
+ it "should get the correct resource" do
25
+ @client.bin('1003041')
26
+ a_get("bin.#{format}").
27
+ with(query: {
28
+ app_id: @client.app_id,
29
+ app_key: @client.app_key,
30
+ bin: '1003041',
31
+ }).should have_been_made
32
+ end
33
+
34
+ it "should return the bin info" do
35
+ data = @client.bin('1003041')
36
+ data.keys.should be == ["bin"]
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe NYCGeoClient::Client do
4
+
5
+ NYCGeoClient::Configuration::VALID_FORMATS.each do |format|
6
+ context ".new(:format => '#{format}')" do
7
+
8
+ before do
9
+ @client = NYCGeoClient::Client.new(app_id: 'ID', app_key: 'KEY', format: format)
10
+ end
11
+
12
+ describe ".blockface" do
13
+ before do
14
+ stub_get("blockface.#{format}").
15
+ with(
16
+ query: {
17
+ app_id: @client.app_id,
18
+ app_key: @client.app_key,
19
+ onStreet: '34 st',
20
+ crossStreetOne: 'fifth ave',
21
+ crossStreetTwo: 'sixth ave',
22
+ borough: 'manhattan',
23
+ compassDirection: 'north'
24
+ }).
25
+ to_return(body: fixture("blockface.#{format}"), headers: {content_type: "application/#{format}; charset=utf-8"})
26
+ end
27
+
28
+ it "should get the correct resource" do
29
+ @client.blockface('34 st', 'fifth ave', 'sixth ave', 'manhattan', {compassDirection: 'north'})
30
+ a_get("blockface.#{format}").
31
+ with(query: {
32
+ app_id: @client.app_id,
33
+ app_key: @client.app_key,
34
+ onStreet: '34 st',
35
+ crossStreetOne: 'fifth ave',
36
+ crossStreetTwo: 'sixth ave',
37
+ borough: 'manhattan',
38
+ compassDirection: 'north'
39
+ }).should have_been_made
40
+ end
41
+
42
+ it "should return the blockface info" do
43
+ data = @client.blockface('34 st', 'fifth ave', 'sixth ave', 'manhattan', {compassDirection: 'north'})
44
+ data.keys.should be == ["blockface"]
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe NYCGeoClient::Client do
4
+
5
+ NYCGeoClient::Configuration::VALID_FORMATS.each do |format|
6
+ context ".new(:format => '#{format}')" do
7
+
8
+ before do
9
+ @client = NYCGeoClient::Client.new(app_id: 'ID', app_key: 'KEY', format: format)
10
+ end
11
+
12
+ describe ".intersection" do
13
+ before do
14
+ stub_get("intersection.#{format}").
15
+ with(
16
+ query: {
17
+ app_id: @client.app_id,
18
+ app_key: @client.app_key,
19
+ crossStreetOne: '34 st',
20
+ crossStreetTwo: 'fifth ave',
21
+ borough: 'manhattan',
22
+ compassDirection: 'north'
23
+ }).
24
+ to_return(body: fixture("intersection.#{format}"), headers: {content_type: "application/#{format}; charset=utf-8"})
25
+ end
26
+
27
+ it "should get the correct resource" do
28
+ @client.intersection('34 st', 'fifth ave', 'manhattan', {compassDirection: 'north'})
29
+ a_get("intersection.#{format}").
30
+ with(query: {
31
+ app_id: @client.app_id,
32
+ app_key: @client.app_key,
33
+ crossStreetOne: '34 st',
34
+ crossStreetTwo: 'fifth ave',
35
+ borough: 'manhattan',
36
+ compassDirection: 'north'
37
+ }).should have_been_made
38
+ end
39
+
40
+ it "should return the intersection info" do
41
+ data = @client.intersection('34 st', 'fifth ave', 'manhattan', {compassDirection: 'north'})
42
+ data.keys.should be == ["intersection"]
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe NYCGeoClient::Client do
4
+
5
+ NYCGeoClient::Configuration::VALID_FORMATS.each do |format|
6
+ context ".new(:format => '#{format}')" do
7
+
8
+ before do
9
+ @client = NYCGeoClient::Client.new(app_id: 'ID', app_key: 'KEY', format: format)
10
+ end
11
+
12
+ describe ".place" do
13
+ before do
14
+ stub_get("place.#{format}").
15
+ with(
16
+ query: {
17
+ app_id: @client.app_id,
18
+ app_key: @client.app_key,
19
+ name: 'empire state building',
20
+ borough: 'manhattan'
21
+ }).
22
+ to_return(body: fixture("place.#{format}"), headers: {content_type: "application/#{format}; charset=utf-8"})
23
+ end
24
+
25
+ it "should get the correct resource" do
26
+ @client.place('empire state building', 'manhattan')
27
+ a_get("place.#{format}").
28
+ with(query: {
29
+ app_id: @client.app_id,
30
+ app_key: @client.app_key,
31
+ name: 'empire state building',
32
+ borough: 'manhattan'
33
+ }).should have_been_made
34
+ end
35
+
36
+ it "should return the place info" do
37
+ data = @client.place('empire state building', 'manhattan')
38
+ data.keys.should be == ["place"]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe NYCGeoClient::Client do
4
+ it "should connect using the endpoint configuration" do
5
+ client = NYCGeoClient::Client.new
6
+ endpoint = URI.parse(client.endpoint)
7
+ connection = client.send(:connection).build_url(nil).to_s
8
+ (connection + '/').should == endpoint.to_s
9
+ end
10
+
11
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe NYCGeoClient do
4
+ after do
5
+ NYCGeoClient.reset
6
+ end
7
+
8
+ context "when delegating to a client" do
9
+
10
+ before do
11
+ stub_get("address.json").
12
+ with(
13
+ query: {
14
+ houseNumber: '13',
15
+ street: 'crosby',
16
+ borough: 'manhattan'
17
+ }).
18
+ to_return(body: fixture("address.json"), headers: {content_type: "application/json; charset=utf-8"})
19
+ end
20
+
21
+ it "should get the correct resource" do
22
+ NYCGeoClient.address('13', 'crosby', 'manhattan')
23
+ a_get("address.json").
24
+ with(query: {
25
+ houseNumber: '13',
26
+ street: 'crosby',
27
+ borough: 'manhattan'
28
+ }).should have_been_made
29
+ end
30
+
31
+ it "should return the same results as a client" do
32
+ NYCGeoClient.address('13', 'crosby', 'manhattan').should == NYCGeoClient::Client.new.address('13', 'crosby', 'manhattan')
33
+ end
34
+
35
+ end
36
+
37
+ describe ".client" do
38
+ it "should be a NYCGeoClient::Client" do
39
+ NYCGeoClient.client.should be_a NYCGeoClient::Client
40
+ end
41
+ end
42
+
43
+ describe ".adapter" do
44
+ it "should return the default adapter" do
45
+ NYCGeoClient.adapter.should == NYCGeoClient::Configuration::DEFAULT_ADAPTER
46
+ end
47
+ end
48
+
49
+ describe ".adapter=" do
50
+ it "should set the adapter" do
51
+ NYCGeoClient.adapter = :typhoeus
52
+ NYCGeoClient.adapter.should == :typhoeus
53
+ end
54
+ end
55
+
56
+ describe ".endpoint" do
57
+ it "should return the default endpoint" do
58
+ NYCGeoClient.endpoint.should == NYCGeoClient::Configuration::DEFAULT_ENDPOINT
59
+ end
60
+ end
61
+
62
+ describe ".endpoint=" do
63
+ it "should set the endpoint" do
64
+ NYCGeoClient.endpoint = 'http://tumblr.com'
65
+ NYCGeoClient.endpoint.should == 'http://tumblr.com'
66
+ end
67
+ end
68
+
69
+ describe ".format" do
70
+ it "should return the default format" do
71
+ NYCGeoClient.format.should == NYCGeoClient::Configuration::DEFAULT_FORMAT
72
+ end
73
+ end
74
+
75
+ describe ".format=" do
76
+ it "should set the format" do
77
+ NYCGeoClient.format = 'xml'
78
+ NYCGeoClient.format.should == 'xml'
79
+ end
80
+ end
81
+
82
+ describe ".user_agent" do
83
+ it "should return the default user agent" do
84
+ NYCGeoClient.user_agent.should == NYCGeoClient::Configuration::DEFAULT_USER_AGENT
85
+ end
86
+ end
87
+
88
+ describe ".user_agent=" do
89
+ it "should set the user_agent" do
90
+ NYCGeoClient.user_agent = 'Custom User Agent'
91
+ NYCGeoClient.user_agent.should == 'Custom User Agent'
92
+ end
93
+ end
94
+
95
+ describe ".configure" do
96
+
97
+ NYCGeoClient::Configuration::VALID_OPTIONS_KEYS.each do |key|
98
+
99
+ it "should set the #{key}" do
100
+ NYCGeoClient.configure do |config|
101
+ config.send("#{key}=", key)
102
+ NYCGeoClient.send(key).should == key
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ end
@@ -0,0 +1,51 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'nyc_geo_client'
3
+ require 'rspec'
4
+ require 'webmock/rspec'
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+ config.include WebMock::API
11
+ end
12
+
13
+ def a_delete(path)
14
+ a_request(:delete, NYCGeoClient.endpoint + path)
15
+ end
16
+
17
+ def a_get(path)
18
+ a_request(:get, NYCGeoClient.endpoint + path)
19
+ end
20
+
21
+ def a_post(path)
22
+ a_request(:post, NYCGeoClient.endpoint + path)
23
+ end
24
+
25
+ def a_put(path)
26
+ a_request(:put, NYCGeoClient.endpoint + path)
27
+ end
28
+
29
+ def stub_delete(path)
30
+ stub_request(:delete, NYCGeoClient.endpoint + path)
31
+ end
32
+
33
+ def stub_get(path)
34
+ stub_request(:get, NYCGeoClient.endpoint + path)
35
+ end
36
+
37
+ def stub_post(path)
38
+ stub_request(:post, NYCGeoClient.endpoint + path)
39
+ end
40
+
41
+ def stub_put(path)
42
+ stub_request(:put, NYCGeoClient.endpoint + path)
43
+ end
44
+
45
+ def fixture_path
46
+ File.expand_path("../fixtures", __FILE__)
47
+ end
48
+
49
+ def fixture(file)
50
+ File.new(fixture_path + '/' + file)
51
+ end