kiik-api 0.1.6 → 0.1.8

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: 8e7ffc528b6f4d1485fa33fb1a22f594ee0d94e8
4
- data.tar.gz: 1d792e7ae88496a52cb0278eee1328191e892f47
3
+ metadata.gz: e1928ec5fdddfe6440469a3de2bcf50963694dac
4
+ data.tar.gz: b634864088e68a781a945b6c0dd6aa8114a6043c
5
5
  SHA512:
6
- metadata.gz: b2975f6e9d5acecee753f6ccb2a7b87109e04ca4557cf25254298c4376c0342bca9b457617589d0ebaf72d840ac3b532b68689344b64d88fd614ec32012fe3ba
7
- data.tar.gz: bc43f2109bffceeaeb26560dc14f3b43f8d0566562dfad4b83165e9ed3d75273d6b2d82a152995ec181c9f6edad99d4b527faabb3951f6608c24fe8580a5abda
6
+ metadata.gz: 97828038a43c69b829f2d61c3eb403e50cf987ab304fe5c7362db3d3659c341913a4122503f2e98ba2adcdf6c846573d71f734042e89dcf8c5a0a09896ec5136
7
+ data.tar.gz: 77167f69cfe54bcea633ceb8555c98e37abf4706224950334d75e7443ef6f9545860532193c57208c4f8b7fedbc56d0b9da3467864db500d24e8c9ea7075dd0f
@@ -23,10 +23,10 @@ require 'kiik/wallet/transaction'
23
23
  module Kiik
24
24
  # set a default
25
25
 
26
- class << self
26
+ class << self
27
27
  attr_accessor :config_path
28
28
  end
29
-
29
+
30
30
  def self.config
31
31
  @config ||= load_config
32
32
  end
@@ -36,8 +36,8 @@ module Kiik
36
36
  @wallet.api
37
37
  end
38
38
 
39
- def self.load_config
40
-
39
+ def self.load_config
40
+
41
41
  if @config_path.nil?
42
42
  if defined?(Rails)
43
43
  @config_path = Rails.root.join('config','kiik.yml')
@@ -49,7 +49,7 @@ module Kiik
49
49
  unless File.file?(config_path)
50
50
  raise NotConfigured.new("The #{config_path} config file is missing.")
51
51
  end
52
-
52
+
53
53
  cfg = YAML.load_file(config_path)
54
54
  raise NoAuthorizationTokenProvided.new("You will need a authorization token to perform request on kiik api") if cfg[:token].nil?
55
55
  cfg
@@ -53,46 +53,27 @@ EvrRI5YPv5wN8nlFUzeaVi/oVxBw9u6JDEmJmsEj9cIqzEHPIqtlbreUgm0vQF9Y
53
53
  huNMrUnjl1nOG5srztxl1Asoa06ERlFE9zMILViXIa4=
54
54
  -----END CERTIFICATE-----
55
55
  -----BEGIN CERTIFICATE-----
56
- MIIERTCCA66gAwIBAgIQM2VQCHmtc+IwueAdDX+skTANBgkqhkiG9w0BAQUFADCB
57
- zjELMAkGA1UEBhMCWkExFTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJ
58
- Q2FwZSBUb3duMR0wGwYDVQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UE
59
- CxMfQ2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UEAxMYVGhh
60
- d3RlIFByZW1pdW0gU2VydmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNl
61
- cnZlckB0aGF3dGUuY29tMB4XDTA2MTExNzAwMDAwMFoXDTIwMTIzMDIzNTk1OVow
62
- gakxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwx0aGF3dGUsIEluYy4xKDAmBgNVBAsT
63
- H0NlcnRpZmljYXRpb24gU2VydmljZXMgRGl2aXNpb24xODA2BgNVBAsTLyhjKSAy
64
- MDA2IHRoYXd0ZSwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MR8wHQYD
65
- VQQDExZ0aGF3dGUgUHJpbWFyeSBSb290IENBMIIBIjANBgkqhkiG9w0BAQEFAAOC
66
- AQ8AMIIBCgKCAQEArKDw+4BZ1JzHpM+doVlzCRBFDA0sbmjxbFtIaElZN/wLMxnC
67
- d3/MEC2VNBzm600JpxzSuMmXNgK3idQkXwbAzESUlI0CYm/rWt0RjSiaXISQEHoN
68
- vXRmL2o4oOLVVETrHQefB7pv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J3rG9XRbkREqaYB7FViHXe4XI5ISXycO1cRrK1zN44veFyQaEfZYGDm/Ac9IiAX
75
+ xPcW6cTYcvnIc3zfFi8VqT79aie2oetaupgf1eNNZAqdE8hhuvU5HIe6uL17In/2
76
+ /qxAeeWsEG89jxt5dovEN7MhGITlNgDrYyCZuen+MwS7QcjBAvlEYyCegc5C09Y/
77
+ LHbTY5xZ3Y+m4Q6gLkH3LpVHz7z9M/P2C2F+fpErgUfCJzDupxBdN49cOSvkBPB7
78
+ jVaMaA==
98
79
  -----END CERTIFICATE-----
