Class: Printavo::Resources::Base
- Inherits:
-
Object
- Object
- Printavo::Resources::Base
- Defined in:
- lib/printavo/resources/base.rb
Direct Known Subclasses
Account, ApprovalRequests, Categories, Contacts, ContractorProfiles, CustomAddresses, Customers, DeliveryMethods, EmailTemplates, Expenses, Fees, Imprints, Inquiries, Invoices, Jobs, LineItemGroups, LineItems, MerchOrders, MerchStores, Mockups, Orders, PaymentRequests, PaymentTerms, Payments, PresetTaskGroups, PresetTasks, PricingMatrices, ProductionFiles, Products, Statuses, Tasks, Threads, TransactionPayments, Transactions, TypesOfWork, Users, Vendors
Instance Method Summary collapse
-
#all_pages(first: 25, **kwargs) ⇒ Array
Returns all records across all pages as a flat Array.
-
#each_page(first: 25, **kwargs) {|records| ... } ⇒ Object
Yields each page of records as an Array, following cursors automatically.
-
#initialize(graphql) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(graphql) ⇒ Base
Returns a new instance of Base.
7 8 9 |
# File 'lib/printavo/resources/base.rb', line 7 def initialize(graphql) @graphql = graphql end |
Instance Method Details
#all_pages(first: 25, **kwargs) ⇒ Array
Returns all records across all pages as a flat Array. Extra keyword arguments are forwarded to fetch_page (e.g. order_id: for Jobs).
41 42 43 |
# File 'lib/printavo/resources/base.rb', line 41 def all_pages(first: 25, **kwargs) [].tap { |all| each_page(first: first, **kwargs) { |records| all.concat(records) } } end |
#each_page(first: 25, **kwargs) {|records| ... } ⇒ Object
Yields each page of records as an Array, following cursors automatically. Extra keyword arguments are forwarded to fetch_page (e.g. order_id: for Jobs).
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/printavo/resources/base.rb', line 21 def each_page(first: 25, **kwargs) after = nil loop do page = fetch_page(first: first, after: after, **kwargs) yield(page.records) break unless page.has_next_page after = page.end_cursor end end |