mondido 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mondido/base_behaviour.rb +15 -0
- data/lib/mondido/base_model.rb +8 -0
- data/lib/mondido/credit_card/refund.rb +4 -0
- data/lib/mondido/credit_card/transaction.rb +4 -0
- data/lib/mondido/exceptions/exceptions.rb +1 -0
- data/lib/mondido/exceptions/missing_file.rb +0 -1
- data/lib/mondido/exceptions/not_applicable.rb +6 -0
- data/lib/mondido/rest_client.rb +7 -0
- data/lib/mondido/version.rb +1 -1
- data/lib/mondido/webhook.rb +9 -0
- data/lib/mondido.rb +2 -0
- data/spec/credit_card/refund_spec.rb +8 -0
- data/spec/credit_card/stored_card_spec.rb +18 -0
- data/spec/credit_card/transaction_spec.rb +9 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 408cefd0a15f84da2b22c61e087445fac32c3802
|
4
|
+
data.tar.gz: f56e3a3db98e62e39346b5cd9dd5ffca308c6a8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10f77cc5143244c76465672cbdcd1b1d31bffc8541cd597e64fd232dfd9e9836a53dc98a51965dfaf5efb52d4a0afcfc642199d2bba9f84e296e53e48ff803a8
|
7
|
+
data.tar.gz: af0e1220a2b4ab3441b7b7303e10f994d79b101ed22cdefd9020913aef992c629d42601de3d394c30ad959093b7a7a5d58b7bc7ebe47222da86a1564dda7e1ef
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Mondido
|
2
|
+
module BaseBehaviour
|
3
|
+
def initialize(attributes={})
|
4
|
+
setters = self.methods
|
5
|
+
.select{ |method| !method.to_s.match(/=\z/).nil? && method.match(/\A(!|=|_)/).nil? }
|
6
|
+
.map{ |method| method.to_s[0, method.length-1].to_sym }
|
7
|
+
|
8
|
+
attributes.select!{ |k,v|
|
9
|
+
setters.include?(k)
|
10
|
+
}
|
11
|
+
|
12
|
+
super(attributes)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/mondido/base_model.rb
CHANGED
@@ -62,6 +62,14 @@ module Mondido
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
# @param id [Integer]
|
66
|
+
# @return [Mondido::*]
|
67
|
+
def self.delete(id)
|
68
|
+
response = Mondido::RestClient.delete(pluralized, id)
|
69
|
+
object = self.new
|
70
|
+
object.update_from_response(JSON.parse(response.body))
|
71
|
+
end
|
72
|
+
|
65
73
|
private
|
66
74
|
|
67
75
|
# @return [String]
|
@@ -22,6 +22,10 @@ module Mondido
|
|
22
22
|
validates :reason,
|
23
23
|
presence: { message: 'errors.reason.missing' },
|
24
24
|
strict: Mondido::Exceptions::ValidationException
|
25
|
+
|
26
|
+
def self.delete(id)
|
27
|
+
raise Mondido::Exceptions::NotApplicable.new 'Can not delete Transaction'
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -2,6 +2,7 @@ module Mondido
|
|
2
2
|
module CreditCard
|
3
3
|
class Transaction < BaseModel
|
4
4
|
include ActiveModel::Model
|
5
|
+
include Mondido::BaseBehaviour
|
5
6
|
|
6
7
|
attr_accessor :id,
|
7
8
|
:amount,
|
@@ -57,6 +58,9 @@ module Mondido
|
|
57
58
|
strict: Mondido::Exceptions::ValidationException
|
58
59
|
|
59
60
|
|
61
|
+
def self.delete(id)
|
62
|
+
raise Mondido::Exceptions::NotApplicable.new 'Can not delete Transaction'
|
63
|
+
end
|
60
64
|
|
61
65
|
def self.create(attributes={})
|
62
66
|
metadata = attributes[:metadata]
|
data/lib/mondido/rest_client.rb
CHANGED
@@ -27,6 +27,8 @@ module Mondido
|
|
27
27
|
query = ''
|
28
28
|
end
|
29
29
|
request = Net::HTTP::Get.new(uri.path + query)
|
30
|
+
when :delete
|
31
|
+
request = Net::HTTP::Delete.new(uri.path)
|
30
32
|
end
|
31
33
|
|
32
34
|
request.basic_auth(Mondido::Credentials.merchant_id, Mondido::Credentials.password)
|
@@ -46,6 +48,11 @@ module Mondido
|
|
46
48
|
call_api(uri: uri_string)
|
47
49
|
end
|
48
50
|
|
51
|
+
def self.delete(method, id=nil)
|
52
|
+
uri_string = [Mondido::Config::URI, method.to_s, id.to_s].join('/')
|
53
|
+
call_api(uri: uri_string, http_method: :delete)
|
54
|
+
end
|
55
|
+
|
49
56
|
def self.all(method, filter={})
|
50
57
|
uri_string = [Mondido::Config::URI, method.to_s].join('/')
|
51
58
|
call_api(uri: uri_string, query: filter.to_query)
|
data/lib/mondido/version.rb
CHANGED
data/lib/mondido.rb
CHANGED
@@ -6,9 +6,11 @@ module Mondido
|
|
6
6
|
require 'mondido/exceptions/exceptions'
|
7
7
|
require 'mondido/rest_client'
|
8
8
|
require 'mondido/base_model'
|
9
|
+
require 'mondido/base_behaviour'
|
9
10
|
require 'mondido/credit_card/transaction'
|
10
11
|
require 'mondido/credit_card/refund'
|
11
12
|
require 'mondido/credit_card/stored_card'
|
13
|
+
require 'mondido/webhook'
|
12
14
|
end
|
13
15
|
|
14
16
|
|
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mondido::CreditCard::Refund do
|
4
|
+
context '#delete' do
|
5
|
+
it 'raises NotApplicable' do
|
6
|
+
expect{
|
7
|
+
Mondido::CreditCard::Refund.delete(1)
|
8
|
+
}.to raise_error(Mondido::Exceptions::NotApplicable)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
context 'create' do
|
5
13
|
context 'valid' do
|
6
14
|
before(:all) do
|
@@ -72,4 +72,22 @@ describe Mondido::CreditCard::StoredCard do
|
|
72
72
|
|
73
73
|
end
|
74
74
|
end
|
75
|
+
|
76
|
+
context '#delete' do
|
77
|
+
before(:all) do
|
78
|
+
uri = URI.parse(Mondido::Config::URI + '/stored_cards/1')
|
79
|
+
uri.user = Mondido::Credentials.merchant_id.to_s
|
80
|
+
uri.password = Mondido::Credentials.password.to_s
|
81
|
+
json_stored_card = File.read('spec/stubs/stored_card.json')
|
82
|
+
@stored_card_hash = JSON.parse(json_stored_card)
|
83
|
+
|
84
|
+
stub_request(:delete, uri.to_s)
|
85
|
+
.to_return(status: 200, body: json_stored_card, headers: {})
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'is a Mondido::CreditCard::StoredCard' do
|
89
|
+
stored_card = Mondido::CreditCard::StoredCard.delete(1)
|
90
|
+
expect(stored_card).to be_an_instance_of(Mondido::CreditCard::StoredCard)
|
91
|
+
end
|
92
|
+
end
|
75
93
|
end
|
@@ -2,16 +2,23 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mondido::CreditCard::Transaction do
|
4
4
|
|
5
|
+
context '#delete' do
|
6
|
+
it 'raises NotApplicable' do
|
7
|
+
expect{
|
8
|
+
Mondido::CreditCard::Transaction.delete(1)
|
9
|
+
}.to raise_error(Mondido::Exceptions::NotApplicable)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
5
13
|
context 'list transactions' do
|
6
14
|
before(:all) do
|
7
|
-
uri = URI.parse(Mondido::Config::URI + '/transactions')
|
15
|
+
uri = URI.parse(Mondido::Config::URI + '/transactions?limit=2&offset=1')
|
8
16
|
uri.user = Mondido::Credentials.merchant_id.to_s
|
9
17
|
uri.password = Mondido::Credentials.password.to_s
|
10
18
|
json_transactions = File.read('spec/stubs/transactions.json')
|
11
19
|
@transactions_array = JSON.parse(json_transactions)
|
12
20
|
|
13
21
|
stub_request(:get, uri.to_s)
|
14
|
-
.with(body: {limit: '2', offset: '1'})
|
15
22
|
.to_return(status: 200, body: json_transactions, headers: {})
|
16
23
|
|
17
24
|
@transactions = Mondido::CreditCard::Transaction.all(limit: 2, offset: 1)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mondido
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Falkén
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -60,6 +60,7 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
+
- lib/mondido/base_behaviour.rb
|
63
64
|
- lib/mondido/base_model.rb
|
64
65
|
- lib/mondido/config.rb
|
65
66
|
- lib/mondido/credentials.rb
|
@@ -69,9 +70,11 @@ files:
|
|
69
70
|
- lib/mondido/exceptions/api_exception.rb
|
70
71
|
- lib/mondido/exceptions/exceptions.rb
|
71
72
|
- lib/mondido/exceptions/missing_file.rb
|
73
|
+
- lib/mondido/exceptions/not_applicable.rb
|
72
74
|
- lib/mondido/exceptions/validation_exception.rb
|
73
75
|
- lib/mondido/rest_client.rb
|
74
76
|
- lib/mondido/version.rb
|
77
|
+
- lib/mondido/webhook.rb
|
75
78
|
- lib/mondido.rb
|
76
79
|
- MIT-LICENSE
|
77
80
|
- Rakefile
|