Skip to content

Commit

Permalink
improve formatting of code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
markburns committed Apr 30, 2012
1 parent d306344 commit a7724fe
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7724fe

Please sign in to comment.