zipcodeservices 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjI5MDFjZTFmMzRmODg5OGVmNzk3YmVhODI5NTJkYTNkMmVkODdkNg==
4
+ MmE3MWYxNzU4NWIyNTdkMzJiNzYzYzNhZjNmNDA0ZjMxYzc0ZTQ5ZQ==
5
5
  data.tar.gz: !binary |-
6
- ZWNhZmE2YWIyMGM5ZTM1YjlkNDU4NDEyNWZiNjhhMGRjNDJlMjI2NQ==
6
+ ZDQ4MzM5OTEzYTNkOGU1ZjdlMjU3MmY0ODg4ZjYzOGExZDlhMzE3Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjZiZTBiNzlmZTE3NzBkMDAxMjkyMTE1MDM3ZTcyOTc1YzgwOThhMmM4MThm
10
- ODM0MmE3ODFmNWI3MDE2ZDg2MTJkMzY3YjAzMmMwMzBhOTE0ZjAwNzVmYmIy
11
- ZDMxMjkyNDE2MzZmMmE1MTczNTdhNGQ3ZjZlNmNlZDMyZTlkZTI=
9
+ ZDJiYWU0N2EwYTFiZGZkMzhiYTQ1NDk0YjVhY2YzOTQ4ZTJlYWQ5ZTBlMmYx
10
+ NTc1M2NhNWI5NDBhYjlmZThjNjM1MDM5YTRhOTU4Mzg5MDkyYWQ0NDdhOTk5
11
+ ZDI3OTY2YjM0MjA1MGY0YjBhNWFkZmM4NzAwMDIxMjBkNzQzMGU=
12
12
  data.tar.gz: !binary |-
13
- YThlYTg4NWQ3MWI1MTlhNjc1YjBkNTdmNmJiZWU3ZGRiOTEzOGQyNDI4NjIx
14
- OGQwZjUwODVlYzk3MjRmYzUwNmVmYTg0ODZkN2MzYmUzMTE5ZDZlODY2OWRh
15
- ZjNhZjI5ZDZiM2RkZTEyMmU3OGQwYzViM2FlZjRkY2Y0MjAzMWU=
13
+ YzA5NzY0YjkwNmUzZTU0YWExOGU5NWUzZTAyZWZhOGIzMzA0NmU5Y2JjMDMy
14
+ YTcwMjkyYWY0ZGI1YWJhZmY2ZTE2MjI0NGVhNzM3NGVhN2M1M2ZhZjFkMmRm
15
+ MzczODQ5NmUwNDk1NDE2M2Y3MmQ3NGU2MjRjZDRmZjQzM2ViYmI=
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ export ZIP_CODE_SERVICES_API_KEY="YOUR API KEY HERE"
data/.gitignore CHANGED
@@ -11,6 +11,7 @@ capybara-*.html
11
11
  .rspec
12
12
  /.bundle
13
13
  /vendor/bundle
