postmon_ruby 0.0.3 → 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f4a2b7f1fc6c75467d7f80b82d3c13699fda216
4
+ data.tar.gz: 7dc7685884c1b00eab38a347ef95ade361c519c0
5
+ SHA512:
6
+ metadata.gz: 4c0ce9b06f829d873395777110830a046a9f03478b82734bf13e1f33dfd1a0cd3d0ac0b6d3d759e720dfca520ebb16d9ded85c42c1afa8e34d8af88dbced7a86
7
+ data.tar.gz: 22a8552792c130cda97be3158a6130d7d5ef0d59089f4e1869d1cca91491971247b5b58867ced65618b44901b587e71c955e7b237c95b72341b618454741558b
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in postmon_ruby.gemspec
4
4
  gemspec
5
- gem "httparty"
data/LICENSE.txt CHANGED
@@ -1,22 +1,21 @@
1
- Copyright (c) 2013 TODO: Write your name
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2014 Postmon API
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ```ruby
22
22
  require 'postmon_ruby'
23
- resultado = PostmonRuby.consultar_cep "01330000"
23
+ resultado = PostmonRuby::Client.search "01330000"
24
24
  puts resultado.logradouro
25
25
  puts resultado.bairro
26
26
  puts resultado.cidade
@@ -33,4 +33,4 @@ puts resultado.estado
33
33
  2. Create your feature branch (`git checkout -b my-new-feature`)
34
34
  3. Commit your changes (`git commit -am 'Add some feature'`)
35
35
  4. Push to the branch (`git push origin my-new-feature`)
36
- 5. Create new Pull Request
36
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,8 +1 @@
1
1
  require "bundler/gem_tasks"
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new do |t|
5
- t.libs << 'test'
6
- end
7
-
8
- task :default => :test
@@ -0,0 +1,17 @@
1
+ module PostmonRuby
2
+ class Address
3
+ @@address_attributes = [ :complemento, :bairro, :cidade, :logradouro, :estado, :cep ]
4
+
5
+ attr_reader :not_found, *@@address_attributes
6
+
7
+ def initialize(options={})
8
+ @not_found = true if options.nil?
9
+ @@address_attributes.each do |attribute|
10
+ send(:"#{attribute}=", options[attribute.to_s] || "")
11
+ end
12
+ end
13
+
14
+ private
15
+ attr_writer *@@address_attributes
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module PostmonRuby
2
+ class Client
3
+ def self.search(cep)
4
+ PostmonRuby::Address.new( HTTParty.get("#{ENDPOINT}/cep/#{cep}") )
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module PostmonRuby
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/postmon_ruby.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require "postmon_ruby/version"
2
- require "postmon_ruby/postmon"
2
+ require "postmon_ruby/client"
3
+ require "postmon_ruby/address"
3
4
  require "httparty"
5
+ require "pry"
4
6
 
5
7
  module PostmonRuby
6
- def self.consultar_cep(cep)
7
- Postmon.new.consultar_cep cep
8
- end
8
+ ENDPOINT = "http://api.postmon.com.br"
9
9
  end
data/postmon_ruby.gemspec CHANGED
@@ -1,20 +1,26 @@
1
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'postmon_ruby/version'
5
5
 
6
- Gem::Specification.new do |gem|
7
- gem.name = "postmon_ruby"
8
- gem.version = PostmonRuby::VERSION
9
- gem.authors = ["Carlos Ribeiro"]
10
- gem.email = ["mail@carlosribeiro.me"]
11
- gem.description = %q{Realiza consultas de cep no serviço Postmon}
12
- gem.summary = %q{}
13
- gem.homepage = ""
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "postmon_ruby"
8
+ spec.version = PostmonRuby::VERSION
9
+ spec.authors = ["Carlos Ribeiro"]
10
+ spec.email = ["mail@carlosribeiro.me"]
11
+ spec.description = "A rubygem to access the Postmon API"
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/PostmonAPI/postmon-ruby"
14
+ spec.license = "MIT"
14
15
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
19
20
 
21
+ spec.add_dependency "httparty", "~> 0.13"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "rspec"
20
26
  end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ module PostmonRuby
4
+ describe Client do
5
+ describe "#find" do
6
+ context "with valid cep" do
7
+ context "address with street" do
8
+ let(:address) { PostmonRuby::Client.search("01330000") }
9
+ it "returns a PostmonRuby::Address object" do
10
+ expect(address).to be_a(PostmonRuby::Address)
11
+ end
12
+ it "returns a complete address" do
13
+ expect(address.bairro).to eq "Bela Vista"
14
+ expect(address.cidade).to eq "São Paulo"
15
+ expect(address.logradouro).to eq "Rua Rocha"
16
+ expect(address.estado).to eq "SP"
17
+ end
18
+ end
19
+
20
+ context "address without street" do
21
+ let(:address) { PostmonRuby::Client.search("85100000") }
22
+ it "returns a PostmonRuby::Address object" do
23
+ # binding.pry
24
+ expect(address).to be_a(PostmonRuby::Address)
25
+ end
26
+ it "returns a empty 'logradouro' " do
27
+ expect(address.logradouro).to be_empty
28
+ end
29
+ end
30
+ end
31
+
32
+ context "with invalid cep" do
33
+ let(:address) { PostmonRuby::Client.search("99999999") }
34
+ it "returns a PostmonRuby::Address object" do
35
+ expect(address).to be_a(PostmonRuby::Address)
36
+ end
37
+
38
+ it "returns true in 'not_found'" do
39
+ expect(address.not_found).to be_true
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,18 @@
1
+ require "postmon_ruby"
2
+ # This file was generated by the `rspec --init` command. Conventionally, all
3
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
+ # Require this file using `require "spec_helper"` to ensure that it is only
5
+ # loaded once.
6
+ #
7
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ end
metadata CHANGED
@@ -1,17 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmon_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Carlos Ribeiro
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-23 00:00:00.000000000 Z
13
- dependencies: []
14
- description: Realiza consultas de cep no serviço Postmon
11
+ date: 2014-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A rubygem to access the Postmon API
15
84
  email:
16
85
  - mail@carlosribeiro.me
17
86
  executables: []
@@ -19,40 +88,42 @@ extensions: []
19
88
  extra_rdoc_files: []
20
89
  files:
21
90
  - .gitignore
91
+ - .rspec
22
92
  - Gemfile
23
93
  - LICENSE.txt
24
94
  - README.md
25
95
  - Rakefile
26
96
  - lib/postmon_ruby.rb
27
- - lib/postmon_ruby/postmon.rb
97
+ - lib/postmon_ruby/address.rb
98
+ - lib/postmon_ruby/client.rb
28
99
  - lib/postmon_ruby/version.rb
29
100
  - postmon_ruby.gemspec
30
- - test/helper.rb
31
- - test/test_postmon_ruby.rb
32
- homepage: ''
33
- licenses: []
101
+ - spec/postmon_ruby/postmon_ruby_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/PostmonAPI/postmon-ruby
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
34
107
  post_install_message:
35
108
  rdoc_options: []
36
109
  require_paths:
37
110
  - lib
38
111
  required_ruby_version: !ruby/object:Gem::Requirement
39
- none: false
40
112
  requirements:
41
- - - ! '>='
113
+ - - '>='
42
114
  - !ruby/object:Gem::Version
43
115
  version: '0'
44
116
  required_rubygems_version: !ruby/object:Gem::Requirement
45
- none: false
46
117
  requirements:
47
- - - ! '>='
118
+ - - '>='
48
119
  - !ruby/object:Gem::Version
49
120
  version: '0'
50
121
  requirements: []
51
122
  rubyforge_project:
52
- rubygems_version: 1.8.24
123
+ rubygems_version: 2.2.2
53
124
  signing_key:
54
- specification_version: 3
55
- summary: ''
125
+ specification_version: 4
126
+ summary: A rubygem to access the Postmon API
56
127
  test_files:
57
- - test/helper.rb
58
- - test/test_postmon_ruby.rb
128
+ - spec/postmon_ruby/postmon_ruby_spec.rb
129
+ - spec/spec_helper.rb
@@ -1,19 +0,0 @@
1
- class Postmon
2
- private
3
- attr_writer :complemento, :bairro, :cidade, :logradouro, :cep, :estado
4
-
5
- public
6
- attr_reader :complemento, :bairro, :cidade, :logradouro, :cep, :estado
7
-
8
- def consultar_cep(cep)
9
- result = HTTParty.get "http://api.postmon.com.br/cep/#{cep}"
10
- self.complemento = result["complemento"] || ""
11
- self.bairro = result["bairro"] || ""
12
- self.cidade = result["cidade"] || ""
13
- self.logradouro = result["logradouro"] || ""
14
- self.cep = result["cep"] || ""
15
- self.estado = result["estado"] || ""
16
- self
17
- end
18
-
19
- end
data/test/helper.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'test/unit'
2
- require 'postmon_ruby'
@@ -1,28 +0,0 @@
1
- #encoding: utf-8
2
- require 'helper'
3
-
4
- class TestPostmonRuby < Test::Unit::TestCase
5
- def test_cep_com_rua
6
- consulta = PostmonRuby.consultar_cep "01330000"
7
- assert_equal "Rua Rocha", consulta.logradouro
8
- assert_equal "Bela Vista", consulta.bairro
9
- assert_equal "São Paulo", consulta.cidade
10
- assert_equal "SP", consulta.estado
11
- end
12
-
13
- def test_cep_sem_rua
14
- consulta = PostmonRuby.consultar_cep "85100000"
15
- assert_equal "Jordão (Guarapuava)", consulta.cidade
16
- assert_equal "PR", consulta.estado
17
- assert consulta.logradouro.empty?
18
- assert consulta.bairro.empty?
19
- end
20
-
21
- def test_cep_inexistente
22
- consulta = PostmonRuby.consultar_cep "99999999"
23
- assert consulta.cidade.empty?
24
- assert consulta.estado.empty?
25
- assert consulta.logradouro.empty?
26
- assert consulta.bairro.empty?
27
- end
28
- end