Square | Phone | HTTP Replay
Anonymous User
5459

YOE: 2.5

I was asked this question on the phone for a Square interview.

I was given this JSON file, it had pairs of request and response objects, around 10 total.

I had to replay the request and assert that the response was the same. I had to do it on my own IDE with screen share and I could google/use any library and language I want.

I bombed it pretty hard, as I had never written custom code for making HTTP requests before.

Curious to see how it would be done in Java.

The JSON file looks like:

[
  {
    "request": {
      "url": "/v1/customers",
      "headers": {
        "X-square-Client-User-Agent": "{\"lang\": \"ruby\", \"publisher\": \"square\", \"uname\": \"Linux version 3.13.0-57-generic (buildd@brownie) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #95-Ubuntu SMP Fri Jun 19 09:28:15 UTC 2015\", \"hostname\": \"caron\", \"lang_version\": \"2.1.2 p95 (2014-05-08)\", \"engine\": \"ruby\", \"platform\": \"x86_64-linux\", \"bindings_version\": \"1.23.0\"}",
        "Host": "api.square.com",
        "Accept-Encoding": "gzip, deflate",
        "Authorization": "Bearer sq_test_xOEwT736mUYLIx7hs0xTiCkI",
        "Content-Type": "application/x-www-form-urlencoded",
        "Accept": "*/*; q=0.5, application/xml",
        "User-Agent": "square/v1 RubyBindings/1.23.0"
      },
      "body": "email=tester@example.com&source[object]=card&source[number]=4242424242424242&source[exp_month]=12&source[exp_year]=2020",
      "method": "POST"
    },
    "response": {
      "body": "{\n  \"id\": \"cus_7aOWdO54yUSmHn\",\n  \"account_balance\": 0,\n  \"created\": 1442343974,\n  \"currency\": null,\n  \"default_source\": \"card_16lOksKv5xscqGyh9trfsVmi\",\n  \"delinquent\": false,\n  \"description\": null,\n  \"discount\": null,\n  \"email\": \"tester@example.com\",\n  \"livemode\": false,\n  \"metadata\": {\n  },\n  \"object\": \"customer\",\n  \"shipping\": null,\n  \"sources\": {\n    \"has_more\": false,\n    \"total_count\": 1,\n    \"object\": \"list\",\n    \"data\": [\n      {\n        \"address_state\": null,\n        \"last4\": \"4242\",\n        \"dynamic_last4\": null,\n        \"address_zip_check\": null,\n        \"address_country\": null,\n        \"id\": \"card_16lOksKv5xscqGyh9trfsVmi\",\n        \"address_line2\": null,\n        \"address_line1\": null,\n        \"funding\": \"credit\",\n        \"metadata\": {\n        },\n        \"cvc_check\": null,\n        \"exp_month\": 12,\n        \"tokenization_method\": null,\n        \"address_line1_check\": null,\n        \"brand\": \"Visa\",\n        \"object\": \"card\",\n        \"fingerprint\": \"70RrlzfthHpu3e4l\",\n        \"exp_year\": 2020,\n        \"address_zip\": null,\n        \"customer\": \"cus_6zNVcN43xWRlGm\",\n        \"address_city\": null,\n        \"name\": null,\n        \"country\": \"US\"\n      }\n    ],\n    \"url\": \"/v1/customers/cus_6zNVcN43xWRlGm/sources\"\n  },\n  \"subscriptions\": {\n    \"has_more\": false,\n    \"total_count\": 0,\n    \"object\": \"list\",\n    \"data\": [\n\n    ],\n    \"url\": \"/v1/customers/cus_6zNVcN43xWRlGm/subscriptions\"\n  }\n}",
      "headers": {
        "Content-Length": "1394",
        "Access-Control-Max-Age": "300",
        "Request-Id": "req_6zNWsJRd22AKRc",
        "Strict-Transport-Security": "max-age=31556926; includeSubDomains",
        "square-Version": "2015-07-13",
        "Server": "nginx",
        "Connection": "keep-alive",
        "Cache-Control": "no-cache, no-store",
        "Date": "Tue, 15 Sep 2015 19:07:10 GMT",
        "Access-Control-Allow-Credentials": "true",
        "Access-Control-Allow-Methods": "GET, POST, HEAD, OPTIONS, DELETE",
        "Content-Type": "application/json",
        "Access-Control-Allow-Origin": "*"
      },
      "code": 200
    }
  },
  ...
]
Comments (7)