14
+ /vendor/*
14
15
  /log/*
15
16
  /tmp/*
16
17
  /db/*.sqlite3
@@ -27,6 +28,8 @@ coverage
27
28
  config/database.yml
28
29
  /public/uploads
29
30
  .*.swp
31
+ .*.swo
30
32
  .env
31
33
  *.gem
32
34
  /spec/vcr_cassettes/*
35
+ /tags
data/Gemfile.lock CHANGED
@@ -2,6 +2,8 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  zipcodeservices (0.0.1)
5
+ multi_xml
6
+ nokogiri
5
7
  typhoeus (= 0.3.3)
6
8
 
7
9
  GEM
@@ -40,7 +42,11 @@ GEM
40
42
  lumberjack (1.0.5)
41
43
  method_source (0.8.2)
42
44
  mime-types (2.2)
45
+ mini_portile (0.5.3)
46
+ multi_xml (0.5.5)
43
47
  nio4r (1.0.0)
48
+ nokogiri (1.6.1)
49
+ mini_portile (~> 0.5.0)
44
50
  pry (0.9.12.6)
45
51
  coderay (~> 1.0)
46
52
  method_source (~> 0.8)
@@ -61,7 +67,7 @@ GEM
61
67
  timers (1.1.0)
62
68
  typhoeus (0.3.3)
63
69
  mime-types
64
- vcr (2.2.4)
70
+ vcr (2.9.2)
65
71
 
66
72
  PLATFORMS
67
73
  ruby
@@ -70,5 +76,5 @@ DEPENDENCIES
70
76
  debugger
71
77
  guard-rspec
72
78
  rspec (~> 2.13)
73
- vcr
79
+ vcr (~> 2.4)
74
80
  zipcodeservices!
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ Zipcode Services.
2
+ =================
3
+
4
+ This is a ruby library that interfaces Zip Code Services -- a IP Address and Zip Code database with Zip Code Distance Search and IP Address Distance Search APIs available to members.
5
+
6
+ ---
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ gem install zipcodeservices
12
+ ```
13
+
14
+ Use
15
+ ```
16
+ ZipCodeServices.apikey = ENV['ZIP_CODE_SERVICES_API_KEY']
17
+ ZipCodeServices.data_format = :json
18
+ zips = ZipCodeServices.zipcode("78702")
19
+ ```
20
+
21
+ ## Contribution
22
+
23
+ Installation for contributors
24
+
25
+ 1. Get an api key from zipcodeservices.com
26
+ 2. Fork the repo
27
+ 3. Add the API key as the environment variable ZIP_CODE_SERVICES_API_KEY
28
+ - Linux:
29
+ * First -- add ```ZIP_CODE_SERVICES_API_KEY=YOUR_KEY``` to .env
30
+ * Next -- Type ```. .env``` before running any tests
31
+ - Windows: Add your environment variables using the following instructions: http://www.computerhope.com/issues/ch000549.htm
32
+ 4. Ensure all tests pass by running ```rspec spec```
33
+ 5. Submit a pull request with your changes
34
+
35
+ Please write tests for any changes you make or we will have our way with you
36
+
37
+
38
+
data/foo.xml ADDED
@@ -0,0 +1 @@
1
+ <GetAllProvincesByCountryIdResponse xmlns="http://tempuri.org/"><GetAllProvincesByCountryIdResult xmlns:a="http://schemas.datacontract.org/2004/07/Zips.DTO" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><a:StateDTO><a:Abbreviation>AL</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>1</a:Id><a:State>Alabama</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>AK</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>2</a:Id><a:State>Alaska</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>AS</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>3</a:Id><a:State>American Samoa</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>AZ</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>4</a:Id><a:State>Arizona</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>AR</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>5</a:Id><a:State>Arkansas</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>CA</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>6</a:Id><a:State>California</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>CO</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>7</a:Id><a:State>Colorado</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>CT</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>8</a:Id><a:State>Connecticut</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>DC</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>9</a:Id><a:State>District Of Columbia</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>DE</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>10</a:Id><a:State>Delaware</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>FM</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>11</a:Id><a:State>Federated States of Micronesia</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>FL</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>12</a:Id><a:State>Florida</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>GA</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>13</a:Id><a:State>Georgia</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>GU</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>14</a:Id><a:State>Guam</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>HI</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>15</a:Id><a:State>Hawaii</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>ID</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>16</a:Id><a:State>Idaho</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>IL</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>17</a:Id><a:State>Illinois</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>IN</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>18</a:Id><a:State>Indiana</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>IA</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>19</a:Id><a:State>Iowa</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>KS</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>20</a:Id><a:State>Kansas</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>KY</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>21</a:Id><a:State>Kentucky</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>LA</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>22</a:Id><a:State>Louisiana</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>ME</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>23</a:Id><a:State>Maine</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>MH</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>24</a:Id><a:State>Marshall Islands</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>MD</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>25</a:Id><a:State>Maryland</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>MA</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>26</a:Id><a:State>Massachusetts</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>MI</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>27</a:Id><a:State>Michigan</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>MN</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>28</a:Id><a:State>Minnesota</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>MS</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>29</a:Id><a:State>Mississippi</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>MO</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>30</a:Id><a:State>Missouri</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>MT</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>31</a:Id><a:State>Montana</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>NE</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>32</a:Id><a:State>Nebraska</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>NV</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>33</a:Id><a:State>Nevada</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>NH</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>34</a:Id><a:State>New Hampshire</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>NJ</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>35</a:Id><a:State>New Jersey</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>NM</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>36</a:Id><a:State>New Mexico</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>NY</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>37</a:Id><a:State>New York</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>NC</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>38</a:Id><a:State>North Carolina</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>ND</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>39</a:Id><a:State>North Dakota</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>OH</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>40</a:Id><a:State>Ohio</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>OK</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>41</a:Id><a:State>Oklahoma</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>OR</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>42</a:Id><a:State>Oregon</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>PW</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>43</a:Id><a:State>Palau</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>PA</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>44</a:Id><a:State>Pennsylvania</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>PR</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>45</a:Id><a:State>Puerto Rico</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>RI</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>46</a:Id><a:State>Rhode Island</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>SC</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>47</a:Id><a:State>South Carolina</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>SD</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>48</a:Id><a:State>South Dakota</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>TN</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>49</a:Id><a:State>Tennessee</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>TX</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>50</a:Id><a:State>Texas</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>UT</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>51</a:Id><a:State>Utah</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>VT</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>52</a:Id><a:State>Vermont</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>VI</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>53</a:Id><a:State>Virgin Islands</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>VA</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>54</a:Id><a:State>Virginia</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>WA</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>55</a:Id><a:State>Washington</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>WV</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>56</a:Id><a:State>West Virginia</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>WI</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>57</a:Id><a:State>Wisconsin</a:State></a:StateDTO><a:StateDTO><a:Abbreviation>WY</a:Abbreviation><a:Continent>North America</a:Continent><a:ContinentCode>NA</a:ContinentCode><a:Country>United States</a:Country><a:CountryAbbreviation>US</a:CountryAbbreviation><a:CountryId>1</a:CountryId><a:Id>58</a:Id><a:State>Wyoming</a:State></a:StateDTO></GetAllProvincesByCountryIdResult></GetAllProvincesByCountryIdResponse>
@@ -1,3 +1,3 @@
1
1
  module ZipCodeServices
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -2,21 +2,34 @@
2
2
  %w[
3
3
  rubygems
4
4
  typhoeus
5
+ multi_xml
5
6
  ].each { |r| require r }
6
7
 
7
8
  module ZipCodeServices
8
- @base_uri = 'https://www.zipcodeservices.com/services/rest/json' #/zipcodes.svc'
9
+ @base_uri = 'https://www.zipcodeservices.com/services/rest' #/json' #/zipcodes.svc'
10
+ #MultiXml.parser = :ox
11
+ MultiXml.parser = :nokogiri
9
12
 
10
13
  class << self;
11
- #attr_accessor :base_uri
14
+ attr_accessor :data_format
12
15
  attr_accessor :apikey
13
16
 
17
+ def base_uri
18
+ fmt = data_format == :xml ? 'xml' : 'json'
19
+ "#{@base_uri}/#{fmt}"
20
+ end
21
+
14
22
  def zipcode(zip)
15
23
  #/{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
24
+ response = Typhoeus::Request.get( "#{base_uri}/zipcodes.svc/#{apikey}/#{zip}")
25
+ if response.code == 200
26
+ if data_format == :xml
27
+ j = MultiXml.parse(response.body)
28
+ raise "BAD API KEY" if j.first[1].first[1]["City"] == nil
29
+ else
30
+ j = JSON::parse(response.body)
31
+ raise "BAD API KEY" if j.first[1]["City"] == nil
32
+ end
20
33
  j
21
34
  elsif response.code == 404
22
35
  nil
@@ -26,11 +39,15 @@ module ZipCodeServices
26
39
  end
27
40
 
28
41
  def radius(zip, rad)
29
- #/{apikey}/{zipcode}
30
- response = Typhoeus::Request.get( "#{@base_uri}/zipcodes.svc/#{apikey}/#{zip}/#{rad}")
42
+ response = Typhoeus::Request.get( "#{base_uri}/zipcodes.svc/#{apikey}/#{zip}/#{rad}")
31
43
  if response.code == 200
32
- j = JSON::parse(response.body)
33
- raise "BAD API KEY" if j["RetrieveZipCodesInRadiusResult"] == nil
44
+ if data_format == :xml
45
+ j = MultiXml.parse(response.body)
46
+ raise "BAD API KEY" if j.first[1].first[1] == nil
47
+ else
48
+ j = JSON::parse(response.body)
49
+ raise "BAD API KEY" if j["RetrieveZipCodesInRadiusResult"] == nil
50
+ end
34
51
  j
35
52
  elsif response.code == 404
36
53
  nil
@@ -39,13 +56,18 @@ module ZipCodeServices
39
56
  end
40
57
  end
41
58
 
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}")
59
+ def radius_by_latlong(lat, lon, rad)
60
+ response = Typhoeus::Request.get( "#{base_uri}/zipcodes.svc/GetZipCodesInRadiusLatLong?apikey=#{apikey}&latitude=#{lat}&longitude=#{lon}&radius=#{rad}")
45
61
  if response.code == 200
46
- j = JSON::parse(response.body)
47
- raise "BAD API KEY" if j["GetZipCodesInRadiusOfLatLongResult"] == nil
48
- j
62
+ if data_format == :xml
63
+ j = MultiXml.parse(response.body)
64
+ raise "BAD API KEY" if j.first[1].first[1].first[1][0]["PostalCode"] == nil
65
+ else
66
+ j = JSON::parse(response.body)
67
+ raise "BAD API KEY" if j.first[1].first["PostalCode"] == nil
68
+ # ["GetZipCodesInRadiusOfLatLongResult"] ==nil
69
+ end
70
+ j
49
71
  elsif response.code == 404
50
72
  nil
51
73
  else
@@ -54,26 +76,34 @@ module ZipCodeServices
54
76
  end
55
77
 
56
78
  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}")
79
+ response = Typhoeus::Request.get( "#{base_uri}/zipcodes.svc/GetDistanceBetweenZipCodes?apikey=#{apikey}&zipcode1=#{zip1}&zipcode2=#{zip2}")
59
80
  if response.code == 200
60
- j = JSON::parse(response.body)
61
- raise "BAD API KEY" if j.first[1]["ZipCode1"] == nil
62
- j
81
+ if data_format == :xml
82
+ j = MultiXml.parse(response.body)
83
+ raise "BAD API KEY" if j.first[1].first[1]["DistanceAwayInMiles"] == nil
84
+ else
85
+ j = JSON::parse(response.body)
86
+ raise "BAD API KEY" if j.first[1]["ZipCode1"] == nil
87
+ end
88
+ j
63
89
  elsif response.code == 404
64
90
  nil
65
91
  else
66
92
  raise response.body
67
- end
68
- end
93
+ end
94
+ end
69
95
 
70
96
  def countries
71
- #/{apikey}/{zipcode}
72
- response = Typhoeus::Request.get( "#{@base_uri}/countries.svc/#{apikey}")
97
+ response = Typhoeus::Request.get( "#{base_uri}/countries.svc/#{apikey}")
73
98
  if response.code == 200
74
- j = JSON::parse(response.body)
75
- raise "BAD API KEY" if j["GetCountriesResult"] == nil
76
- j
99
+ if data_format == :xml
100
+ j = MultiXml.parse(response.body)
101
+ raise "BAD API KEY" if j.first[1].first[1].first[1][0]["Abbreviation"] == nil
102
+ else
103
+ j = JSON::parse(response.body)
104
+ raise "BAD API KEY" if j["GetCountriesResult"] == nil
105
+ end
106
+ j
77
107
  elsif response.code == 404
78
108
  nil
79
109
  else
@@ -82,12 +112,17 @@ module ZipCodeServices
82
112
  end
83
113
 
84
114
  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
115
+ response = Typhoeus::Request.get( "#{base_uri}/provinces.svc/#{apikey}/#{country_id}")
116
+ if response.code == 200
117
+ if data_format == :xml
118
+ j = MultiXml.parse(response.body)
119
+ raise "BAD API KEY" if j.first[1].first[1].first[1][0]["Abbreviation"] == nil
120
+ j
121
+ else
122
+ j = JSON::parse(response.body)
123
+ raise "BAD API KEY" if j["GetAllProvincesByCountryIdResult"] == nil
124
+ j
125
+ end
91
126
  elsif response.code == 404
92
127
  nil
93
128
  else
@@ -98,11 +133,17 @@ module ZipCodeServices
98
133
 
99
134
  def cities(province_id)
100
135
  #/{apikey}/{zipcode}
101
- response = Typhoeus::Request.get( "#{@base_uri}/cities.svc/#{apikey}/#{province_id}")
136
+ response = Typhoeus::Request.get( "#{base_uri}/cities.svc/#{apikey}/#{province_id}")
102
137
  if response.code == 200
103
- j = JSON::parse(response.body)
104
- raise "BAD API KEY" if j["GetCitiesByProvinceResult"] == nil
105
- j
138
+ if data_format == :xml
139
+ j = MultiXml.parse(response.body)
140
+ raise "BAD API KEY" if j.first[1].first[1].first[1][0]["City"] == nil
141
+ j
142
+ else
143
+ j = JSON::parse(response.body)
144
+ raise "BAD API KEY" if j["GetCitiesByProvinceResult"] == nil
145
+ j
146
+ end
106
147
  elsif response.code == 404
107
148
  nil
108
149
  else
@@ -111,12 +152,17 @@ module ZipCodeServices
111
152
  end
112
153
 
113
154
  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}")
155
+ response = Typhoeus::Request.get( "#{base_uri}/cities.svc/#{apikey}/#{province_id}/#{country_id}")
116
156
  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
157
+ if data_format == :xml
158
+ j = MultiXml.parse(response.body)
159
+ raise "BAD API KEY" if j.first[1].first[1].first[1][20]["City"] == nil
160
+ j
161
+ else
162
+ j = JSON::parse(response.body)
163
+ raise "BAD API KEY" if j["GetCitiesByProvinceAndCountryResult"] == nil # NOTE: also happens when a province id is not valid for a country
164
+ j
165
+ end
120
166
  elsif response.code == 404
121
167
  nil
122
168
  else
@@ -124,7 +170,42 @@ module ZipCodeServices
124
170
  end
125
171
  end
126
172
 
173
+ def ipaddress(ip)
174
+ response = Typhoeus::Request.get( "#{base_uri}/ipaddress.svc/GetIP?apikey=#{apikey}&ip=#{ip}")
175
+ if response.code == 200
176
+ if data_format == :xml
177
+ j = MultiXml.parse(response.body)
178
+ raise "BAD API KEY" if j.first[1].first[1]["ZipCode"] == nil
179
+ j
180
+ else
181
+ j = JSON::parse(response.body)
182
+ raise "BAD API KEY" if j["RetrieveIPAddressDataResult"] == nil # NOTE: also happens when a province id is not valid for a country
183
+ j
184
+ end
185
+ elsif response.code == 404
186
+ nil
187
+ else
188
+ raise response.body
189
+ end
190
+ end
127
191
 
128
- end
192
+ def ipaddress_radius(ip, rad)
193
+ response = Typhoeus::Request.get( "#{base_uri}/ipaddress.svc/GetZipsInRadiusOfIP?apikey=#{apikey}&ip=#{ip}&radius=#{rad}")
194
+ if response.code == 200
195
+ if data_format == :xml
196
+ j = MultiXml.parse(response.body)
197
+ raise "BAD API KEY" if j.first[1].first[1].first[1]["PostalCode"] == nil
198
+ j
199
+ else
200
+ j = JSON::parse(response.body)
201
+ raise "BAD API KEY" if j["RetrieveZipCodesInRadiusOfIPResult"] == nil # NOTE: also happens when a province id is not valid for a country
202
+ j
203
+ end
204
+ elsif response.code == 404
205
+ nil
206
+ else
207
+ raise response.body
208
+ end
209
+ end
210
+ end
129
211
  end
130
-
data/spec/client_spec.rb CHANGED
@@ -1,52 +1,117 @@
1
1
  require 'zipcodeservices'
2
2
  require 'spec_helper'
3
3
 
4
- describe "client" do
5
-
4
+ describe "json client" do
6
5
  before(:each) do
7
- ZipCodeServices.apikey = 'YOUR_API_KEY_HERE'
6
+ ZipCodeServices.data_format = :json
8
7
  end
9
8
 
10
- it "should retrieve zip code info", :vcr, record: :new_episodes do
9
+ it "should retrieve zip code info", :vcr, record: :all do
11
10
  zips = ZipCodeServices.zipcode("78702")
12
11
  zips.first[1]["City"].should == "Austin"
13
12
  # test other item
14
13
  end
15
14
 
16
- it "should get zip codes in radius of zip code", :vcr, record: :new_episodes do
15
+ it "should get zip codes in radius of zip code", :vcr, record: :all do
17
16
  zips = ZipCodeServices.radius(78702, 1)
18
17
  zips.first[1].first["PostalCode"].should == "78701"
19
18
  end
20
19
 
21
- it "should get zip codes in radius of latitude and longitude", :vcr, record: :new_episodes do
20
+ it "should get zip codes in radius of latitude and longitude", :vcr, record: :all do
22
21
  zips = ZipCodeServices.radius_by_latlong("30.2645715", "-97.7284341", 1)
23
22
  zips.first[1].first["PostalCode"].should == "73301"
24
23
  end
25
24
 
26
- it "should get the distance between zip codes", :vcr, record: :new_episodes do
25
+ it "should get the distance between zip codes", :vcr, record: :all do
27
26
  zips = ZipCodeServices.distance_between_zipcodes("78702", "01109")
28
27
  zips.first[1]["DistanceAwayInMiles"].should == 1616.501295
29
28
  end
30
29
 
31
30
 
32
- it "should get countries", :vcr, record: :new_episodes do
31
+ it "should get countries", :vcr, record: :all do
33
32
  countries = ZipCodeServices.countries
34
33
  countries.first[1].first["Abbreviation"].should == "US"
35
34
  end
36
35
 
37
- it "should get states / provinces by country id (country id attained by request to countries list)", :vcr, record: :new_episodes do
36
+ it "should get states-provinces by country id", :vcr, record: :all do
38
37
  states = ZipCodeServices.states(1)
39
- states.first[1].first["Abbreviation"].should == "AL"
38
+ states.first[1].first["Abbreviation"].should == "AL"
40
39
  end
41
40
 
42
- it "should get cities by province id / provinces id (country id attained by request to states list)", :vcr, record: :new_episodes do
41
+ it "should get cities by state id (province id)", :vcr, record: :all do
43
42
  cities = ZipCodeServices.cities(200)
44
- cities.first[1].first["City"].should == "Alamo"
43
+ cities.first[1].first["City"].should == "Alamo"
45
44
  end
46
45
 
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
46
+ it "should get cities by state id (provinces id) and country id", :vcr, record: :all do
48
47
  cities = ZipCodeServices.cities_by_state_and_country(1, 1)
49
48
  cities.first[1][20]["City"].should == "Arlington"
50
49
  end
51
50
 
51
+ it "should return information on ip addresses", :vcr, record: :all do
52
+ data = ZipCodeServices.ipaddress("184.98.179.3")
53
+ data.first[1]["ZipCode"].should == "85001"
54
+ end
55
+
56
+ it "should return zips in radius of ip address", :vcr, record: :all do
57
+ data = ZipCodeServices.ipaddress_radius("184.98.179.3", 1)
58
+ data.first[1].first["PostalCode"].should == "86323"
59
+ end
60
+ end
61
+
62
+
63
+ describe "xml client" do
64
+ before(:each) do
65
+ ZipCodeServices.data_format = :xml
66
+ end
67
+
68
+ it "should retrieve zip code info", :vcr, record: :all do
69
+ zips = ZipCodeServices.zipcode("78702")
70
+ zips.first[1].first[1]["City"].should == "Austin"
71
+ end
72
+
73
+ it "should get zip codes in radius of zip code", :vcr, record: :all do
74
+ zips = ZipCodeServices.radius(78702, 1)
75
+ zips.first[1].first[1].first[1].first["PostalCode"].should == "78701"
76
+ end
77
+
78
+ it "should get zip codes in radius of latitude and longitude", :vcr, record: :all do
79
+ zips = ZipCodeServices.radius_by_latlong("30.2645715", "-97.7284341", 1)
80
+ zips.first[1]["GetZipCodesInRadiusOfLatLongResult"]["ZipCodeWithDistanceDTO"][0]["PostalCode"].should == "73301"
81
+ end
82
+
83
+ it "should get the distance between zip codes", :vcr, record: :all do
84
+ zips = ZipCodeServices.distance_between_zipcodes("78702", "01109")
85
+ zips.first[1]["RetrieveDistanceBetweenZipCodesResult"]["DistanceAwayInMiles"].should == "1616.501295"
86
+ end
87
+
88
+ it "should get countries", :vcr, record: :all do
89
+ countries = ZipCodeServices.countries
90
+ countries.first[1].first[1].first[1][0]["Abbreviation"].should == "US"
91
+ end
92
+
93
+ it "should get states-provinces by country id", :vcr, record: :all do
94
+ states = ZipCodeServices.states(1)
95
+ states.first[1].first[1].first[1][0]["Abbreviation"].should == "AL"
96
+ end
97
+
98
+ it "should get cities by state id (province id)", :vcr, record: :all do
99
+ cities = ZipCodeServices.cities(200)
100
+ cities.first[1].first[1].first[1][0]["City"].should == "Alamo"
101
+ end
102
+
103
+ it "should get cities by state id (provinces id) and country id", :vcr, record: :all do
104
+ cities = ZipCodeServices.cities_by_state_and_country(1, 1)
105
+ cities.first[1].first[1].first[1][20]["City"].should == "Arlington"
106
+ end
107
+
108
+ it "should return information on ip addresses", :vcr, record: :all do
109
+ data = ZipCodeServices.ipaddress("184.98.179.3")
110
+ data.first[1].first[1]["ZipCode"].should == "85001"
111
+ end
112
+
113
+ it "should return zips in radius of ip address", :vcr, record: :all do
114
+ data = ZipCodeServices.ipaddress_radius("184.98.179.3", 1)
115
+ data.first[1].first[1].first[1]["PostalCode"].should == "86323"
116
+ end
52
117
  end
data/spec/spec_helper.rb CHANGED
@@ -2,10 +2,13 @@ require 'rspec'
2
2
  require 'vcr'
3
3
  #require 'webmock/rspec'
4
4
 
5
+ ZipCodeServices.apikey = ENV['ZIP_CODE_SERVICES_API_KEY']
6
+
5
7
  VCR.configure do |c|
6
8
  c.allow_http_connections_when_no_cassette = true
7
9
  c.cassette_library_dir = 'spec/vcr_cassettes'
8
10
  c.hook_into :typhoeus
11
+ c.filter_sensitive_data("<API_KEY>") { ZipCodeServices.apikey }
9
12
  end
10
13
 
11
14
  RSpec.configure do |config|