From a7724fe9f03cd37541ef59c70c1586180e2c02b3 Mon Sep 17 00:00:00 2001 From: Mark Burns Date: Mon, 30 Apr 2012 09:21:56 +0100 Subject: [PATCH] improve formatting of code snippets --- README.md | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index da27150..49acf21 100644 --- a/README.md +++ b/README.md @@ -9,46 +9,46 @@ Examples Client example ```ruby - params = {:some => 'parameters'} - token = Signature::Token.new('my_key', 'my_secret') - request = Signature::Request.new('POST', '/api/thing', params) - auth_hash = request.sign(token) - query_params = params.merge(auth_hash) - - HTTParty.post('http://myservice/api/thing', { - :query => query_params - }) +params = {:some => 'parameters'} +token = Signature::Token.new('my_key', 'my_secret') +request = Signature::Request.new('POST', '/api/thing', params) +auth_hash = request.sign(token) +query_params = params.merge(auth_hash) + +HTTParty.post('http://myservice/api/thing', { + :query => query_params +}) ``` `query_params` looks like: ```ruby - { - :some => "parameters", - :auth_timestamp => 1273231888, - :auth_signature => "28b6bb0f242f71064916fad6ae463fe91f5adc302222dfc02c348ae1941eaf80", - :auth_version => "1.0", - :auth_key => "my_key" - } +{ + :some => "parameters", + :auth_timestamp => 1273231888, + :auth_signature => "28b6bb0f242f71064916fad6ae463fe91f5adc302222dfc02c348ae1941eaf80", + :auth_version => "1.0", + :auth_key => "my_key" +} ``` Server example (sinatra) ```ruby - error Signature::AuthenticationError do |controller| - error = controller.env["sinatra.error"] - halt 401, "401 UNAUTHORIZED: #{error.message}\n" - end - - post '/api/thing' do - request = Signature::Request.new('POST', env["REQUEST_PATH"], params) - # This will raise a Signature::AuthenticationError if request does not authenticate - token = request.authenticate do |key| - Signature::Token.new(key, lookup_secret(key)) - end - - # Do whatever you need to do - end +error Signature::AuthenticationError do |controller| + error = controller.env["sinatra.error"] + halt 401, "401 UNAUTHORIZED: #{error.message}\n" +end + +post '/api/thing' do + request = Signature::Request.new('POST', env["REQUEST_PATH"], params) + # This will raise a Signature::AuthenticationError if request does not authenticate + token = request.authenticate do |key| + Signature::Token.new(key, lookup_secret(key)) + end + + # Do whatever you need to do +end ``` Pre-requisites