ryz310/my_api_client

View on GitHub
example/api_clients/my_pagination_api_client.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

require_relative 'application_api_client'

# An usage example of the `my_api_client`.
# See also: my_api/app/controllers/pagination_controller.rb
class MyPaginationApiClient < ApplicationApiClient
  # Paging with JSONPath
  # GET pagination?page=1
  def paging_with_jsonpath
    pget 'pagination', headers: headers, query: { page: 1 }, paging: '$.links.next'
  end

  # Paging with Proc
  # GET pagination?page=1
  def paging_with_proc
    pget 'pagination', headers: headers, query: { page: 1 }, paging: lambda { |response|
      response.data.links.next
    }
  end

  private

  def headers
    { 'Content-Type': 'application/json;charset=UTF-8' }
  end
end