@@ -2,10 +2,10 @@ module Kiik
2
2
 
3
3
  class Client
4
4
 
5
- attr_reader :site
5
+ attr_reader :site
6
6
  attr_accessor :token, :options
7
7
 
8
- def initialize(token, options={}, &block)
8
+ def initialize(token, options={}, &block)
9
9
  opts = options.dup
10
10
  @token = token
11
11
  @site = opts.delete(:site)
@@ -15,7 +15,7 @@ module Kiik
15
15
  :max_redirects => 5,
16
16
  :raise_errors => true}.merge(opts)
17
17
  @options[:connection_opts][:ssl] = ssl if ssl
18
- end
18
+ end
19
19
 
20
20
  def site=(value)
21
21
  @connection = nil
@@ -41,7 +41,7 @@ module Kiik
41
41
  connection.response :logger, ::Logger.new($stdout) if ENV['OAUTH_DEBUG'] == 'true'
42
42
 
43
43
  url = connection.build_url(url, opts[:params]).to_s
44
-
44
+
45
45
  Kiik::Logger.info(url)
46
46
 
47
47
  response = connection.run_request(verb, url, opts[:body], authorization_header(opts[:headers])) do |req|
@@ -1,10 +1,10 @@
1
1
  module Kiik
2
-
3
- class NotConfigured < Exception
4
- end
5
-
6
- class NoAuthorizationTokenProvided < Exception
7
- end
2
+
3
+ class NotConfigured < Exception
4
+ end
5
+
6
+ class NoAuthorizationTokenProvided < Exception
7
+ end
8
8
 
9
9
  class TypeNotSupported < Exception
10
10
  end
@@ -12,7 +12,7 @@ module Kiik
12
12
  class MethodNotAllowedForType < Exception
13
13
  end
14
14
 
15
- class Error < StandardError
15
+ class Error < StandardError
16
16
  attr_reader :response, :code, :description
17
17
 
18
18
  # standard error values include:
@@ -1,5 +1,5 @@
1
1
  module Kiik
2
- class Logger
2
+ class Logger
3
3
  def self.info(msg)
4
4
  puts "Kiik::INFO: #{msg}"
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module Kiik
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -1,12 +1,12 @@
1
1
  module Kiik
2
2
 
3
- class Wallet
3
+ class Wallet
4
4
  attr_reader :token, :site, :version
5
5
  attr_accessor :logger, :options
6
6
 
7
7
  def initialize(token,options={})
8
- @site = 'https://wallet.kiik.com.br'
9
- @version = 'v1'
8
+ @site = options.delete(:url) || 'https://wallet.kiik.com.br'
9
+ @version = options.delete(:version) || 'v1'
10
10
  @token = token
11
11
  @ca_file = options.delete(:ca_file) || default_ca_file
12
12
  @logger = options.delete(:logger) || Kiik::Logger
@@ -1,122 +1,125 @@
1
1
  module Kiik
