Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ben-biddington
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben-biddington/ff9901023e3ae96464e1 to your computer and use it in GitHub Desktop.
Save ben-biddington/ff9901023e3ae96464e1 to your computer and use it in GitHub Desktop.
Wire protocol documentation
require 'minitest/autorun'
require 'minitest/pride'
class WireConversationWithTwitter < MiniTest::Test
def test_that_it_rejects_an_unauthorised_request
when_I_request <<-TEXT
GET /1.1/statuses
Host: api.twitter.com
Accept: application/json
TEXT
then_it_returns_exactly <<-REPLY
HTTP/1.1 400 Bad Request
content-length: 24
content-type: text/plain;charset=utf-8
date: Sat, 30 Aug 2014 01:30:43 UTC
server: tsa_a
set-cookie: guest_id=v1%3A140936224322485447; Domain=.twitter.com; Path=/; Expires=Mon, 29-Aug-2016 01:30:43 UTC
strict-transport-security: max-age=631138519
x-connection-hash: 7710cb2762e0a47702d21bb7e10d3056
Bad Authentication data
REPLY
end
private
def when_I_request(what);
@reply = <<-OBVIOUSLY_INCORRECT_CANNED_ANSWER
HTTP/1.1 400 Bad Request
content-length: 24
Bad Authentication data
OBVIOUSLY_INCORRECT_CANNED_ANSWER
end
def then_it_returns_exactly(expected)
assert_equal expected, @reply
end
end
# curl -v https://api.twitter.com/1.1/statuses -H "Accept: application/json"
# > GET /1.1/statuses
# > Host: api.twitter.com
# > Accept: application/json
# < HTTP/1.1 400 Bad Request
# < content-length: 24
# < content-type: text/plain;charset=utf-8
# < date: Sat, 30 Aug 2014 01:30:43 UTC
# < server: tsa_a
# < set-cookie: guest_id=v1%3A140936224322485447; Domain=.twitter.com; Path=/; Expires=Mon, 29-Aug-2016 01:30:43 UTC
# < strict-transport-security: max-age=631138519
# < x-connection-hash: 7710cb2762e0a47702d21bb7e10d3056
# <
# Bad Authentication data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment