intelipost 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +5 -0
- data/intelipost.gemspec +1 -0
- data/lib/intelipost.rb +3 -0
- data/lib/intelipost/cep.rb +5 -0
- data/lib/intelipost/client.rb +54 -0
- data/lib/intelipost/fluent_interface.rb +32 -0
- data/lib/intelipost/version.rb +1 -1
- data/spec/lib/intelipost/cep_spec.rb +12 -0
- data/spec/lib/intelipost/client_spec.rb +41 -0
- data/spec/spec_helper.rb +26 -0
- metadata +26 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c193215181b741e2bf5f458233728acf3e08342
|
4
|
+
data.tar.gz: 13241a8a94899805bca60720d5b09ec06523a28e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 856e00cddf24e9d51264dcb74a5a5059c2e3046d6e17c55d79a336d378211bd37451631be0229015a52428ea2b44edb57e96e306923ee8ca6965503d74044539
|
7
|
+
data.tar.gz: b04e81f87b0f341a62028d9f1637e1a2185f27ccaa2b58a739080914736af3234630f868dd69664a1781304162a1f1317e7414503325e8f70b7e451d8660ede6
|
data/.gitignore
CHANGED
data/README.md
CHANGED
data/intelipost.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "faraday", "~> 0.9.1"
|
22
22
|
spec.add_dependency "faraday_middleware", "~> 0.9.1"
|
23
23
|
spec.add_dependency "hashie", "~> 3.4.1"
|
24
|
+
spec.add_dependency "dotenv", "~> 2.0.1"
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.9.4"
|
26
27
|
spec.add_development_dependency "rake", "~> 10.4.2"
|
data/lib/intelipost.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Intelipost
|
2
|
+
class Client
|
3
|
+
HOST = 'api.intelipost.com.br'
|
4
|
+
SERVICE = 'api/'
|
5
|
+
API_VERSION = 'v1'
|
6
|
+
attr_reader :uri, :options, :connection, :api_key
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@options = {ssl: true}
|
10
|
+
@options.merge! options
|
11
|
+
uri = @options[:ssl] ? 'https://' : 'http://'
|
12
|
+
uri.concat HOST
|
13
|
+
|
14
|
+
@uri = URI.join uri, SERVICE, API_VERSION
|
15
|
+
@api_key = @options[:api_key]
|
16
|
+
|
17
|
+
@connection = connection
|
18
|
+
end
|
19
|
+
|
20
|
+
def connection
|
21
|
+
raise ArgumentError, 'an api_key is required to connect' if api_key.nil?
|
22
|
+
Faraday.new(url: @uri.to_s) do |conn|
|
23
|
+
conn.request :json
|
24
|
+
|
25
|
+
conn.response :json
|
26
|
+
|
27
|
+
conn.headers['api_key'] = api_key
|
28
|
+
conn.adapter Faraday.default_adapter
|
29
|
+
conn.proxy @options[:proxy]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def get(endpoint, args={})
|
34
|
+
connection.get(endpoint, args).body
|
35
|
+
end
|
36
|
+
|
37
|
+
def method_missing(method, *args, &block)
|
38
|
+
method = camelize method
|
39
|
+
if Intelipost.const_defined? method
|
40
|
+
return Intelipost.const_get(method).new self
|
41
|
+
else
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def camelize(term)
|
47
|
+
string = term.to_s
|
48
|
+
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
|
49
|
+
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
|
50
|
+
string.gsub!('/', '::')
|
51
|
+
string
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Intelipost
|
2
|
+
module FluentInterface
|
3
|
+
module ClassMethods
|
4
|
+
def set_endpoint endpoint
|
5
|
+
define_method :endpoint do
|
6
|
+
endpoint
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
def method_missing(method, *args, &block)
|
13
|
+
uri = [endpoint, method, args].join '/'
|
14
|
+
connection.get uri
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class FluentInterfaceBase
|
20
|
+
extend Intelipost::FluentInterface::ClassMethods
|
21
|
+
include Intelipost::FluentInterface::InstanceMethods
|
22
|
+
attr_accessor :connection
|
23
|
+
|
24
|
+
def initialize(connection)
|
25
|
+
@connection = connection
|
26
|
+
end
|
27
|
+
|
28
|
+
def spawn
|
29
|
+
clone
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/intelipost/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Intelipost::Cep do
|
4
|
+
subject { Intelipost::Cep.new double('Intelipost::Client') }
|
5
|
+
|
6
|
+
describe '#address_complete' do
|
7
|
+
it 'correctly queries the cep' do
|
8
|
+
expect(subject.connection).to receive(:get).with('cep_location/address_complete/00000000')
|
9
|
+
subject.address_complete '00000000'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Intelipost::Client, :vcr do
|
4
|
+
it 'raises ArgumentError if initialized with no options' do
|
5
|
+
expect do
|
6
|
+
Intelipost::Client.new
|
7
|
+
end.to raise_error ArgumentError
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'raises ArgumentError if initialized without credentials' do
|
11
|
+
expect do
|
12
|
+
Intelipost::Client.new api_key: nil
|
13
|
+
end.to raise_error ArgumentError
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'initialized with credentials' do
|
17
|
+
subject { Intelipost::Client.new api_key: ENV['INTELIPOST_API_KEY'] }
|
18
|
+
|
19
|
+
describe '#connection' do
|
20
|
+
it 'is an instance of Faraday::Connection' do
|
21
|
+
expect(subject.connection).to be_an_instance_of Faraday::Connection
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has the api_key header on the request' do
|
25
|
+
expect(subject.connection.headers).to include('api_key')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#options' do
|
30
|
+
it 'includes api_key' do
|
31
|
+
expect(subject.options).to include(:api_key)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#cep' do
|
36
|
+
it 'returns an correct response' do
|
37
|
+
expect(subject.cep.address_complete('04661100')).to include('content')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'dotenv'
|
3
|
+
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter '/spec'
|
6
|
+
end if ENV["COVERAGE"]
|
7
|
+
|
8
|
+
require File.expand_path("../../lib/intelipost", __FILE__)
|
9
|
+
require 'intelipost'
|
10
|
+
require 'vcr'
|
11
|
+
|
12
|
+
Dotenv.load
|
13
|
+
|
14
|
+
VCR.configure do |c|
|
15
|
+
c.cassette_library_dir = 'spec/cassettes'
|
16
|
+
c.hook_into :webmock
|
17
|
+
c.configure_rspec_metadata!
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.expect_with :rspec do |c|
|
22
|
+
c.syntax = :expect
|
23
|
+
end
|
24
|
+
|
25
|
+
config.order = "random"
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intelipost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo Sampaio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.4.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.1
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,7 +164,13 @@ files:
|
|
150
164
|
- Rakefile
|
151
165
|
- intelipost.gemspec
|
152
166
|
- lib/intelipost.rb
|
167
|
+
- lib/intelipost/cep.rb
|
168
|
+
- lib/intelipost/client.rb
|
169
|
+
- lib/intelipost/fluent_interface.rb
|
153
170
|
- lib/intelipost/version.rb
|
171
|
+
- spec/lib/intelipost/cep_spec.rb
|
172
|
+
- spec/lib/intelipost/client_spec.rb
|
173
|
+
- spec/spec_helper.rb
|
154
174
|
homepage: http://github.com/natuelabs/intelipost
|
155
175
|
licenses:
|
156
176
|
- MIT
|
@@ -175,4 +195,7 @@ rubygems_version: 2.2.2
|
|
175
195
|
signing_key:
|
176
196
|
specification_version: 4
|
177
197
|
summary: Gem to access the REST API of Intelipost
|
178
|
-
test_files:
|
198
|
+
test_files:
|
199
|
+
- spec/lib/intelipost/cep_spec.rb
|
200
|
+
- spec/lib/intelipost/client_spec.rb
|
201
|
+
- spec/spec_helper.rb
|