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 +4 -4
- data/lib/kiik-api.rb +5 -5
- data/lib/kiik/cacert.pem +23 -42
- data/lib/kiik/client.rb +4 -4
- data/lib/kiik/errors.rb +7 -7
- data/lib/kiik/logger.rb +1 -1
- data/lib/kiik/version.rb +1 -1
- data/lib/kiik/wallet.rb +3 -3
- data/lib/kiik/wallet/client.rb +123 -120
- data/lib/kiik/wallet/creditcard.rb +41 -41
- data/lib/kiik/wallet/transaction.rb +30 -30
- data/lib/kiik/wallet/user.rb +61 -80
- data/spec/fixtures/kiik.yml +1 -0
- data/spec/lib/kiik/wallet_client_spec.rb +3 -3
- data/spec/lib/kiik/wallet_client_user_spec.rb +8 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1928ec5fdddfe6440469a3de2bcf50963694dac
|
4
|
+
data.tar.gz: b634864088e68a781a945b6c0dd6aa8114a6043c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97828038a43c69b829f2d61c3eb403e50cf987ab304fe5c7362db3d3659c341913a4122503f2e98ba2adcdf6c846573d71f734042e89dcf8c5a0a09896ec5136
|
7
|
+
data.tar.gz: 77167f69cfe54bcea633ceb8555c98e37abf4706224950334d75e7443ef6f9545860532193c57208c4f8b7fedbc56d0b9da3467864db500d24e8c9ea7075dd0f
|
data/lib/kiik-api.rb
CHANGED
@@ -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
|
data/lib/kiik/cacert.pem
CHANGED
@@ -53,46 +53,27 @@ EvrRI5YPv5wN8nlFUzeaVi/oVxBw9u6JDEmJmsEj9cIqzEHPIqtlbreUgm0vQF9Y
|
|
53
53
|
huNMrUnjl1nOG5srztxl1Asoa06ERlFE9zMILViXIa4=
|
54
54
|
-----END CERTIFICATE-----
|
55
55
|
-----BEGIN CERTIFICATE-----
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
-----END CERTIFICATE-----
|
80
|
-
-----BEGIN CERTIFICATE-----
|
81
|
-
MIIDJzCCApCgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBzjELMAkGA1UEBhMCWkEx
|
82
|
-
FTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYD
|
83
|
-
VQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlv
|
84
|
-
biBTZXJ2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A8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBR7W0XP
|
72
|
+
r87Lev0xkhpqtvNG61dIUDANBgkqhkiG9w0BAQUFAAOCAQEAeRHAS7ORtvzw6WfU
|
73
|
+
DW5FvlXok9LOAz/t2iWwHVfLHjp2oEzsUHboZHIMpKnxuIvW1oeEuzLlQRHAd9mz
|
74
|
+
YJ3rG9XRbkREqaYB7FViHXe4XI5ISXycO1cRrK1zN44veFyQaEfZYGDm/Ac9IiAX
|
75
|
+
xPcW6cTYcvnIc3zfFi8VqT79aie2oetaupgf1eNNZAqdE8hhuvU5HIe6uL17In/2
|
76
|
+
/qxAeeWsEG89jxt5dovEN7MhGITlNgDrYyCZuen+MwS7QcjBAvlEYyCegc5C09Y/
|
77
|
+
LHbTY5xZ3Y+m4Q6gLkH3LpVHz7z9M/P2C2F+fpErgUfCJzDupxBdN49cOSvkBPB7
|
78
|
+
jVaMaA==
|
98
79
|
-----END CERTIFICATE-----
|
data/lib/kiik/client.rb
CHANGED
@@ -2,10 +2,10 @@ module Kiik
|
|
2
2
|
|
3
3
|
class Client
|
4
4
|
|
5
|
-
|
5
|
+
attr_reader :site
|
6
6
|
attr_accessor :token, :options
|
7
7
|
|
8
|
-
|
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
|
-
|
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|
|
data/lib/kiik/errors.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Kiik
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
15
|
+
class Error < StandardError
|
16
16
|
attr_reader :response, :code, :description
|
17
17
|
|
18
18
|
# standard error values include:
|
data/lib/kiik/logger.rb
CHANGED
data/lib/kiik/version.rb
CHANGED
data/lib/kiik/wallet.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Kiik
|
2
2
|
|
3
|
-
|
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
|
data/lib/kiik/wallet/client.rb
CHANGED
@@ -1,122 +1,125 @@
|
|
1
1
|
module Kiik
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
3
|
-
|
2
|
+
class Wallet
|
3
|
+
class Transaction
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
@base_uri = '/transactions/card'
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
24
|
-
|
23
|
+
request(token,:post,@base_uri,params,&block)
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
def callback(token,params={},&block)
|
27
|
+
request(token,:put,'/payment/callback',params,&block)
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
|
36
|
+
end
|
37
|
+
end
|
38
38
|
end
|
data/lib/kiik/wallet/user.rb
CHANGED
@@ -1,82 +1,63 @@
|
|
1
1
|
module Kiik
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
data/spec/fixtures/kiik.yml
CHANGED
@@ -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.
|
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.
|
255
|
+
rubygems_version: 2.4.5
|
256
256
|
signing_key:
|
257
257
|
specification_version: 4
|
258
258
|
summary: A Gem for Kiik API
|