cadun 0.2.2 → 0.2.3

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.
data/lib/cadun/user.rb CHANGED
@@ -2,7 +2,7 @@ module Cadun
2
2
  class User
3
3
  attr_reader :gateway
4
4
 
5
- { "id" => "id",
5
+ { "id" => "user_id",
6
6
  "nome" => "name",
7
7
  "emailPrincipal" => "email",
8
8
  "tipoUsuario" => "user_type",
@@ -10,10 +10,13 @@ module Cadun
10
10
  "bairro" => "neighborhood",
11
11
  "cidade/nome" => "city",
12
12
  "estado/sigla" => "state",
13
- "pais/nome" => "country" }.each do |path, method|
13
+ "pais/nome" => "country",
14
+ "cep" => "zipcode" }.each do |path, method|
14
15
  define_method(method) { gateway.content.xpath(path).text }
15
16
  end
16
17
 
18
+ alias :id :user_id
19
+
17
20
  def initialize(options = {})
18
21
  @gateway = Gateway.new(options)
19
22
  end
@@ -34,6 +37,10 @@ module Cadun
34
37
  "#{telefoneCelularDdd} #{telefoneCelular}"
35
38
  end
36
39
 
40
+ def to_hash
41
+ %w(user_id name email user_type gender neighborhood city state country address birthday phone mobile login cpf zipcode status).inject(Hash.new(0)) { |hash, method| hash[method.to_sym] = send(method); hash }
42
+ end
43
+
37
44
  def method_missing(method)
38
45
  gateway.content.xpath(method.to_s).text
39
46
  end
data/lib/cadun/version.rb CHANGED
@@ -2,7 +2,7 @@ module Cadun
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY] * '.'
8
8
  end
@@ -53,13 +53,15 @@ describe Cadun::User do
53
53
  verify_method "country", "Brasil"
54
54
 
55
55
  verify_method "user_type", "NAO_ASSINANTE"
56
+
57
+ verify_method "user_id", "21737810"
56
58
  end
57
59
 
58
60
  context "when the user id is given" do
59
- subject { Cadun::User.new :user_id => "10001000", :ip => "127.0.0.1" }
61
+ subject { Cadun::User.new :user_id => "10001000" }
60
62
 
61
63
  it "should load the gateway" do
62
- mock(Cadun::Gateway).new(hash_including(:ip => "127.0.0.1", :user_id => "10001000"))
64
+ mock(Cadun::Gateway).new(hash_including(:user_id => "10001000"))
63
65
  subject
64
66
  end
65
67
 
@@ -67,4 +69,26 @@ describe Cadun::User do
67
69
 
68
70
  verify_method "name", "Guilherme Chico"
69
71
  end
72
+
73
+ describe "#to_hash" do
74
+ subject { Cadun::User.new(:user_id => "10001000").to_hash }
75
+
76
+ specify { should include(:user_id => "10001000") }
77
+ specify { should include(:name => "Guilherme Chico") }
78
+ specify { should include(:email => "fab1@spam.la") }
79
+ specify { should include(:user_type => "NAO_ASSINANTE") }
80
+ specify { should include(:gender => "MASCULINO") }
81
+ specify { should include(:neighborhood => "Andaraí") }
82
+ specify { should include(:city => "Rio de Janeiro") }
83
+ specify { should include(:state => "RJ") }
84
+ specify { should include(:country => "Brasil") }
85
+ specify { should include(:address => "Rua Uruguai, 59") }
86
+ specify { should include(:birthday => Date.new(1983, 02, 22)) }
87
+ specify { should include(:phone => "21 22881060") }
88
+ specify { should include(:mobile => "21 99999999") }
89
+ specify { should include(:login => "fabricio_fab1") }
90
+ specify { should include(:cpf => "09532034765") }
91
+ specify { should include(:zipcode => "20510060") }
92
+ specify { should include(:status => "ATIVO") }
93
+ end
70
94
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cadun
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.2
5
+ version: 0.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bruno