Sha256: 752ac17fd6428c53773e817aa9a9a463f68c02d2341e31891908df47a7cb6b99

Contents?: true

Size: 1.36 KB

Versions: 35

Compression:

Stored size: 1.36 KB

Contents

require_relative './model'

module Spaceship
  class ConnectAPI
    class Response
      include Enumerable
      attr_reader :body
      attr_reader :status
      attr_reader :headers
      attr_reader :client

      def initialize(body: nil, status: nil, headers: nil, client: nil)
        @body = body
        @status = status
        @headers = headers
        @client = client
      end

      def next_url
        return nil if body.nil?
        links = body["links"] || {}
        return links["next"]
      end

      def next_page
        url = next_url
        return nil if url.nil?
        return client.get(url)
      end

      def next_pages(count: 1)
        if !count.nil? && count < 0
          count = 0
        end

        responses = [self]
        counter = 0

        resp = self
        loop do
          resp = resp.next_page
          break if resp.nil?
          responses << resp
          counter += 1

          break if !count.nil? && counter >= count
        end

        return responses
      end

      def all_pages
        return next_pages(count: nil)
      end

      def to_models
        return [] if body.nil?
        model_or_models = Spaceship::ConnectAPI::Models.parse(body)
        return [model_or_models].flatten
      end

      def each(&block)
        to_models.each do |model|
          yield(model)
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
fastlane-2.198.1 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.198.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.197.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.196.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.195.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.194.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.193.1 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.193.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.192.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.191.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.190.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.189.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.188.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.187.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.186.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.185.1 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.185.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.184.1 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.184.0 spaceship/lib/spaceship/connect_api/response.rb
fastlane-2.183.2 spaceship/lib/spaceship/connect_api/response.rb