Sha256: 5e37e763f4ceb178ce71a11f3d64c14d620b7a7c29d63604f4f280ea310adb79

Contents?: true

Size: 1.07 KB

Versions: 15

Compression:

Stored size: 1.07 KB

Contents

module Spree
  module Api
    module V2
      module CollectionOptionsHelpers
        def collection_links(collection)
          {
            self: request.original_url,
            next: pagination_url(collection.next_page || collection.total_pages),
            prev: pagination_url(collection.prev_page || 1),
            last: pagination_url(collection.total_pages),
            first: pagination_url(1)
          }
        end

        def collection_meta(collection)
          {
            count: collection.size,
            total_count: collection.total_count,
            total_pages: collection.total_pages
          }
        end

        # leaving this method in public scope so it's still possible to modify
        # those params to support non-standard non-JSON API parameters
        def collection_permitted_params
          params.permit(:format, :page, :per_page, :sort, :include, :fields, filter: {})
        end

        private

        def pagination_url(page)
          url_for(collection_permitted_params.merge(page: page))
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
spree_api-3.7.11 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.10 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.9 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.8 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.7 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.6 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.5 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.4 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.3 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.2 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.1 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.0 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.0.rc3 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.0.rc2 app/helpers/spree/api/v2/collection_options_helpers.rb
spree_api-3.7.0.rc1 app/helpers/spree/api/v2/collection_options_helpers.rb