bipbop 0.3.0 → 0.4.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: 10b1bcef3727064a83dbb4e9a582851a08046e33
4
- data.tar.gz: 7c9fe89c3e2679c8880e84104fe026bcf903c107
3
+ metadata.gz: 76f3eb74882dd4c18ca1e8375d3752b40ad8d609
4
+ data.tar.gz: 4dc532e2754b98ca036623542915ef3dbe4bd045
5
5
  SHA512:
6
- metadata.gz: abed2a1a3e7b8b4cb3bdcddf18373e6d57477793e3fe243dbbece7b39f45fd4bff00a05568e725151326086103beb07a7e1c4042d8b5c939bdfb2f98b1053e63
7
- data.tar.gz: 37d89ad2c7c3f17c6dc27f42e97e2793c6b7641e7de5d35b9dd4911c326550c680c19e0fa69bb72818bb1104f7f046ba4ca523fd7303b6f0ed5513abc14e0eac
6
+ metadata.gz: 129256e5981f7589bdaef461f5dda86702ca8bbc585d5c7be4855ffa8cf9ee1d394f056827b14d3b81e63dd30be5fe0909a09b9d49796ced07461c0e0194012d
7
+ data.tar.gz: f3ae5820e884c0f389fce6be06752d510f6cd0c229348fc2445a5f3aca424e5044b18fe46aa0320d133b32ba1f040139e769de6c44e270f86b566579ba476a72
data/README.md CHANGED
@@ -24,23 +24,23 @@ Ruby Wrapper for [bipbop](http://bipbop.com.br)
24
24
 
25
25
  ```ruby
26
26
  bipbop = Bipbop.new('my api key')
27
- bipbop.cpfcnpj('99999999999') # where 99999999999 is the number of one cpf
28
- => "NAME OF PERSON"
27
+ bipbop.cpfcnpj(documento: '99999999999') # where 99999999999 is the number of one cpf
28
+ => { "nome" => "NAME OF PERSON" }
29
29
  ```
30
30
 
31
31
  ### CNPJ
32
32
 
33
33
  ```ruby
34
34
  bipbop = Bipbop.new('my api key')
35
- bipbop.cpfcnpj('99999999000100') # where 99999999000100 is the number of cnpj
36
- => "NAME OF COMPANY LTDA"
35
+ bipbop.cpfcnpj(documento: '99999999000100') # where 99999999000100 is the number of cnpj
36
+ => { "nome" => "NAME OF COMPANY LTDA" }
37
37
  ```
38
38
 
39
39
  ### SOCIAL
40
40
 
41
41
  ```ruby
42
42
  bipbop = Bipbop.new('my api key')
43
- bipbop.social(document: '99999999999', email: 'user@example.com')
43
+ bipbop.social(documento: '99999999999', email: 'user@example.com')
44
44
  => {
45
45
  "name" => {
46
46
  "__content__" => "NAME OF PERSON",
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bipbop 0.3.0 ruby lib
5
+ # stub: bipbop 0.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bipbop"
9
- s.version = "0.3.0"
9
+ s.version = "0.4.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  "spec/fixtures/vcr_cassettes/bipbop/cpfcnpj/invalid.yml",
37
37
  "spec/fixtures/vcr_cassettes/bipbop/cpfcnpj/valid-cnpj.yml",
38
38
  "spec/fixtures/vcr_cassettes/bipbop/cpfcnpj/valid-cpf.yml",
39
+ "spec/fixtures/vcr_cassettes/bipbop/social/invalid.yml",
39
40
  "spec/fixtures/vcr_cassettes/bipbop/social/valid-document-and-email.yml",
40
41
  "spec/fixtures/vcr_cassettes/bipbop/social/valid-document.yml",
41
42
  "spec/spec_helper.rb",
@@ -4,33 +4,37 @@ class Bipbop
4
4
  include HTTParty
5
5
  base_uri 'irql.bipbop.com.br'
6
6
 
7
- attr_reader :api_key, :response
7
+ attr_reader :api_key
8
8
 
9
9
  def initialize(api_key = nil)
10
10
  @api_key = api_key || ENV['BIPBOP_API_KEY']
11
11
  end
12
12
 
13
- def cpfcnpj(document)
14
- request("SELECT FROM 'BIPBOPJS'.'CPFCNPJ' WHERE 'DOCUMENTO' = '#{document}'")
15
- (response.code == 200) ? response["IRQL"]['body']['nome'] : nil
13
+ def cpfcnpj(params)
14
+ request(:bipbopjs, :cpfcnpj, params)
16
15
  end
17
16
 
18
17
  def social(params)
19
- conditions = []
20
- conditions << "'DOCUMENTO' = '#{params[:document]}'" if params[:document]
21
- conditions << "'EMAIL' = '#{params[:email]}'" if params[:email]
22
- response = request("SELECT FROM 'SOCIAL'.'CONSULTA' WHERE #{conditions.join(" AND ")}")
23
- (response.code == 200) ? response["IRQL"]['body'] : nil
18
+ request(:social, :consulta, params)
24
19
  end
25
20
 
26
21
  private
27
22
 
28
- def request(irql)
29
- @response = self.class.get("/", query(irql))
23
+ def irql(database, table, params)
24
+ conditions = []
25
+ params.each_pair do |key, value|
26
+ conditions << "'#{key.upcase}' = '#{value}'"
27
+ end
28
+ "SELECT FROM '#{database.upcase}'.'#{table.upcase}' WHERE #{conditions.join(" AND ")}"
30
29
  end
31
30
 
32
- def query(irql)
33
- { :query => {'q' => irql, 'apiKey' => @api_key}}
31
+ def request(database, table, params)
32
+ response = self.class.get("/", query(irql(database, table, params)))
33
+ (response.code == 200) ? response["IRQL"]['body'] : nil
34
+ end
35
+
36
+ def query(q)
37
+ { :query => {'q' => q, 'apiKey' => @api_key}}
34
38
  end
35
39
 
36
40
  end
@@ -16,21 +16,24 @@ describe "Bipbop" do
16
16
  end
17
17
  describe 'cpfcnpj' do
18
18
  context 'invalid', vcr: { cassette_name: 'bipbop/cpfcnpj/invalid' } do
19
- it { bipbop.cpfcnpj('99999999999').should be_nil }
19
+ it { bipbop.cpfcnpj(documento: '99999999999').should be_nil }
20
20
  end
21
21
  context 'valid cpf', vcr: { cassette_name: 'bipbop/cpfcnpj/valid-cpf' } do
22
- it { bipbop.cpfcnpj('09116059751').should == 'RAFAEL DE LIMA PAULA' }
22
+ it { bipbop.cpfcnpj(documento: '09116059751').should == {"nome"=>'RAFAEL DE LIMA PAULA'} }
23
23
  end
24
24
  context 'valid cnpj', vcr: { cassette_name: 'bipbop/cpfcnpj/valid-cnpj' } do
25
- it { bipbop.cpfcnpj('05813794000126').should == 'BOLETO SIMPLES COBRANCAS LTDA - ME' }
25
+ it { bipbop.cpfcnpj(documento: '05813794000126').should == {"nome"=>'BOLETO SIMPLES COBRANCAS LTDA - ME'} }
26
26
  end
27
27
  end
28
28
  describe 'social' do
29
+ context 'invalid', vcr: { cassette_name: 'bipbop/social/invalid' } do
30
+ it { bipbop.social(documento: '9').should == {"influence"=>"20", "confidence"=>"42", "confidence_influence"=>"43", "confidence_criteria"=>"40"} }
31
+ end
29
32
  context 'document', vcr: { cassette_name: 'bipbop/social/valid-document' } do
30
- it { bipbop.social(document: '09116059751').should == {"name"=>{"__content__"=>"RAFAEL DE LIMA PAULA", "gender"=>"male"}, "approximate_age"=>"30", "hash"=>"6CzXsZA09xMgXrHmJHUNY5X0cu7fv5yXwPGVX/i7nVE6awYftn5LpsVvdeoqbuMfBGdKIm0t1F+jrdifMraoyA==", "criteria"=>"A1", "buy_limit"=>"10214.87", "buy_avg"=>"268.33", "influence"=>"52", "confidence"=>"57", "confidence_influence"=>"56", "confidence_criteria"=>"59"} }
33
+ it { bipbop.social(documento: '09116059751').should == {"name"=>{"__content__"=>"RAFAEL DE LIMA PAULA", "gender"=>"male"}, "approximate_age"=>"30", "hash"=>"6CzXsZA09xMgXrHmJHUNY5X0cu7fv5yXwPGVX/i7nVE6awYftn5LpsVvdeoqbuMfBGdKIm0t1F+jrdifMraoyA==", "criteria"=>"A1", "buy_limit"=>"10214.87", "buy_avg"=>"268.33", "influence"=>"52", "confidence"=>"57", "confidence_influence"=>"56", "confidence_criteria"=>"59"} }
31
34
  end
32
35
  context 'document with email', vcr: { cassette_name: 'bipbop/social/valid-document-and-email' } do
33
- it { bipbop.social(document: '09116059751', email: 'contato@rafael.adm.br').should == {"name"=>{"__content__"=>"RAFAEL DE LIMA PAULA", "gender"=>"male"}, "approximate_age"=>"30", "hash"=>"D9C1OOc/DF5kubLGgKxSDlGL3owYz9+eZx/Wz423G3U5lj+ZqfZF7fv3f2m4GNEHSkwFpEFuaX90fCB4Vug8EA==", "criteria"=>"A1", "buy_limit"=>"10214.87", "buy_avg"=>"268.33", "influence"=>"52", "confidence"=>"57", "confidence_influence"=>"56", "confidence_criteria"=>"59"} }
36
+ it { bipbop.social(documento: '09116059751', email: 'contato@rafael.adm.br').should == {"name"=>{"__content__"=>"RAFAEL DE LIMA PAULA", "gender"=>"male"}, "approximate_age"=>"30", "hash"=>"D9C1OOc/DF5kubLGgKxSDlGL3owYz9+eZx/Wz423G3U5lj+ZqfZF7fv3f2m4GNEHSkwFpEFuaX90fCB4Vug8EA==", "criteria"=>"A1", "buy_limit"=>"10214.87", "buy_avg"=>"268.33", "influence"=>"52", "confidence"=>"57", "confidence_influence"=>"56", "confidence_criteria"=>"59"} }
34
37
  end
35
38
  end
36
39
  end
@@ -0,0 +1,51 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://irql.bipbop.com.br/?apiKey=BIPBOP_API_KEY&q=SELECT%20FROM%20'SOCIAL'.'CONSULTA'%20WHERE%20'DOCUMENTO'%20=%20'9'
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Cache-Control:
16
+ - no-cache="set-cookie"
17
+ - public
18
+ Content-Type:
19
+ - text/xml
20
+ Date:
21
+ - Fri, 03 Oct 2014 03:38:19 GMT
22
+ Expires:
23
+ - Sat, 04 Oct 2014 03:38:14 GMT
24
+ Server:
25
+ - bipbop
26
+ Set-Cookie:
27
+ - AWSELB=AB014DFB0639528854AECF5F443FF4231F941D340774F350D54A5846185FBE31D8DBA5572864AEB083A406D8BC20545C7EF0A812122A8B2F9155C493CB14894B2CE2B49520;PATH=/;MAX-AGE=86400
28
+ Content-Length:
29
+ - '456'
30
+ Connection:
31
+ - keep-alive
32
+ body:
33
+ encoding: UTF-8
34
+ string: |
35
+ <?xml version="1.0" encoding="UTF-8"?>
36
+ <IRQL>
37
+ <header>
38
+ <date-time>03/10/2014 00:38:14</date-time>
39
+ <execution-time>5</execution-time>
40
+ <query database="SOCIAL" table="CONSULTA">SELECT FROM 'SOCIAL'.'CONSULTA' WHERE 'DOCUMENTO' = '9'</query>
41
+ </header>
42
+ <body>
43
+ <influence>20</influence>
44
+ <confidence>42</confidence>
45
+ <confidence-influence>43</confidence-influence>
46
+ <confidence-criteria>40</confidence-criteria>
47
+ </body>
48
+ </IRQL>
49
+ http_version:
50
+ recorded_at: Fri, 03 Oct 2014 03:38:16 GMT
51
+ recorded_with: VCR 2.9.3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bipbop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Lima
@@ -190,6 +190,7 @@ files:
190
190
  - spec/fixtures/vcr_cassettes/bipbop/cpfcnpj/invalid.yml
191
191
  - spec/fixtures/vcr_cassettes/bipbop/cpfcnpj/valid-cnpj.yml
192
192
  - spec/fixtures/vcr_cassettes/bipbop/cpfcnpj/valid-cpf.yml
193
+ - spec/fixtures/vcr_cassettes/bipbop/social/invalid.yml
193
194
  - spec/fixtures/vcr_cassettes/bipbop/social/valid-document-and-email.yml
194
195
  - spec/fixtures/vcr_cassettes/bipbop/social/valid-document.yml
195
196
  - spec/spec_helper.rb