mondido 1.0.6 → 1.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0c7b7025af3744e8f78b3c4c7451655e8760597
4
- data.tar.gz: be6f7d9e109fcde736755a7b825a4943428e8758
3
+ metadata.gz: 408cefd0a15f84da2b22c61e087445fac32c3802
4
+ data.tar.gz: f56e3a3db98e62e39346b5cd9dd5ffca308c6a8e
5
5
  SHA512:
6
- metadata.gz: f7a411306eeaa32feecadd67cf9416a7ec0e94769c7a20bdb45e12d3814bf2f387a7a7e4fca4edc8e9cdc0b89a4ce219e26d803ebe2f0d0917774c35417d0d14
7
- data.tar.gz: 348deeeb9bb4b9ba6b204ce1f1cb9f263282feb50392b36e537fd6d81075fb766f7555f86808e69581b0ae811d9a73d2e283cb4b94dd296bb23d40167463a740
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
@@ -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]
@@ -3,5 +3,6 @@ module Mondido
3
3
  require 'mondido/exceptions/validation_exception'
4
4
  require 'mondido/exceptions/api_exception'
5
5
  require 'mondido/exceptions/missing_file'
6
+ require 'mondido/exceptions/not_applicable'
6
7
  end
7
8
  end
@@ -1,4 +1,3 @@
1
-
2
1
  module Mondido
3
2
  module Exceptions
4
3
  class MissingFile < StandardError
@@ -0,0 +1,6 @@
1
+ module Mondido
2
+ module Exceptions
3
+ class NotApplicable < StandardError
4
+ end
5
+ end
6
+ end
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Mondido
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
@@ -0,0 +1,9 @@
1
+ module Mondido
2
+ class Webhook
3
+ def self.receive(request)
4
+ json = request.body.string
5
+ hash = JSON.parse(json)
6
+ transaction = Mondido::CreditCard::Transaction.new(hash)
7
+ end
8
+ end
9
+ end
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.6
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-07 00:00:00.000000000 Z
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