2
- class Wallet
3
- class Client
4
-
5
- ALLOWED_TYPES = {
6
- :client => [ :create, :detail ],
7
- :user => [ :create ],
8
- :creditcard => [ :create, :detail ],
9
- :transaction => [ :create ]
10
- }
11
-
12
- attr_reader :name, :id, :secret, :access_token, :email
13
-
14
- def initialize(wallet,options)
15
- @id = options[:api_id]
16
- @name = options[:name]
17
- @email = options[:email]
18
- @secret = options[:api_secret]
19
- @access_token = options[:access_token]
20
- @wallet = wallet
21
- @base_uri = '/clients/#{id}'
22
- end
23
-
24
- def token
25
- @wallet.token
26
- end
27
-
28
- def client
29
- @wallet.client
30
- end
31
-
32
- def use_token(new_token,&block)
33
- @wallet.client.token = new_token
34
- block.call(self)
35
- @wallet.client.token = @wallet.token
36
- end
37
-
38
- def detail(type,options={},&block)
39
- allow(type,:detail)
40
-
41
- case type
42
- when :client
43
- request(:get, base_uri,{}, &block)
44
- when :creditcard
45
- token = options.delete(:token)
46
- card.detail(token,options,&block)
47
- end
48
-
49
- end
50
-
51
- def list(type,options={},&block)
52
- allow(type,:list)
53
-
54
- case type
55
- when :creditcard
56
- token = options.delete(:token)
57
- card.list(token,&block)
58
- end
59
-
60
- end
61
-
62
- def set_secret(secret,&block)
63
- request(:put, base_uri, { :client => { :api_secret => secret } },&block)
64
- end
65
-
66
- def create(type, options={},&block)
67
- allow(type,:create)
68
-
69
- token = options.delete(:token)
70
- case type
71
- when :user
72
- user.create(options,&block)
73
- when :creditcard
74
- card.create(token,options,&block)
75
- when :transaction
76
- transaction.create(token,options.delete(:credit_card),options,&block)
77
- end
78
- end
79
-
80
- def user
81
- @user ||= Kiik::Wallet::User.new(self)
82
- end
83
-
84
- def card
85
- @card ||= Kiik::Wallet::Creditcard.new(self)
86
- end
87
-
88
- def transaction
89
- @transaction ||= Kiik::Wallet::Transaction.new(self)
90
- end
91
-
92
- def request(verb, uri, params = {}, &block)
93
- response = @wallet.client.request(verb, "/#{@wallet.version}#{uri}", request_params(params))
94
-
95
- if block_given?
96
- yield(response.parsed)
97
- else
98
- response.parsed
99
- end
100
- end
101
-
102
- private
103
- def allow(type,method)
104
- raise TypeNotSupported.new("The #{type} is not supported by this api") if !ALLOWED_TYPES.include?(type)
105
- raise MethodNotAllowedForType.new("This type: #{type} don't allow this method.") if !ALLOWED_TYPES[type].include?(method)
106
- end
107
-
108
- def request_params(params={})
109
- p = {
110
- :params => {},
111
- :body => params.to_json,
112
- :headers => {
113
- 'Accept' => 'application/json',
114
- 'Content-type' => 'application/json'
115
- }
116
- }
117
- p
118
- end
119
-
120
- end
121
- end
2
+ class Wallet
3
+ class Client
4
+
5
+ ALLOWED_TYPES = {
6
+ :client => [ :create, :detail ],
7
+ :user => [ :create ],
8
+ :creditcard => [ :create, :detail ],
9
+ :transaction => [ :create ]
10
+ }
11
+
12
+ attr_reader :name, :id, :secret, :access_token, :email
13
+
14
+ def initialize(wallet,options)
15
+ @id = options[:api_id]
16
+ @name = options[:name]
17
+ @email = options[:email]
18
+ @secret = options[:api_secret]
19
+ @access_token = options[:access_token]
20
+ @wallet = wallet
21
+ @base_uri = '/clients/#{id}'
22
+ end
23
+
24
+ def token
25
+ @wallet.token
26
+ end
27
+
28
+ def client
29
+ @wallet.client
30
+ end
31
+
32
+ def use_token(new_token,&block)
33
+ @wallet.client.token = new_token
34
+ begin
35
+ block.call(self)
36
+ ensure
37
+ @wallet.client.token = @wallet.token
38
+ end
39
+ end
40
+
41
+ def detail(type,options={},&block)
42
+ allow(type,:detail)
43
+
44
+ case type
45
+ when :client
46
+ request(:get, base_uri,{}, &block)
47
+ when :creditcard
48
+ token = options.delete(:token)
49
+ card.detail(token,options,&block)
50
+ end
51
+
52
+ end
53
+
54
+ def list(type,options={},&block)
55
+ allow(type,:list)
56
+
57
+ case type
58
+ when :creditcard
59
+ token = options.delete(:token)
60
+ card.list(token,&block)
61
+ end
62
+
63
+ end
64
+
65
+ def set_secret(secret,&block)
66
+ request(:put, base_uri, { :client => { :api_secret => secret } },&block)
67
+ end
68
+
69
+ def create(type, options={},&block)
70
+ allow(type,:create)
71
+
72
+ token = options.delete(:token)
73
+ case type
74
+ when :user
75
+ user.create(options,&block)
76
+ when :creditcard
77
+ card.create(token,options,&block)
78
+ when :transaction
79
+ transaction.create(token,options.delete(:credit_card),options,&block)
80
+ end
81
+ end
82
+
83
+ def user
84
+ @user ||= Kiik::Wallet::User.new(self)
85
+ end
86
+
87
+ def card
88
+ @card ||= Kiik::Wallet::Creditcard.new(self)
89
+ end
90
+
91
+ def transaction
92
+ @transaction ||= Kiik::Wallet::Transaction.new(self)
93
+ end
94
+
95
+ def request(verb, uri, params = {}, &block)
96
+ response = @wallet.client.request(verb, "/#{@wallet.version}#{uri}", request_params(params))
97
+
98
+ if block_given?
99
+ yield(response.parsed)
100
+ else
101
+ response.parsed
102
+ end
103
+ end
104
+
105
+ private
106
+ def allow(type,method)
107
+ raise TypeNotSupported.new("The #{type} is not supported by this api") if !ALLOWED_TYPES.include?(type)
108
+ raise MethodNotAllowedForType.new("This type: #{type} don't allow this method.") if !ALLOWED_TYPES[type].include?(method)
109
+ end
110
+
111
+ def request_params(params={})
112
+ p = {
113
+ :params => {},
114
+ :body => params.to_json,
115
+ :headers => {
116
+ 'Accept' => 'application/json',
117
+ 'Content-type' => 'application/json'
118
+ }
119
+ }
120
+ p
121
+ end
122
+
123
+ end
124
+ end
122
125
  end
