Class: PhraseApp::InContextEditor::ApiCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/phraseapp-in-context-editor-ruby/api_collection.rb

Instance Method Summary collapse

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

#collectionObject



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