001/*
002 * Copyright 2010-2014 Ning, Inc.
003 * Copyright 2014-2015 The Billing Project, LLC
004 *
005 * The Billing Project licenses this file to you under the Apache License, version 2.0
006 * (the "License"); you may not use this file except in compliance with the
007 * License.  You may obtain a copy of the License at:
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
014 * License for the specific language governing permissions and limitations
015 * under the License.
016 */
017package com.ning.billing.recurly.model;
018
019import org.apache.http.Header;
020import org.apache.http.HttpResponse;
021
022public class ResponseMetadata {
023    /**
024     * Represents the unique id given to this
025     * request by Recurly. Comes from the X-Request-Id
026     * header in the response.
027     */
028    private String requestId;
029
030    /**
031     * Represents the unique id given to this
032     * request by Cloudflare (if request is proxied through
033     * Cloudflare). Comes from the CF-RAY header in the response.
034     */
035    private String cfRay;
036
037    /**
038     * The HTTP Status Code of the response.
039     */
040    private int statusCode;
041
042    public ResponseMetadata(HttpResponse response) {
043        final Header requestIdHeader = response.getFirstHeader("X-Request-Id");
044        this.requestId = requestIdHeader == null ? null : requestIdHeader.getValue();
045        final Header cfRayHeader = response.getFirstHeader("CF-RAY");
046        this.cfRay = cfRayHeader == null ? null : cfRayHeader.getValue();
047        this.statusCode = response.getStatusLine().getStatusCode();
048    }
049
050    public String getRequestId() {
051        return this.requestId;
052    }
053
054    public String getCfRay() {
055        return this.cfRay;
056    }
057
058    public int getStatusCode() {
059        return this.statusCode;
060    }
061
062    @Override
063    public String toString() {
064        final StringBuilder sb = new StringBuilder("ResponseMetadata{");
065        sb.append("requestId=").append(requestId);
066        sb.append(", cfRay=").append(cfRay);
067        sb.append(", statusCode=").append(statusCode);
068        sb.append('}');
069        return sb.toString();
070    }
071}