@@ -1,43 +1,43 @@
1
1
  module Kiik
2
- class Wallet
3
- class Creditcard
4
-
5
- def initialize(client)
6
- @client = client
7
- @base_uri = '/cards'
8
- end
9
-
10
- def create(token,options={},&block)
11
- params = {
12
- :card => {
13
- :name => options[:name],
14
- :number => options[:number],
15
- :expiration_month => options[:expiration_month],
16
- :expiration_year => options[:expiration_year]
17
- }
18
- }
19
-
20
- request(token,:post,@base_uri,params,&block)
21
- end
22
-
23
- def list(token,&block)
24
- request(token,:get,@base_uri,{},&block)
25
- end
26
-
27
- def get(token,id,&block)
28
- request(token,:get,"#{@base_uri}/#{id}",{},&block)
29
- end
30
-
31
- def detail(token,id,&block)
32
- request(token,:get,"#{@base_uri}/#{id}/details",{},&block)
33
- end
34
-
35
- private
36
- def request(token,verb,url,params,&block)
37
- proc = Proc.new { |client| client.request(verb,url,params,&block) }
38
- @client.use_token(token, &proc)
39
- end
40
-
41
- end
42
- end
2
+ class Wallet
3
+ class Creditcard
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ @base_uri = '/cards'
8
+ end
9
+
10
+ def create(token,options={},&block)
11
+ params = {
12
+ :card => {
13
+ :name => options[:name],
14
+ :number => options[:number],
15
+ :expiration_month => options[:expiration_month],
16
+ :expiration_year => options[:expiration_year]
17
+ }
18
+ }
19
+
20
+ request(token,:post,@base_uri,params,&block)
21
+ end
22
+
23
+ def list(token,&block)
24
+ request(token,:get,@base_uri,{},&block)
25
+ end
26
+
27
+ def get(token,id,&block)
28
+ request(token,:get,"#{@base_uri}/#{id}",{},&block)
29
+ end
30
+
31
+ def detail(token,id,&block)
32
+ request(token,:get,"#{@base_uri}/#{id}/details",{},&block)
33
+ end
34
+
35
+ private
36
+ def request(token,verb,url,params,&block)
37
+ proc = Proc.new { |client| client.request(verb,url,params,&block) }
38
+ @client.use_token(token, &proc)
39
+ end
40
+
41
+ end
42
+ end
43
43
  end
