Skip to content

Commit

Permalink
Hooks and Notifications
Browse files Browse the repository at this point in the history
Hooks and Notifications: New object to allow management of URL
notifications

- new payment methods allowing the management of Hook projects with
different EventType

- documentation: http://docs.mangopay.com/api-references/notifications
  • Loading branch information
Sergiusz Woźnicki committed Mar 5, 2014
1 parent 55952b1 commit 87f77b2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/mangopay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
require 'mangopay/card'
require 'mangopay/event'
require 'mangopay/kyc_document'
require 'mangopay/hook'

module MangoPay

Expand Down
7 changes: 7 additions & 0 deletions lib/mangopay/hook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module MangoPay
class Hook < Resource
include MangoPay::HTTPCalls::Create
include MangoPay::HTTPCalls::Update
include MangoPay::HTTPCalls::Fetch
end
end
39 changes: 39 additions & 0 deletions spec/lib/mangopay/hook_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require_relative '../../spec_helper'

describe MangoPay::Hook do
include_context 'hooks'

describe 'CREATE' do
it 'creates a hook' do
expect(new_hook['Id']).to_not be_nil
end
end

describe 'UPDATE' do
it 'updates a hook' do
new_url = new_hook['Url'] + '.com'
updated_hook = MangoPay::Hook.update(new_hook['Id'], {
Url: new_url,
Tag: 'Updated Tag'
})
expect(updated_hook['Url']).to eq(new_url)
expect(updated_hook['Tag']).to eq('Updated Tag')
end
end

describe 'FETCH' do

it 'fetches a hook' do
hook = MangoPay::Hook.fetch(new_hook['Id'])
expect(hook['Id']).to eq(new_hook['Id'])
end

it 'fetches all the hooks' do
hooks = MangoPay::Hook.fetch()
expect(hooks).to be_kind_of(Array)
expect(hooks).not_to be_empty
end

end

end
17 changes: 17 additions & 0 deletions spec/lib/mangopay/shared_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,20 @@ def create_new_transfer(from_wallet, to_wallet, amnt = 500)
})
end
end

###############################################
shared_context 'hooks' do
###############################################
let(:new_hook) {
hooks = MangoPay::Hook.fetch({'page' => 1, 'per_page' => 1})
if hooks.length == 0
MangoPay::Hook.create({
EventType: 'PAYIN_NORMAL_CREATED',
Url: 'http://test.com',
Tag: 'Test hook'
})
else
hooks[0]
end
}
end

0 comments on commit 87f77b2

Please sign in to comment.