Permalink
Browse files

wip, getting extracer to log requests

  • Loading branch information...
1 parent f456b05 commit c9b9af4b8c973df22391f8542ffa3fe1aea5c90b @matthewfl matthewfl committed Feb 7, 2014
View
@@ -1,2 +1,3 @@
scenarios.json
*.iml
+balanced.rev1.json
@@ -32,6 +32,7 @@ Feature: Holds
Then the response is valid according to the "card_holds" schema
And the card_hold has a "voided_at" attribute set
+ @focus
Scenario: Voided holds aren't visible from the index
Given I have voided a hold
When I fetch the card
@@ -8,7 +8,6 @@ Feature: Tokenize a credit card
For more on tokenization as a concept, see ['tokenization' on
Wikipedia.](http://en.wikipedia.org/wiki/Tokenization_%28data_security%29)
- @focus
Scenario: Tokenize a card without a secret key
Cards are able to be tokenized without sending along a secret key. When
this happens, the customer gets less information than if the key was sent.
@@ -21,12 +20,10 @@ Feature: Tokenize a credit card
"expiration_year": 2016
}
"""
- Then debug
Then I should get a 201 Created status code
And the response is valid according to the "card_tokens" schema
When I GET "cards.href" from the previous response
- Then debug
Then I should get a 200 OK status code
And the response is valid according to the "cards" schema
@@ -50,3 +50,7 @@
require 'balanced/extracer'
$client = Balanced::TinyClient.new($api_secret, $accept_header, $root_url)
+
+at_exit do
+ $extracer.save
+end
View
@@ -4,6 +4,41 @@ module Balanced
class Extracer
def initialize
# @json = load_all_json
+ @requests = []
+ @links = {}
+ end
+
+ def log_request(method, endpoint, request, response)
+ # TODO: it would be nice to log the file name and line number for this step
+ # then we could look into providing links to the cucumber useage
+ require 'debugger'; debugger
+ @requests << {
+ method: method,
+ endpoing: endpoint,
+ request: request,
+ response: response
+ }
+ if response['links']
+ @links = @links.merge(response['links'])
+ end
+ # TODO: make these extract from arrays when those are being used
+ if method == 'POST'
+
+ elsif method == 'PUT'
+
+ end
+ end
+
+ def save
+ file = File.join(File.dirname(__FILE__)+'/../../balanced.rev1.json')
+ json = {
+ schemas: load_all_json,
+ requests: @requests,
+ links: @links
+ }
+ File.open(file, 'w') do |f|
+ f.write(JSON.pretty_generate(json))
+ end
end
@@ -39,7 +74,6 @@ def load_all_json
ret
end
-
end
end
@@ -33,6 +33,7 @@ def post(endpoint, body, env={})
response = HTTParty.post(url, options)
@responses << response
+ $extracer.log_request('POST', endpoint, body, last_body)
response
end
@@ -65,6 +66,7 @@ def put(endpoint, body, env={})
response = HTTParty.put("#{@root_url}#{endpoint}", options)
@responses << response
+ $extracer.log_request('POST', endpoint, body, last_body)
response
end

0 comments on commit c9b9af4

Please sign in to comment.