module ShopifyAPI::PaginatedCollection::CollectionPagination
Constants
- AVAILABLE_IN_VERSION
- AVAILABLE_IN_VERSION_EARLY
Public Class Methods
new(args)
click to toggle source
Calls superclass method
# File lib/shopify_api/paginated_collection.rb, line 6 def initialize(args) @next_url = pagination_link_headers.next_link&.url&.to_s @previous_url = pagination_link_headers.previous_link&.url&.to_s super(args) end
Public Instance Methods
fetch_next_page()
click to toggle source
# File lib/shopify_api/paginated_collection.rb, line 22 def fetch_next_page fetch_page(@next_url) end
fetch_previous_page()
click to toggle source
# File lib/shopify_api/paginated_collection.rb, line 26 def fetch_previous_page fetch_page(@previous_url) end
next_page?()
click to toggle source
# File lib/shopify_api/paginated_collection.rb, line 12 def next_page? ensure_available @next_url.present? end
next_page_info()
click to toggle source
# File lib/shopify_api/paginated_collection.rb, line 30 def next_page_info extract_page_info(@next_url) end
previous_page?()
click to toggle source
# File lib/shopify_api/paginated_collection.rb, line 17 def previous_page? ensure_available @previous_url.present? end
previous_page_info()
click to toggle source
# File lib/shopify_api/paginated_collection.rb, line 34 def previous_page_info extract_page_info(@previous_url) end
Private Instance Methods
ensure_available()
click to toggle source
# File lib/shopify_api/paginated_collection.rb, line 56 def ensure_available return if ShopifyAPI::Base.api_version >= AVAILABLE_IN_VERSION return if ShopifyAPI::Base.api_version >= AVAILABLE_IN_VERSION_EARLY && resource_class.early_july_pagination? raise NotImplementedError end
extract_page_info(url)
click to toggle source
# File lib/shopify_api/paginated_collection.rb, line 62 def extract_page_info(url) CGI.escape(Rack::Utils.parse_query(URI(url).query)['page_info']) if url.present? end
fetch_page(url)
click to toggle source
# File lib/shopify_api/paginated_collection.rb, line 43 def fetch_page(url) ensure_available return [] unless url.present? resource_class.all(from: url) end
pagination_link_headers()
click to toggle source
# File lib/shopify_api/paginated_collection.rb, line 50 def pagination_link_headers @pagination_link_headers ||= ShopifyAPI::PaginationLinkHeaders.new( ShopifyAPI::Base.connection.response["Link"] ) end