zipcodeservices 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mjg3MzkyOTBlMzZkNGE4Y2NhZTgzZmIzZTRlZWMwY2FjMTZhZjNiMg==
4
+ MjI5MDFjZTFmMzRmODg5OGVmNzk3YmVhODI5NTJkYTNkMmVkODdkNg==
5
5
  data.tar.gz: !binary |-
6
- YTE5ZGVlNzUwZTQ1ZTNlMjJkNzY5OTEzYzIyNmVjZmViOTM1MGEzYw==
6
+ ZWNhZmE2YWIyMGM5ZTM1YjlkNDU4NDEyNWZiNjhhMGRjNDJlMjI2NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDE4ZTNkYjA0ZmM5ZjUxZDJmNjQ1NGQ0ODU1ZjcyZjA2ZTQwYTI5YTc2OWM2
10
- ODg5MjVhMjgzNmY1ZjA3YmY4YmY4YmQwNjc2MGM4ZjdkMGM5NGJkYjE5ZTZi
11
- YjMzZjBlZTg4N2RmODg3ZjZkNjJkNTQyNGJhYjk2OWIzOWJjNmM=
9
+ MjZiZTBiNzlmZTE3NzBkMDAxMjkyMTE1MDM3ZTcyOTc1YzgwOThhMmM4MThm
10
+ ODM0MmE3ODFmNWI3MDE2ZDg2MTJkMzY3YjAzMmMwMzBhOTE0ZjAwNzVmYmIy
11
+ ZDMxMjkyNDE2MzZmMmE1MTczNTdhNGQ3ZjZlNmNlZDMyZTlkZTI=
12
12
  data.tar.gz: !binary |-
