sepomex 0.1.0 → 0.2.0
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 +4 -4
- data/.gitignore +1 -0
- data/README.md +55 -7
- data/lib/sepomex/collection.rb +17 -0
- data/lib/sepomex/version.rb +1 -1
- data/lib/sepomex/zip_code.rb +9 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60a528b01402e995f58a69698b2a7bcf668186a7
|
4
|
+
data.tar.gz: fbfaf235a30f421fc0d61597ca253c18f9e2764b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 966dc72e1fbf1daad4fd2bd85eb2e6eb8449a63ed8c32e041511d3544598ca603731b6c6cf739798f8b5e37f0172dd1d074a32e196327fb24b679448c789cb02
|
7
|
+
data.tar.gz: a93a57c27ad52455a9e253c6584b7617409df823ebb3baa872b6e55016cd77488c01d6296fe43da9e9798cfcd168d87b97b971efff6f8417581388cdfb2a149a
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
-
# Sepomex
|
1
|
+
# Sepomex-rb
|
2
2
|
|
3
|
-
|
3
|
+
A super simple Ruby wrapper to consume the Sepomex API at [http://sepomex-api.herokuapp.com/api/v1/zip_codes](http://sepomex-api.herokuapp.com/api/v1/zip_codes)
|
4
4
|
|
5
|
-
|
5
|
+
## Table of contents
|
6
|
+
- [Quick start](#quick-start)
|
7
|
+
- [Usage](#usage)
|
8
|
+
- [Bug tracker & feature request](#bug-tracker-&-feature-request)
|
9
|
+
- [Development](#development)
|
10
|
+
- [Contributing](#contributing)
|
11
|
+
- [Heroes](#heroes)
|
12
|
+
- [License](#license)
|
6
13
|
|
7
|
-
##
|
14
|
+
## Quick Start
|
8
15
|
|
9
16
|
Add this line to your application's Gemfile:
|
10
17
|
|
@@ -14,15 +21,38 @@ gem 'sepomex'
|
|
14
21
|
|
15
22
|
And then execute:
|
16
23
|
|
17
|
-
|
24
|
+
```console
|
25
|
+
% bundle
|
26
|
+
```
|
18
27
|
|
19
28
|
Or install it yourself as:
|
20
29
|
|
21
|
-
|
30
|
+
```
|
31
|
+
% gem install sepomex
|
32
|
+
```
|
22
33
|
|
23
34
|
## Usage
|
24
35
|
|
25
|
-
|
36
|
+
```ruby
|
37
|
+
zip_codes = Sepomex::ZipCode.all
|
38
|
+
|
39
|
+
=> [ #<Sepomex::ZipCode id=1, d_codigo="01000", d_asenta="San Ángel", d_tipo_asenta="Colonia", d_mnpio="Álvaro Obregón", d_estado="Distrito Federal", d_ciudad="Ciudad de México", d_cp="01001", c_estado="09", c_oficina="01001", c_cp="", c_tipo_asenta="09", c_mnpio="010", id_asenta_cpcons="0001", d_zona="Urbano", c_cve_ciudad="01">,
|
40
|
+
#<Sepomex::ZipCode id=2...]
|
41
|
+
```
|
42
|
+
|
43
|
+
You can specify the page to request as an option on the method.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
zip_codes = Sepomex::ZipCode.all(page: 2)
|
47
|
+
|
48
|
+
=> [ #<Sepomex::ZipCode id=51, d_codigo="01000", d_asenta="San Ángel", d_tipo_asenta="Colonia", d_mnpio="Álvaro Obregón", d_estado="Distrito Federal", d_ciudad="Ciudad de México", d_cp="01001", c_estado="09", c_oficina="01001", c_cp="", c_tipo_asenta="09", c_mnpio="010", id_asenta_cpcons="0001", d_zona="Urbano", c_cve_ciudad="01">,
|
49
|
+
#<Sepomex::ZipCode id=52...]
|
50
|
+
```
|
51
|
+
|
52
|
+
## Bug tracker & feature request
|
53
|
+
|
54
|
+
Have a bug or a feature request? [Please open a new issue](https://github.com/IcaliaLabs/sepomex-rb/issues). Before opening any issue, please search for existing issues.
|
55
|
+
|
26
56
|
|
27
57
|
## Development
|
28
58
|
|
@@ -37,3 +67,21 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
37
67
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
68
|
4. Push to the branch (`git push origin my-new-feature`)
|
39
69
|
5. Create a new Pull Request
|
70
|
+
|
71
|
+
## Heroes
|
72
|
+
|
73
|
+
**Abraham Kuri**
|
74
|
+
|
75
|
+
+ [http://twitter.com/kurenn](http://twitter.com/kurenn)
|
76
|
+
+ [http://github.com/kurenn](http://github.com/kurenn)
|
77
|
+
+ [http://klout.com/#/kurenn](http://klout.com/#/kurenn)
|
78
|
+
|
79
|
+
**Oscar Elizondo**
|
80
|
+
|
81
|
+
+ [http://twitter.com/oehinojosa](http://twitter.com/oehinojosa)
|
82
|
+
+ [http://github.com/oelizondo](http://github.com/oelizondo)
|
83
|
+
|
84
|
+
|
85
|
+
## Copyright and license
|
86
|
+
|
87
|
+
Code and documentation copyright 2015 Icalia Labs. Code released under [the MIT license](LICENSE).
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Sepomex
|
2
|
+
class Collection
|
3
|
+
attr_reader :total_pages, :total_objects, :per_page, :collection
|
4
|
+
|
5
|
+
def initialize(attributes = {})
|
6
|
+
@total_pages = attributes["total_pages"]
|
7
|
+
@total_objects = attributes["total_objects"]
|
8
|
+
@per_page = attributes["per_page"]
|
9
|
+
@collection = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(name, *args, &block)
|
13
|
+
@collection.send(name, *args, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/sepomex/version.rb
CHANGED
data/lib/sepomex/zip_code.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sepomex/errors'
|
2
|
+
require 'sepomex/collection'
|
2
3
|
|
3
4
|
module Sepomex
|
4
5
|
class ZipCode < OpenStruct
|
@@ -7,10 +8,17 @@ module Sepomex
|
|
7
8
|
base_uri "sepomex-api.herokuapp.com/api/v1"
|
8
9
|
|
9
10
|
def self.all(options = {})
|
11
|
+
|
10
12
|
response = get("/zip_codes", { query: options })
|
11
13
|
|
12
14
|
if response.success?
|
13
|
-
response["
|
15
|
+
zip_codes = Sepomex::Collection.new(response["meta"]["pagination"])
|
16
|
+
|
17
|
+
response["zip_codes"].each do |attributes|
|
18
|
+
zip_codes << new(attributes)
|
19
|
+
end
|
20
|
+
|
21
|
+
zip_codes
|
14
22
|
else
|
15
23
|
raise_exception(response.code, response.body)
|
16
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sepomex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abraham Kuri
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- bin/console
|
87
87
|
- bin/setup
|
88
88
|
- lib/sepomex.rb
|
89
|
+
- lib/sepomex/collection.rb
|
89
90
|
- lib/sepomex/errors.rb
|
90
91
|
- lib/sepomex/version.rb
|
91
92
|
- lib/sepomex/zip_code.rb
|