Skip to content

Commit

Permalink
adding hydrater
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfl authored and steveklabnik committed Dec 18, 2013
1 parent 35776fa commit 1e61843
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
14 changes: 14 additions & 0 deletions features/debits.feature
@@ -0,0 +1,14 @@
Feature: Debit a card or bank account
Debits is the action of charging a customers card or bank account.
Upon a debit succeeding, the value will be reflected in the marketplace's escrow balance
or in the escrow for an order.

Scenario: Debiting a card
Given I have tokenized a card
When I POST to /cards/:card_id/debits with the JSON API body:
"""
{
"amount": 20000
}
"""
Then I should get a 201 Created status code
3 changes: 2 additions & 1 deletion features/step_definitions/cards.rb
@@ -1,12 +1,13 @@
Given(/^I have tokenized a card$/) do
@client.post('/cards',
@client.post('/cards',
{
number: "4111111111111111",
expiration_month: "12",
expiration_year: 2016
}
)
@card_id = @client['cards']['id']
@client.add_hydrate(:card_id, @card_id)
end

Given(/^I have tokenized more than one card$/) do
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion features/step_definitions/http_steps.rb
Expand Up @@ -32,7 +32,7 @@
end

When(/^I POST to (\/\S*) with the JSON API body:$/) do |url, body|
@client.post(url, body)
@client.post(@client.hydrater(url), body)
end

require 'json-schema'
Expand Down
15 changes: 15 additions & 0 deletions lib/balanced/tiny_client.rb
Expand Up @@ -12,6 +12,7 @@ def initialize(api_secret, accept_header, root_url)
@root_url = root_url

@responses = []
@hydrate_tokens = {}
end

def post(endpoint, body)
Expand Down Expand Up @@ -70,6 +71,20 @@ def inject(key)
key.split('.').inject(last_body) {|o, k| Array(o[k])[0] }
end

def hydrater(what)
@hydrate_tokens.each_pair do |key, value|
if key.class == Symbol
key = ":#{key}"
end
what = what.gsub(key, value)
end
what
end

def add_hydrate(key, value)
@hydrate_tokens[key] = value
end

def validate(against)
file_name = File.join('fixtures', "#{against}.json")
if File.exists? file_name and not against.is_a? Hash
Expand Down

0 comments on commit 1e61843

Please sign in to comment.