Sha256: 91ddd4a2aec74873f3b84fd3d28caa02b6816c90adedee1fade0627a45d23316

Contents?: true

Size: 637 Bytes

Versions: 19

Compression:

Stored size: 637 Bytes

Contents

module Paddle
  module Classic
    class Collection
      attr_reader :data, :total

      def self.from_response(response, type:, key: nil)
        body = response.body

        if key.is_a?(String)
          data  = body["response"][key].map { |attrs| type.new(attrs) }
          total = body["response"]["total"]
        else
          data  = body["response"].map { |attrs| type.new(attrs) }
          total = body["response"].count
        end

        new(
          data: data,
          total: total
        )
      end

      def initialize(data:, total:)
        @data = data
        @total = total
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
paddle-2.7.0 lib/paddle/classic/collection.rb
paddle-2.6.0 lib/paddle/classic/collection.rb
paddle-2.5.2 lib/paddle/classic/collection.rb
paddle-2.5.1 lib/paddle/classic/collection.rb
paddle-2.5.0 lib/paddle/classic/collection.rb
paddle-2.4.1 lib/paddle/classic/collection.rb
paddle-2.4.0 lib/paddle/classic/collection.rb
paddle-2.3.0 lib/paddle/classic/collection.rb
paddle-2.2.1 lib/paddle/classic/collection.rb
paddle-2.2.0 lib/paddle/classic/collection.rb
paddle-2.1.4 lib/paddle/classic/collection.rb
paddle-2.1.3 lib/paddle/classic/collection.rb
paddle-2.1.2 lib/paddle/classic/collection.rb
paddle-2.1.1 lib/paddle/classic/collection.rb
paddle-2.1.0 lib/paddle/classic/collection.rb
paddle-2.0.0 lib/paddle/classic/collection.rb
paddle-1.1.2 lib/paddle/classic/collection.rb
paddle-1.1.1 lib/paddle/classic/collection.rb
paddle-1.1.0 lib/paddle/classic/collection.rb