Sha256: c4f8dbc957d9c66d02c8e435e0af39bd62f6142c65275f9d492745f01511447d

Contents?: true

Size: 1.37 KB

Versions: 82

Compression:

Stored size: 1.37 KB

Contents

module Recurly
  module HTTP
    class Response
      attr_accessor :status, :body, :request,
        :request_id, :rate_limit, :rate_limit_remaining,
        :rate_limit_reset, :date, :proxy_metadata,
        :content_type, :total_records

      def initialize(resp, request)
        @request = Request.new(request.method, request.path, request.body)
        @status = resp.code.to_i
        @request_id = resp["x-request-id"]
        @rate_limit = resp["x-ratelimit-limit"].to_i
        @rate_limit_remaining = resp["x-ratelimit-remaining"].to_i
        @rate_limit_reset = Time.at(resp["x-ratelimit-reset"].to_i).to_datetime
        @total_records = resp["recurly-total-records"]&.to_i
        if resp["content-type"]
          @content_type = resp["content-type"].split(";").first
        else
          @content_type = resp.content_type
        end
        if resp.body && !resp.body.empty?
          @body = resp.body
        else
          @body = nil
        end
      end
    end

    class Request
      attr_accessor :method, :path, :body

      def initialize(method, path, body = nil)
        @method = method
        @path = path
        if body && !body.empty?
          @body = body
        else
          @body = nil
        end
      end

      def ==(other)
        method == other.method \
          && path == other.path \
          && body == other.body
      end
    end
  end
end

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
recurly-3.22.0 lib/recurly/http.rb
recurly-4.21.1 lib/recurly/http.rb
recurly-4.21.0 lib/recurly/http.rb
recurly-4.20.0 lib/recurly/http.rb
recurly-3.21.0 lib/recurly/http.rb
recurly-4.19.0 lib/recurly/http.rb
recurly-3.20.0 lib/recurly/http.rb
recurly-4.18.0 lib/recurly/http.rb
recurly-4.17.0 lib/recurly/http.rb
recurly-3.19.0 lib/recurly/http.rb
recurly-4.15.0 lib/recurly/http.rb
recurly-4.14.0 lib/recurly/http.rb
recurly-4.13.0 lib/recurly/http.rb
recurly-4.12.0 lib/recurly/http.rb
recurly-4.11.0 lib/recurly/http.rb
recurly-4.10.0 lib/recurly/http.rb
recurly-4.9.0 lib/recurly/http.rb
recurly-4.8.0 lib/recurly/http.rb
recurly-4.7.0 lib/recurly/http.rb
recurly-4.6.0 lib/recurly/http.rb