sepomex 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e1595f4b7e9caf263e845125b0147495becf068
4
- data.tar.gz: 276d81b2f1f31300853eef370f3eaf0497045d7c
3
+ metadata.gz: 60a528b01402e995f58a69698b2a7bcf668186a7
4
+ data.tar.gz: fbfaf235a30f421fc0d61597ca253c18f9e2764b
5
5
  SHA512:
6
- metadata.gz: 362b9b2733fa9dd0c991eb04ea4acca726bc143c17c4e75dd9a40589b1d5ee509397472ccb4319fb078a2f95ca9d8384297082fed6a5ec5c0c38ad5b9f686388
7
- data.tar.gz: 37fad23a8f0c3dfff48646be9278ff5cc0beaff1f4df27d255ea6a048a96e158a0a32905d886ca83c30b216a81e74eed1635553c1f9a24b9cee69b74c7d31118
6
+ metadata.gz: 966dc72e1fbf1daad4fd2bd85eb2e6eb8449a63ed8c32e041511d3544598ca603731b6c6cf739798f8b5e37f0172dd1d074a32e196327fb24b679448c789cb02
7
+ data.tar.gz: a93a57c27ad52455a9e253c6584b7617409df823ebb3baa872b6e55016cd77488c01d6296fe43da9e9798cfcd168d87b97b971efff6f8417581388cdfb2a149a
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .DS_Store
11
+ *.gem
data/README.md CHANGED
@@ -1,10 +1,17 @@
1
- # Sepomex
1
+ # Sepomex-rb
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sepomex`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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
- ## Installation
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
- $ bundle
24
+ ```console
25
+ % bundle
26
+ ```
18
27
 
19
28
  Or install it yourself as:
20
29
 
21
- $ gem install sepomex
30
+ ```
31
+ % gem install sepomex
32
+ ```
22
33
 
23
34
  ## Usage
24
35
 
25
- TODO: Write usage instructions here
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
@@ -1,3 +1,3 @@
1
1
  module Sepomex
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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["zip_codes"].map { |attributes| new(attributes) }
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.1.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