Sha256: 124d21f5bebcf947b04bee6218f32230b5ccb0e5325d2093cecbfbe7056d5c6f

Contents?: true

Size: 884 Bytes

Versions: 20

Compression:

Stored size: 884 Bytes

Contents

module Phrase
  class Response
    attr_reader :data

    def initialize(data, headers)
      @data = data
      @paginated = false
      @next_page = nil

      link_headers = headers["link"]
      if link_headers
        @paginated = true
        parsed_links = LinkHeaderParser.parse(link_headers, base: 'https://api.phrase.com').by_relation_type
        next_page_link = parsed_links[:next]&.first
        if next_page_link
          @next_page = CGI.parse(URI.parse(next_page_link.target_uri).query)["page"]&.first&.to_i
        end
      end
    end

    def method_missing(method, *args, &block)
      if data.respond_to?(method)
        data.send(method, *args, &block)
      else
        super
      end
    end

    def next_page
      @next_page
    end

    def next_page?
      paginated? && !next_page.nil?
    end

    def paginated?
      @paginated
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
phrase-2.4.0 lib/phrase/response.rb
phrase-2.3.1 lib/phrase/response.rb
phrase-2.3.0 lib/phrase/response.rb
phrase-2.2.0 lib/phrase/response.rb
phrase-2.1.0 lib/phrase/response.rb
phrase-2.0.0 lib/phrase/response.rb
phrase-1.0.14 lib/phrase/response.rb
phrase-1.0.13 lib/phrase/response.rb
phrase-1.0.12 lib/phrase/response.rb
phrase-1.0.11 lib/phrase/response.rb
phrase-1.0.10 lib/phrase/response.rb
phrase-1.0.9 lib/phrase/response.rb
phrase-1.0.8 lib/phrase/response.rb
phrase-1.0.7 lib/phrase/response.rb
phrase-1.0.6 lib/phrase/response.rb
phrase-1.0.5 lib/phrase/response.rb
phrase-1.0.4 lib/phrase/response.rb
phrase-1.0.3 lib/phrase/response.rb
phrase-1.0.2 lib/phrase/response.rb
phrase-1.0.1 lib/phrase/response.rb