postmon_ruby 2.1.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/README.md +1 -46
- data/Rakefile +1 -1
- data/lib/postmon_ruby.rb +3 -2
- data/lib/postmon_ruby/address.rb +1 -1
- data/lib/postmon_ruby/city.rb +1 -1
- data/lib/postmon_ruby/client.rb +0 -1
- data/lib/postmon_ruby/finders/cep_finder.rb +1 -1
- data/lib/postmon_ruby/finders/city_finder.rb +1 -1
- data/lib/postmon_ruby/finders/finder.rb +1 -1
- data/lib/postmon_ruby/finders/finders.rb +4 -4
- data/lib/postmon_ruby/finders/state_finder.rb +1 -1
- data/lib/postmon_ruby/finders/tracker/ect_tracker_finder.rb +1 -1
- data/lib/postmon_ruby/finders/tracker_finder.rb +1 -1
- data/lib/postmon_ruby/http/http.rb +26 -0
- data/lib/postmon_ruby/state.rb +1 -1
- data/lib/postmon_ruby/track.rb +1 -1
- data/lib/postmon_ruby/version.rb +1 -1
- data/postmon_ruby.gemspec +2 -2
- metadata +70 -96
- data/bin/postmon-ruby +0 -28
- data/lib/postmon_ruby/gem_output.rb +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
|
4
|
-
|
5
|
-
SHA512:
|
6
|
-
|
7
|
-
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
data.tar.gz: 30f1b8a965d093ec41b5dc99c4439be4c4bf2352
|
4
|
+
metadata.gz: ca37ddb91f9690f52307fdc011ced0a12d0b7efd
|
5
|
+
SHA512:
|
6
|
+
data.tar.gz: 69a7601c53867846ab7fb90044b406a7812d1fc4098502a22807d058be059ff66d089a491f3e9225c834d490b4bc45be7fcb78ba2325cd4606c964c7d4e2a3f9
|
7
|
+
metadata.gz: 2f571d9ef5c274a6da7ee3da96168651f12523e5dd042d6d711efd37bf102b9b1cd3ed0b34bccc18587dd7e30d23594ae5dda0a8b8b2031c0d276d8a708dbe06
|
data/README.md
CHANGED
@@ -45,52 +45,7 @@ puts resultado.nome
|
|
45
45
|
```
|
46
46
|
|
47
47
|
###Para consultar pelo terminal
|
48
|
-
|
49
|
-
|
50
|
-
$ postmon-ruby --cep 49015040
|
51
|
-
|
52
|
-
Complemento: lado ímpar
|
53
|
-
Bairro: São José
|
54
|
-
Cidade: Aracaju
|
55
|
-
Logradouro: Avenida Barão de Maruim
|
56
|
-
Estado: SE
|
57
|
-
Cep: 49015040
|
58
|
-
|
59
|
-
#### Consultar informações de uma cidade:
|
60
|
-
|
61
|
-
$ postmon-ruby --cidade SE,Aracaju
|
62
|
-
|
63
|
-
Area_km2: 181,857
|
64
|
-
Codigo_ibge: 2800308
|
65
|
-
|
66
|
-
#### Consultar informações de um estado:
|
67
|
-
|
68
|
-
$ postmon-ruby --estado SE
|
69
|
-
|
70
|
-
Area_km2: 21.915,116
|
71
|
-
Codigo_ibge: 28
|
72
|
-
Nome: Sergipe
|
73
|
-
|
74
|
-
#### Consultar informações de rastreio de um pacote:
|
75
|
-
|
76
|
-
$ postmon-ruby --rastreio RF223325059SG
|
77
|
-
|
78
|
-
Codigo: RF223325059SG
|
79
|
-
Servico: ect
|
80
|
-
detalhes: Em trвnsito para UNIDADE DE TRATAMENTO INTERNACIONAL - BRASIL
|
81
|
-
local: CINGAPURA
|
82
|
-
data: 11/04/2014 14:04
|
83
|
-
situacao: Encaminhado
|
84
|
-
|
85
|
-
#### Menu de opções:
|
86
|
-
|
87
|
-
$ postmon-ruby -h
|
88
|
-
|
89
|
-
Usage postmon [options]
|
90
|
-
--cep CEP Consultar CEP
|
91
|
-
--cidade UF,Cidade Consultar informações de uma cidade
|
92
|
-
--estado UF Consultar informações de um estado
|
93
|
-
--rastreio CODIGO_POSTAGEM Consultar informações de rastreio de um pacote
|
48
|
+
A comand-line-interface para consultar ceps, informações do IBGE e rastreio de pacotes diretamente do terminal foi separada em outro projeto. PostmonCLI(https://github.com/PostmonAPI/postmon-cli)
|
94
49
|
|
95
50
|
## Contributing
|
96
51
|
|
data/Rakefile
CHANGED
data/lib/postmon_ruby.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require "postmon_ruby/version"
|
2
|
+
require "json"
|
3
|
+
require "postmon_ruby/http/http"
|
2
4
|
require "postmon_ruby/client"
|
3
5
|
require "postmon_ruby/city"
|
4
6
|
require "postmon_ruby/state"
|
5
7
|
require "postmon_ruby/address"
|
6
|
-
require "postmon_ruby/gem_output"
|
7
8
|
require "postmon_ruby/track"
|
8
9
|
require "postmon_ruby/finders/finder"
|
9
10
|
require "postmon_ruby/finders/cep_finder"
|
@@ -12,7 +13,7 @@ require "postmon_ruby/finders/state_finder"
|
|
12
13
|
require "postmon_ruby/finders/tracker/ect_tracker_finder"
|
13
14
|
require "postmon_ruby/finders/tracker_finder"
|
14
15
|
require "postmon_ruby/finders/finders"
|
15
|
-
require "
|
16
|
+
require "net/http"
|
16
17
|
|
17
18
|
module PostmonRuby
|
18
19
|
ENDPOINT = "http://api.postmon.com.br/v1"
|
data/lib/postmon_ruby/address.rb
CHANGED
@@ -5,7 +5,7 @@ module PostmonRuby
|
|
5
5
|
attr_reader :not_found, *@@address_attributes
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
|
-
@not_found = true if options.
|
8
|
+
@not_found = true if options.not_found?
|
9
9
|
@@address_attributes.each do |attribute|
|
10
10
|
send(:"#{attribute}=", options[attribute.to_s] || "")
|
11
11
|
end
|
data/lib/postmon_ruby/city.rb
CHANGED
@@ -5,7 +5,7 @@ module PostmonRuby
|
|
5
5
|
attr_reader :not_found, *@@city_attributes
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
|
-
@not_found = true if options.
|
8
|
+
@not_found = true if options.not_found?
|
9
9
|
@@city_attributes.each do |attribute|
|
10
10
|
send(:"#{attribute}=", options[attribute.to_s] || "")
|
11
11
|
end
|
data/lib/postmon_ruby/client.rb
CHANGED
@@ -2,10 +2,10 @@ module PostmonRuby
|
|
2
2
|
module Finders
|
3
3
|
class Finders
|
4
4
|
@finders = {
|
5
|
-
cep
|
6
|
-
cidade
|
7
|
-
estado
|
8
|
-
rastreio
|
5
|
+
:cep => PostmonRuby::Finders::CepFinder.new,
|
6
|
+
:cidade => PostmonRuby::Finders::CityFinder.new,
|
7
|
+
:estado => PostmonRuby::Finders::StateFinder.new,
|
8
|
+
:rastreio => PostmonRuby::Finders::TrackerFinder.new
|
9
9
|
}
|
10
10
|
|
11
11
|
def self.get_finder(finder)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PostmonRuby
|
2
|
+
class Http
|
3
|
+
def self.get(uri)
|
4
|
+
instance = PostmonRuby::Http.new
|
5
|
+
instance.instance_variable_set("@response", Net::HTTP.get_response(uri))
|
6
|
+
instance
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](key)
|
10
|
+
@json = json unless @json
|
11
|
+
@json[key]
|
12
|
+
end
|
13
|
+
|
14
|
+
def not_found?
|
15
|
+
@response.is_a?(Net::HTTPNotFound)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def json
|
21
|
+
return {} if not_found?
|
22
|
+
JSON.parse(@response.body)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/postmon_ruby/state.rb
CHANGED
@@ -5,7 +5,7 @@ module PostmonRuby
|
|
5
5
|
attr_reader :not_found, *@@state_attributes
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
|
-
@not_found = true if options.
|
8
|
+
@not_found = true if options.not_found?
|
9
9
|
@@state_attributes.each do |attribute|
|
10
10
|
send(:"#{attribute}=", options[attribute.to_s] || "")
|
11
11
|
end
|
data/lib/postmon_ruby/track.rb
CHANGED
data/lib/postmon_ruby/version.rb
CHANGED
data/postmon_ruby.gemspec
CHANGED
@@ -14,11 +14,11 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = '
|
17
|
+
spec.executables = ''
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["./lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "
|
21
|
+
spec.add_dependency "json", "~> 1.8.1"
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
23
|
spec.add_development_dependency "rake"
|
24
24
|
spec.add_development_dependency "pry"
|
metadata
CHANGED
@@ -1,114 +1,89 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: postmon_ruby
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Carlos Ribeiro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
|
12
|
+
date: 2014-05-08 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
17
18
|
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :runtime
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.8.1
|
21
21
|
prerelease: false
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.13'
|
27
|
-
- !ruby/object:Gem::Dependency
|
22
|
+
requirement: *id001
|
23
|
+
type: :runtime
|
24
|
+
- !ruby/object:Gem::Dependency
|
28
25
|
name: bundler
|
29
|
-
|
30
|
-
requirements:
|
26
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
31
28
|
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :development
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: "1.3"
|
35
31
|
prerelease: false
|
36
|
-
|
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'
|
32
|
+
requirement: *id002
|
48
33
|
type: :development
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rake
|
36
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- &id004
|
39
|
+
- ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
49
42
|
prerelease: false
|
50
|
-
|
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'
|
43
|
+
requirement: *id003
|
62
44
|
type: :development
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: pry
|
47
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- *id004
|
63
50
|
prerelease: false
|
64
|
-
|
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'
|
51
|
+
requirement: *id005
|
76
52
|
type: :development
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- *id004
|
77
58
|
prerelease: false
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
59
|
+
requirement: *id006
|
60
|
+
type: :development
|
61
|
+
- !ruby/object:Gem::Dependency
|
84
62
|
name: webmock
|
85
|
-
|
86
|
-
requirements:
|
63
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
87
65
|
- - ~>
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version:
|
90
|
-
type: :development
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "1.17"
|
91
68
|
prerelease: false
|
92
|
-
|
93
|
-
|
94
|
-
- - ~>
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '1.17'
|
69
|
+
requirement: *id007
|
70
|
+
type: :development
|
97
71
|
description: A rubygem to access the Postmon API
|
98
|
-
email:
|
72
|
+
email:
|
99
73
|
- mail@carlosribeiro.me
|
100
|
-
executables:
|
101
|
-
|
74
|
+
executables: []
|
75
|
+
|
102
76
|
extensions: []
|
77
|
+
|
103
78
|
extra_rdoc_files: []
|
104
|
-
|
79
|
+
|
80
|
+
files:
|
105
81
|
- .gitignore
|
106
82
|
- .rspec
|
107
83
|
- Gemfile
|
108
84
|
- LICENSE.txt
|
109
85
|
- README.md
|
110
86
|
- Rakefile
|
111
|
-
- bin/postmon-ruby
|
112
87
|
- lib/postmon_ruby.rb
|
113
88
|
- lib/postmon_ruby/address.rb
|
114
89
|
- lib/postmon_ruby/city.rb
|
@@ -120,7 +95,7 @@ files:
|
|
120
95
|
- lib/postmon_ruby/finders/state_finder.rb
|
121
96
|
- lib/postmon_ruby/finders/tracker/ect_tracker_finder.rb
|
122
97
|
- lib/postmon_ruby/finders/tracker_finder.rb
|
123
|
-
- lib/postmon_ruby/
|
98
|
+
- lib/postmon_ruby/http/http.rb
|
124
99
|
- lib/postmon_ruby/state.rb
|
125
100
|
- lib/postmon_ruby/track.rb
|
126
101
|
- lib/postmon_ruby/version.rb
|
@@ -132,30 +107,29 @@ files:
|
|
132
107
|
- spec/postmon_ruby/state_finder_spec.rb
|
133
108
|
- spec/spec_helper.rb
|
134
109
|
homepage: https://github.com/PostmonAPI/postmon-ruby
|
135
|
-
licenses:
|
110
|
+
licenses:
|
136
111
|
- MIT
|
137
112
|
metadata: {}
|
113
|
+
|
138
114
|
post_install_message:
|
139
115
|
rdoc_options: []
|
140
|
-
|
116
|
+
|
117
|
+
require_paths:
|
141
118
|
- ./lib
|
142
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
-
requirements:
|
144
|
-
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
requirements:
|
149
|
-
- - '>='
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version: '0'
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- *id004
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- *id004
|
152
125
|
requirements: []
|
126
|
+
|
153
127
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.0.14
|
155
129
|
signing_key:
|
156
130
|
specification_version: 4
|
157
131
|
summary: A rubygem to access the Postmon API
|
158
|
-
test_files:
|
132
|
+
test_files:
|
159
133
|
- spec/postmon_ruby/cep_finder_spec.rb
|
160
134
|
- spec/postmon_ruby/city_finder_spec.rb
|
161
135
|
- spec/postmon_ruby/client_spec.rb
|
data/bin/postmon-ruby
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#encoding: UTF-8
|
3
|
-
|
4
|
-
require 'optparse'
|
5
|
-
require 'postmon_ruby'
|
6
|
-
|
7
|
-
options = {}
|
8
|
-
|
9
|
-
OptionParser.new do |opts|
|
10
|
-
opts.banner = "Usage postmon [options]"
|
11
|
-
opts.on("--cep CEP", String, "Consultar CEP") do |cep|
|
12
|
-
options[:cep] = cep
|
13
|
-
end
|
14
|
-
|
15
|
-
opts.on("--cidade UF,Cidade", Array, "Consultar informações de uma cidade") do |uf_cidade|
|
16
|
-
options[:cidade] = uf_cidade
|
17
|
-
end
|
18
|
-
|
19
|
-
opts.on("--estado UF", String, "Consultar informações de um estado") do |uf|
|
20
|
-
options[:estado] = uf
|
21
|
-
end
|
22
|
-
|
23
|
-
opts.on("--rastreio CODIGO_POSTAGEM", String, "Consultar informações de rastreio de um pacote") do |rastreio|
|
24
|
-
options[:rastreio] = rastreio
|
25
|
-
end
|
26
|
-
end.parse!
|
27
|
-
|
28
|
-
PostmonRuby::GemOutput.get_info(options)
|
@@ -1,67 +0,0 @@
|
|
1
|
-
module PostmonRuby
|
2
|
-
class GemOutput
|
3
|
-
def self.get_info(options)
|
4
|
-
unless options[:cep].nil?
|
5
|
-
cep(options[:cep])
|
6
|
-
end
|
7
|
-
|
8
|
-
unless options[:cidade].nil?
|
9
|
-
cidade(options[:cidade].first, options[:cidade].last)
|
10
|
-
end
|
11
|
-
|
12
|
-
unless options[:estado].nil?
|
13
|
-
estado(options[:estado])
|
14
|
-
end
|
15
|
-
|
16
|
-
unless options[:rastreio].nil?
|
17
|
-
rastreio(options[:rastreio])
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
def self.cep(cep)
|
23
|
-
resultado = Client.search :cep, cep
|
24
|
-
output_variables(resultado)
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.cidade(uf, cidade)
|
28
|
-
resultado = Client.search :cidade, uf, cidade
|
29
|
-
output_variables(resultado)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.estado(uf)
|
33
|
-
resultado = PostmonRuby::Client.search :estado, uf
|
34
|
-
output_variables(resultado)
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.rastreio(rastreio)
|
38
|
-
resultado = PostmonRuby::Client.search :rastreio, :ect, rastreio
|
39
|
-
output_variables(resultado)
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.output_variables(resultado)
|
43
|
-
if resultado.not_found
|
44
|
-
puts "Nenhum resultado encontrado."
|
45
|
-
else
|
46
|
-
info = {}
|
47
|
-
|
48
|
-
resultado.instance_variables.each do |var|
|
49
|
-
info[var.to_s.delete("@").capitalize] = resultado.instance_variable_get(var)
|
50
|
-
end
|
51
|
-
|
52
|
-
print_array_output(info)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.print_array_output(array, level = 0)
|
57
|
-
array.each do |k, v|
|
58
|
-
print "\t" if level > 0
|
59
|
-
if(v.kind_of?(Enumerable) || k.kind_of?(Enumerable))
|
60
|
-
print_array_output(v||k, 1)
|
61
|
-
else
|
62
|
-
puts "#{k}: #{v}"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|