Sha256: fd46f06c46aec08960516c469e9eb8cc9ed488653384262622e1efccef4e8cb1

Contents?: true

Size: 900 Bytes

Versions: 4

Compression:

Stored size: 900 Bytes

Contents

# frozen_string_literal: true

module RubyLokaliseApi
  module Request
    include RubyLokaliseApi::BaseRequest

    # Lokalise returns pagination info in special headers
    PAGINATION_HEADERS = %w[x-pagination-total-count x-pagination-page-count x-pagination-limit
                            x-pagination-page].freeze

    private

    def respond_with(response, client)
      body = custom_load response.body
      uri = Addressable::URI.parse response.env.url
      raise_on_error! response, body
      extract_headers_from(response).
        merge('content' => body,
              'client' => client,
              'path' => uri.path.gsub(%r{/api2/}, ''))
    end

    # Keep only pagination headers
    def extract_headers_from(response)
      response.
        headers.
        to_h.
        keep_if { |k, _v| PAGINATION_HEADERS.include?(k) }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-lokalise-api-7.2.0 lib/ruby_lokalise_api/request.rb
ruby-lokalise-api-7.1.1 lib/ruby_lokalise_api/request.rb
ruby-lokalise-api-7.1.0 lib/ruby_lokalise_api/request.rb
ruby-lokalise-api-7.0.0 lib/ruby_lokalise_api/request.rb