Class: Easyship::Pagination::Cursor
- Inherits:
-
Object
- Object
- Easyship::Pagination::Cursor
- Defined in:
- lib/easyship/pagination/cursor.rb
Overview
Represents a pagination object
Constant Summary collapse
- CONFIGURATION_VARIABLES =
i[requests_per_second requests_per_minute].freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#requests_per_minute ⇒ Object
readonly
Returns the value of attribute requests_per_minute.
-
#requests_per_second ⇒ Object
readonly
Returns the value of attribute requests_per_second.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(client, path, params) ⇒ Cursor
constructor
A new instance of Cursor.
Constructor Details
#initialize(client, path, params) ⇒ Cursor
11 12 13 14 15 16 17 18 |
# File 'lib/easyship/pagination/cursor.rb', line 11 def initialize(client, path, params) @client = client @path = path @params = params @per_page = params[:per_page] || Easyship.configuration.per_page @requests_per_second = params[:requests_per_second] || Easyship.configuration.requests_per_second @requests_per_minute = params[:requests_per_minute] || Easyship.configuration.requests_per_minute end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/easyship/pagination/cursor.rb', line 9 def client @client end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/easyship/pagination/cursor.rb', line 9 def key @key end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/easyship/pagination/cursor.rb', line 9 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/easyship/pagination/cursor.rb', line 9 def path @path end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
9 10 11 |
# File 'lib/easyship/pagination/cursor.rb', line 9 def per_page @per_page end |
#requests_per_minute ⇒ Object (readonly)
Returns the value of attribute requests_per_minute.
9 10 11 |
# File 'lib/easyship/pagination/cursor.rb', line 9 def requests_per_minute @requests_per_minute end |
#requests_per_second ⇒ Object (readonly)
Returns the value of attribute requests_per_second.
9 10 11 |
# File 'lib/easyship/pagination/cursor.rb', line 9 def requests_per_second @requests_per_second end |
Instance Method Details
#all ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/easyship/pagination/cursor.rb', line 20 def all page = 1 loop do limiter.throttle! body = client.get(path, build_request_params(page: page)) break if body.nil? || body.empty? yield body break if body.dig(:meta, :pagination, :next).nil? page += 1 end end |