@@ -1,38 +1,38 @@
1
1
  module Kiik
2
- class Wallet
3
- class Transaction
2
+ class Wallet
3
+ class Transaction
4
4
 
5
- def initialize(client)
6
- @client = client
7
- @base_uri = '/transactions/card'
8
- end
5
+ def initialize(client)
6
+ @client = client
7
+ @base_uri = '/transactions/card'
8
+ end
9
9
 
10
- def create(token,card,options={},&block)
11
- params = {
12
- :card => {
13
- :credit_card_token => card[:token],
14
- :cvv => card[:cvv]
15
- },
16
- :transaction => {
17
- :recipient => options[:recipient],
18
- :amount => options[:amount],
19
- :order_number => options[:order_number]
20
- }
21
- }
10
+ def create(token,card,options={},&block)
11
+ params = {
12
+ :card => {
13
+ :credit_card_token => card[:token],
14
+ :cvv => card[:cvv]
15
+ },
16
+ :transaction => {
17
+ :recipient => options[:recipient],
18
+ :amount => options[:amount],
19
+ :order_number => options[:order_number]
20
+ }
21
+ }
22
22
 
23
- request(token,:post,@base_uri,params,&block)
24
- end
23
+ request(token,:post,@base_uri,params,&block)
24
+ end
25
25
 
26
- def callback(token,params={},&block)
27
- request(token,:put,'/payment/callback',params,&block)
28
- end
26
+ def callback(token,params={},&block)
27
+ request(token,:put,'/payment/callback',params,&block)
28
+ end
29
29
 
30
- private
31
- def request(token,verb,url,params,&block)
32
- proc = Proc.new { |client| client.request(verb,url,params,&block) }
33
- @client.use_token(token, &proc)
34
- end
30
+ private
31
+ def request(token,verb,url,params,&block)
32
+ proc = Proc.new { |client| client.request(verb,url,params,&block) }
33
+ @client.use_token(token, &proc)
34
+ end
35
35
 
36
- end
37
- end
36
+ end
37
+ end
38
38
  end
@@ -1,82 +1,63 @@
1
1
  module Kiik