13
- Y2NkMGM3NmVlNmEzOGI1NjEwYmMzZGMyOWRkYjNmZTM0YmY2MjBmNjFmZDQ2
14
- MGU5NzE1MmRjY2U2YzU4NzAwOTYxYTNiZjJiNzRkZDgxMGRiODZjMjRmN2Ri
15
- NmU4ZTMzNzFkMWQ4OTFlZTEzMjJjOWFiZjdmMzg4ZWU3OWZhNTk=
13
+ YThlYTg4NWQ3MWI1MTlhNjc1YjBkNTdmNmJiZWU3ZGRiOTEzOGQyNDI4NjIx
14
+ OGQwZjUwODVlYzk3MjRmYzUwNmVmYTg0ODZkN2MzYmUzMTE5ZDZlODY2OWRh
15
+ ZjNhZjI5ZDZiM2RkZTEyMmU3OGQwYzViM2FlZjRkY2Y0MjAzMWU=
data/.gitignore ADDED
@@ -0,0 +1,32 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # br operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ *.rbc
8
+ *.sassc
9
+ .sass-cache
10
+ capybara-*.html
11
+ .rspec
12
+ /.bundle
13
+ /vendor/bundle
14
+ /log/*
15
+ /tmp/*
16
+ /db/*.sqlite3
17
+ /public/system/*
18
+ /coverage/
19
+ /spec/tmp/*
20
+ **.orig
21
+ rerun.txt
22
+ pickle-email-*.html
23
+ *_Store
24
+ /.rvmrc
25
+ /.ruby-gemset
26
+ coverage
27
+ config/database.yml
28
+ /public/uploads
29
+ .*.swp
30
+ .env
31
+ *.gem
32
+ /spec/vcr_cassettes/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in aislefinder.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ zipcodeservices (0.0.1)
5
+ typhoeus (= 0.3.3)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ celluloid (0.15.2)
11
+ timers (~> 1.1.0)
12
+ celluloid-io (0.15.0)
13
+ celluloid (>= 0.15.0)
14
+ nio4r (>= 0.5.0)
15
+ coderay (1.1.0)
16
+ columnize (0.8.9)
17
+ debugger (1.6.6)
18
+ columnize (>= 0.3.1)
19
+ debugger-linecache (~> 1.2.0)
20
+ debugger-ruby_core_source (~> 1.3.2)
21
+ debugger-linecache (1.2.0)
22
+ debugger-ruby_core_source (1.3.2)
23
+ diff-lcs (1.2.5)
24
+ ffi (1.9.3)
25
+ formatador (0.2.4)
26
+ guard (2.6.0)
27
+ formatador (>= 0.2.4)
28
+ listen (~> 2.7)
29
+ lumberjack (~> 1.0)
30
+ pry (>= 0.9.12)
31
+ thor (>= 0.18.1)
32
+ guard-rspec (4.2.8)
33
+ guard (~> 2.1)
34
+ rspec (>= 2.14, < 4.0)
35
+ listen (2.7.4)
36
+ celluloid (>= 0.15.2)
37
+ celluloid-io (>= 0.15.0)
38
+ rb-fsevent (>= 0.9.3)
39
+ rb-inotify (>= 0.9)
40
+ lumberjack (1.0.5)
41
+ method_source (0.8.2)
42
+ mime-types (2.2)
43
+ nio4r (1.0.0)
44
+ pry (0.9.12.6)
45
+ coderay (~> 1.0)
46
+ method_source (~> 0.8)
47
+ slop (~> 3.4)
48
+ rb-fsevent (0.9.4)
49
+ rb-inotify (0.9.4)
50
+ ffi (>= 0.5.0)
51
+ rspec (2.14.1)
52
+ rspec-core (~> 2.14.0)
53
+ rspec-expectations (~> 2.14.0)
54
+ rspec-mocks (~> 2.14.0)
55
+ rspec-core (2.14.8)
56
+ rspec-expectations (2.14.5)
57
+ diff-lcs (>= 1.1.3, < 2.0)
58
+ rspec-mocks (2.14.6)
59
+ slop (3.5.0)
60
+ thor (0.19.1)
61
+ timers (1.1.0)
62
+ typhoeus (0.3.3)
63
+ mime-types
64
+ vcr (2.2.4)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ debugger
71
+ guard-rspec
72
+ rspec (~> 2.13)
73
+ vcr
74
+ zipcodeservices!
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
@@ -0,0 +1,3 @@
1
+ module ZipCodeServices
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,130 @@
1
+ # Require the necessary files
2
+ %w[
3
+ rubygems
4
+ typhoeus
5
+ ].each { |r| require r }
6
+
7
+ module ZipCodeServices
8
+ @base_uri = 'https://www.zipcodeservices.com/services/rest/json' #/zipcodes.svc'
9
+
10
+ class << self;
11
+ #attr_accessor :base_uri
12
+ attr_accessor :apikey
13
+
14
+ def zipcode(zip)
15
+ #/{apikey}/{zipcode}
16
+ response = Typhoeus::Request.get( "#{@base_uri}/zipcodes.svc/#{apikey}/#{zip}")
17
+ if response.code == 200
18
+ j = JSON::parse(response.body)
19
+ raise "BAD API KEY" if j.first[1]["City"] == nil
20
+ j
21
+ elsif response.code == 404
22
+ nil
23
+ else
24
+ raise response.body
25
+ end
26
+ end
27
+
28
+ def radius(zip, rad)
29
+ #/{apikey}/{zipcode}
30
+ response = Typhoeus::Request.get( "#{@base_uri}/zipcodes.svc/#{apikey}/#{zip}/#{rad}")
31
+ if response.code == 200
32
+ j = JSON::parse(response.body)
33
+ raise "BAD API KEY" if j["RetrieveZipCodesInRadiusResult"] == nil
34
+ j
35
+ elsif response.code == 404
36
+ nil
37
+ else
38
+ raise response.body
39
+ end
40
+ end
41
+
42
+ def radius_by_latlong(lat, long, rad)
43
+ #/{apikey}/{zipcode}
44
+ response = Typhoeus::Request.get( "#{@base_uri}/zipcodes.svc/GetZipCodesInRadiusLatLong?apikey=#{apikey}&latitude=#{lat}&longitude=#{lon}&radius=#{rad}")
45
+ if response.code == 200
46
+ j = JSON::parse(response.body)
47
+ raise "BAD API KEY" if j["GetZipCodesInRadiusOfLatLongResult"] == nil
48
+ j
49
+ elsif response.code == 404
50
+ nil
51
+ else
52
+ raise response.body
53
+ end
54
+ end
55
+
56
+ def distance_between_zipcodes(zip1, zip2)
57
+ #/{apikey}/{zipcode}
58
+ response = Typhoeus::Request.get( "#{@base_uri}/zipcodes.svc/GetDistanceBetweenZipCodes?apikey=#{apikey}&zipcode1=#{zip1}&zipcode2=#{zip2}")
59
+ if response.code == 200
60
+ j = JSON::parse(response.body)
61
+ raise "BAD API KEY" if j.first[1]["ZipCode1"] == nil
62
+ j
63
+ elsif response.code == 404
64
+ nil
65
+ else
66
+ raise response.body
67
+ end
68
+ end
69
+
70
+ def countries
71
+ #/{apikey}/{zipcode}
72
+ response = Typhoeus::Request.get( "#{@base_uri}/countries.svc/#{apikey}")
73
+ if response.code == 200
74
+ j = JSON::parse(response.body)
75
+ raise "BAD API KEY" if j["GetCountriesResult"] == nil
76
+ j
77
+ elsif response.code == 404
78
+ nil
79
+ else
80
+ raise response.body
81
+ end
82
+ end
83
+
84
+ def states(country_id)
85
+ #/{apikey}/{zipcode}
86
+ response = Typhoeus::Request.get( "#{@base_uri}/provinces.svc/#{apikey}/#{country_id}")
87
+ if response.code == 200
88
+ j = JSON::parse(response.body)
89
+ raise "BAD API KEY" if j["GetAllProvincesByCountryIdResult"] == nil
90
+ j
91
+ elsif response.code == 404
92
+ nil
93
+ else
94
+ raise response.body
95
+ end
96
+ end
97
+ alias :provinces :states
98
+
99
+ def cities(province_id)
100
+ #/{apikey}/{zipcode}
101
+ response = Typhoeus::Request.get( "#{@base_uri}/cities.svc/#{apikey}/#{province_id}")
102
+ if response.code == 200
103
+ j = JSON::parse(response.body)
104
+ raise "BAD API KEY" if j["GetCitiesByProvinceResult"] == nil
105
+ j
106
+ elsif response.code == 404
107
+ nil
108
+ else
109
+ raise response.body
110
+ end
111
+ end
112
+
113
+ def cities_by_state_and_country(province_id, country_id)
114
+ #/{apikey}/{zipcode}
115
+ response = Typhoeus::Request.get( "#{@base_uri}/cities.svc/#{apikey}/#{province_id}/#{country_id}")
116
+ if response.code == 200
117
+ j = JSON::parse(response.body)
118
+ raise "BAD API KEY" if j["GetCitiesByProvinceAndCountryResult"] == nil # NOTE: also happens when a province id is not valid for a country
119
+ j
120
+ elsif response.code == 404
121
+ nil
122
+ else
123
+ raise response.body
124
+ end
125
+ end
126
+
127
+
128
+ end
129
+ end
130
+
@@ -0,0 +1,52 @@
1
+ require 'zipcodeservices'
2
+ require 'spec_helper'
3
+
4
+ describe "client" do
5
+
6
+ before(:each) do
7
+ ZipCodeServices.apikey = 'YOUR_API_KEY_HERE'
8
+ end
9
+
10
+ it "should retrieve zip code info", :vcr, record: :new_episodes do
11
+ zips = ZipCodeServices.zipcode("78702")
12
+ zips.first[1]["City"].should == "Austin"
13
+ # test other item
14
+ end
15
+
16
+ it "should get zip codes in radius of zip code", :vcr, record: :new_episodes do
17
+ zips = ZipCodeServices.radius(78702, 1)
18
+ zips.first[1].first["PostalCode"].should == "78701"
19
+ end
20
+
21
+ it "should get zip codes in radius of latitude and longitude", :vcr, record: :new_episodes do
22
+ zips = ZipCodeServices.radius_by_latlong("30.2645715", "-97.7284341", 1)
23
+ zips.first[1].first["PostalCode"].should == "73301"
24
+ end
25
+
26
+ it "should get the distance between zip codes", :vcr, record: :new_episodes do
27
+ zips = ZipCodeServices.distance_between_zipcodes("78702", "01109")
28
+ zips.first[1]["DistanceAwayInMiles"].should == 1616.501295
29
+ end
30
+
31
+
32
+ it "should get countries", :vcr, record: :new_episodes do
33
+ countries = ZipCodeServices.countries
34
+ countries.first[1].first["Abbreviation"].should == "US"
35
+ end
36
+
37
+ it "should get states / provinces by country id (country id attained by request to countries list)", :vcr, record: :new_episodes do
38
+ states = ZipCodeServices.states(1)
39
+ states.first[1].first["Abbreviation"].should == "AL"
40
+ end
41
+
42
+ it "should get cities by province id / provinces id (country id attained by request to states list)", :vcr, record: :new_episodes do
43
+ cities = ZipCodeServices.cities(200)
44
+ cities.first[1].first["City"].should == "Alamo"
45
+ end
46
+
47
+ it "should get cities by state id (provinces id) and country id (country id attained by request for country list, province id attained by request for states list)", :vcr, record: :new_episodes do
48
+ cities = ZipCodeServices.cities_by_state_and_country(1, 1)
49
+ cities.first[1][20]["City"].should == "Arlington"
50
+ end
51
+
52
+ end
@@ -0,0 +1,76 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ #require 'webmock/rspec'
4
+
5
+ VCR.configure do |c|
6
+ c.allow_http_connections_when_no_cassette = true
7
+ c.cassette_library_dir = 'spec/vcr_cassettes'
8
+ c.hook_into :typhoeus
9
+ end
10
+
11
+ RSpec.configure do |config|
12
+
13
+
14
+ config.mock_with :rspec
15
+
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.around(:each, :vcr) do |example|
18
+ #name = example.metadata[:full_description].split(/\s+/, 2).join("/").underscore.gsub(/[^\w\/]+/, "_")
19
+ name = example.metadata[:full_description].split(/\s+/, 2).join("/").downcase.gsub(/\s+/,"_")
20
+ #options = example.metadata.slice(:record, :match_requests_on).except(:example_group)
21
+ options = example.metadata.reduce({}){ |acc, x| [:record,:match_requests_on].include?(x[0]) ? acc.merge({x[0] => x[1]}) : acc }
22
+ VCR.use_cassette(name, options) { example.call }
23
+ #VCR.use_cassette(name) { example.call }
24
+ end
25
+
26
+ # Use color in STDOUT
27
+ config.color_enabled = true
28
+
29
+ # Use color not only in STDOUT but also in pagers and files
30
+ config.tty = true
31
+
32
+ # Use the specified formatter
33
+ config.formatter = :documentation # :progress, :html, :textmate
34
+
35
+ #WebMock.disable_net_connect!(:allow => 'coveralls.io')
36
+
37
+ #RSpec.configure do |config|
38
+ # config.expect_with :rspec do |c|
39
+ # c.syntax = :expect
40
+ # end
41
+ #end
42
+
43
+ #def a_delete(path)
44
+ # a_request(:delete, ZipCodeServices::base_uri + path)
45
+ #end
46
+
47
+ #def a_get(path)
48
+ # a_request(:get, ZipCodeServices::base_uri + path)
49
+ #end
50
+
51
+ #def a_post(path)
52
+ # a_request(:post, ZipCodeServices::base_uri + path)
53
+ #end
54
+
55
+ #def a_put(path)
56
+ # a_request(:put, ZipCodeServices::base_uri + path)
57
+ #end
58
+
59
+ #def stub_delete(path)
60
+ # stup_request(:delete, ZipCodeServices::base_uri + path)
61
+ #end
62
+
63
+ #def stub_get(path)
64
+ # stup_request(:get, ZipCodeServices::base_uri + path)
65
+ #end
66
+
67
+ #def stub_post(path)
68
+ # stup_request(:post, ZipCodeServices::base_uri + path)
69
+ #end
70
+
71
+ #def stub_put(path)
72
+ # stup_request(:put, ZipCodeServices::base_uri + path)
73
+ #end
74
+
75
+
76
+ end
@@ -0,0 +1,8 @@
1
+ VCR.configure do |c|
2
+ # temporarily allows calls to go directly to facebook
3
+ #c.ignore_hosts 'facebook.com', 'graph.facebook.com'
4
+
5
+ c.cassette_library_dir = Rails.root.join("spec", "vcr")
6
+ #c.hook_into :fakeweb
7
+ c.hook_into :typheous
8
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "zipcodeservices/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'zipcodeservices'
7
+ s.version = ZipCodeServices::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.date = '2014-05-06'
10
+ s.summary = "zipcodeservices for zipcodeservices.com"
11
+ s.description = "Ruby Client for zipcodeservices.com. Gives ip address and radius queries. Visit zipcodeservices.com for more details"
12
+ s.authors = ["W Watson", "T Carpenter"]
13
+ s.email = 'wolfpack@vulk.com'
14
+ s.files = ["lib/zipcodeservices.rb"]
15
+ s.homepage = 'http://rubygems.org/gems/zipcodeservices'
16
+ s.license = 'MIT'
17
+ s.required_ruby_version = '>= 1.9.3'
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_development_dependency 'rspec', ["~> 2.13"]
24
+ s.add_development_dependency 'vcr'
25
+ s.add_development_dependency 'guard-rspec'
26
+ s.add_development_dependency 'debugger'
27
+
28
+ s.add_runtime_dependency "typhoeus", "0.3.3"
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipcodeservices
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - W Watson
@@ -26,7 +26,7 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '2.13'
28
28
  - !ruby/object:Gem::Dependency
29
- name: webmock
29
+ name: vcr
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ! '>='
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - ! '>='
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: debugger
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: typhoeus
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -73,7 +87,17 @@ email: wolfpack@vulk.com
73
87
  executables: []
74
88
  extensions: []
75
89
  extra_rdoc_files: []
76
- files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - Guardfile
95
+ - lib/zipcodeservices.rb
96
+ - lib/zipcodeservices/version.rb
97
+ - spec/client_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/support/vcr_setup.rb
100
+ - zipcodeservices.gemspec
77
101
  homepage: http://rubygems.org/gems/zipcodeservices
78
102
  licenses:
79
103
  - MIT
@@ -98,4 +122,7 @@ rubygems_version: 2.2.2
98
122
  signing_key:
99
123
  specification_version: 4
100
124
  summary: zipcodeservices for zipcodeservices.com
101
- test_files: []
125
+ test_files:
126
+ - spec/client_spec.rb
127
+ - spec/spec_helper.rb
128
+ - spec/support/vcr_setup.rb