Class: PhraseApp::InContextEditor::ApiCollection
- Inherits:
-
Object
- Object
- PhraseApp::InContextEditor::ApiCollection
- Defined in:
- lib/phraseapp-in-context-editor-ruby/api_collection.rb
Instance Method Summary collapse
- #collection ⇒ Object
-
#initialize(api_client, action, ids = [], query = nil) ⇒ ApiCollection
constructor
A new instance of ApiCollection.
Constructor Details
#initialize(api_client, action, ids = [], query = nil) ⇒ ApiCollection
Returns a new instance of ApiCollection.
4 5 6 7 8 9 10 11 |
# File 'lib/phraseapp-in-context-editor-ruby/api_collection.rb', line 4 def initialize(api_client, action, ids=[], query=nil) raise "PhraseApp API client can't handle action #{action}" unless api_client.respond_to?(action) @api_client = api_client @action = action @ids = ids @query = query end |
Instance Method Details
#collection ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/phraseapp-in-context-editor-ruby/api_collection.rb', line 13 def collection results = [] page = 1 per_page = 100 paginated, err = send_request(page, per_page) results << paginated while paginated.size == per_page break if page > 100 page = page + 1 paginated, err = send_request(page, per_page) results << paginated if paginated.present? end results.flatten.uniq end |