2
- class Wallet
3
- class User
4
-
5
- attr_reader :token
6
-
7
- def initialize(client)
8
- @client = client
9
- @base_uri = '/users'
10
- @card = Kiik::Wallet::Creditcard.new(client)
11
- end
12
-
13
- def create(options={},&block)
14
- params = {
15
- :user => {
16
- :email => options[:email],
17
- :password => options[:password],
18
- :external_id => options[:id]
19
- }
20
- }
21
- @client.request(:post,@base_uri,request_params(params),&block)
22
- end
23
-
24
- def update(options={},&block)
25
- params = {
26
- :user => {
27
- :email => options[:email],
28
- :password => options[:password],
29
- :new_password => options[:new_password]
30
- }
31
- }
32
- @client.request(:put,"#{@base_uri}/#{options[:id]}",request_params(params),&block)
33
- end
34
-
35
- def set_password(options={},&block)
36
- params = {
37
- :user => {
38
- :email => options[:email],
39
- :password => options[:password],
40
- :new_password => options[:new_password]
41
- }
42
- }
43
- @client.request(:put,"#{@base_uri}/#{options[:id]}",request_params(params),&block)
44
- end
45
-
46
- def login(options={},&block)
47
- params = {
48
- :auth => {
49
- :external_id => options[:id],
50
- :password => options[:password]
51
- }
52
- }
53
- @client.request(:post, '/auth/login', params ) do |response|
54
- @token = response["token"]
55
- block.call(response)
56
- end
57
- end
58
-
59
- def regenerate_token(options={},&block)
60
- params = {
61
- :auth => {
62
- :external_id => options[:id],
63
- :password => options[:password]
64
- }
65
- }
66
- @client.request(:post, '/auth/regenerate_token', params ) do |response|
67
- @token = response["token"]
68
- block.call(response)
69
- end
70
- end
71
-
72
- def create_creditcard(options={},&block)
73
- @card.create(options,&block)
74
- end
75
-
76
- private
77
- def request_params(params={})
78
- params.merge({ :client => { :api_id => @client.id } })
79
- end
80
- end
81
- end
2
+ class Wallet
3
+ class User
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ @base_uri = '/users'
8
+ @card = Kiik::Wallet::Creditcard.new(client)
9
+ end
10
+
11
+ def create(options={},&block)
12
+ params = {
13
+ :user => {
14
+ :email => options[:email],
15
+ :password => options[:password],
16
+ :external_id => options[:id]
17
+ }
18
+ }
19
+ @client.request(:post,@base_uri,request_params(params),&block)
20
+ end
21
+
22
+ def set_password(options={},&block)
23
+ params = {
24
+ :user => {
25
+ :email => options[:email],
26
+ :password => options[:password],
27
+ :new_password => options[:new_password]
28
+ }
29
+ }
30
+ @client.request(:put,"#{@base_uri}/#{options[:id]}",request_params(params),&block)
31
+ end
32
+
33
+ def login(options={},&block)
34
+ params = {
35
+ :auth => {
36
+ :external_id => options[:id],
37
+ :password => options[:password]
38
+ }
39
+ }
40
+ @client.request(:post, '/auth/login', params, &block )
41
+ end
42
+
43
+ def regenerate_token(options={},&block)
44
+ params = {
45
+ :auth => {
46
+ :external_id => options[:id],
47
+ :password => options[:password]
48
+ }
49
+ }
50
+ @client.request(:post, '/auth/regenerate_token', params, &block )
51
+ end
52
+
53
+ def create_creditcard(options={},&block)
54
+ @card.create(options,&block)
55
+ end
56
+
57
+ private
58
+ def request_params(params={})
59
+ params.merge({ :client => { :api_id => @client.id } })
60
+ end
61
+ end
62
+ end
82
63
  end
@@ -1,5 +1,6 @@
1
1
  :token: "098f6bcd4621d373cade4e832627b4f6"
2
2
  :wallet:
3
+ :url: "https://wallet2.kiik.com.br"
3
4
  :name: "Wallet Application"
4
5
  :api_id: "WALT"
5
6
  :api_secret: "b5i32od62d5hadxvopcgsdmipv2g8b"
@@ -1,8 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Kiik do
4
-
5
-
4
+
5
+
6
6
  context 'initialization' do
7
7
 
8
8
  before(:each) do
@@ -50,6 +50,6 @@ describe Kiik do
50
50
  end
51
51
 
52
52
  end
53
-
53
+
54
54
 
55
55
  end
@@ -1,24 +1,28 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Kiik do
4
-
4
+
5
5
  before(:each) do
6
6
  Kiik.config_path = 'spec/fixtures/kiik.yml'
7
7
  end
8
8
 
9
9
  describe Kiik::Wallet::Client do
10
-
10
+
11
11
  let(:wallet) { Kiik.wallet }
12
-
12
+
13
13
  context "initialization" do
14
14
 
15
15
  it 'should set the user api ' do
16
16
  expect(wallet.user).not_to be_nil
17
17
  end
18
18
 
19
+ it 'should set the user api ' do
20
+ expect(wallet.user.login(:id => "123123-1231231-12312-31231", :password => "teste123" )).not_to be_nil
21
+ end
22
+
19
23
  end
20
24
 
21
25
  end
22
-
26
+
23
27
 
24
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiik-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno de Queiroz
@@ -252,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
252
  version: '0'
253
253
  requirements: []
254
254
  rubyforge_project:
255
- rubygems_version: 2.2.2
255
+ rubygems_version: 2.4.5
256
256
  signing_key:
257
257
  specification_version: 4
258
258
  summary: A Gem for Kiik API