Class: Lokalise::Collections::Base

Inherits:
Object
  • Object
show all
Extended by:
Request, Utils::AttributeHelpers, Utils::EndpointHelpers
Includes:
Utils::AttributeHelpers
Defined in:
lib/ruby-lokalise-api/collections/base.rb

Constant Summary

Constants included from Request

Request::PAGINATION_HEADERS

Constants included from Lokalise::Connection

Lokalise::Connection::BASE_URL

Constants included from Utils::AttributeHelpers

Utils::AttributeHelpers::UNIFIED_RESOURCES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Request

delete, get, patch, post, put

Methods included from JsonHandler

#custom_dump, #custom_load

Methods included from Lokalise::Connection

#connection

Methods included from Utils::AttributeHelpers

attributes_for, data_key_for, id_key_for

Methods included from Utils::EndpointHelpers

path_from

Constructor Details

#initialize(response, params = {}) ⇒ Lokalise::Collections::Base

Initializes a new collection based on the response

Parameters:

  • response (Hash)
  • params (Hash) (defaults to: {})


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ruby-lokalise-api/collections/base.rb', line 19

def initialize(response, params = {})
  produce_collection_for response
  populate_pagination_data_for response
  # Project, team id, user id, and branch may not be present in some cases
  @project_id = response['content']['project_id']
  @team_id = response['content']['team_id']
  @user_id = response['content']['user_id']
  @branch = response['content']['branch']
  @request_params = params
  @client = response['client']
  @path = response['path']
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def branch
  @branch
end

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def client
  @client
end

#collectionObject (readonly)

Returns the value of attribute collection.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def collection
  @collection
end

#current_pageObject (readonly)

Returns the value of attribute current_page.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def current_page
  @current_page
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def path
  @path
end

#project_idObject (readonly)

Returns the value of attribute project_id.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def project_id
  @project_id
end

#request_paramsObject (readonly)

Returns the value of attribute request_params.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def request_params
  @request_params
end

#results_per_pageObject (readonly)

Returns the value of attribute results_per_page.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def results_per_page
  @results_per_page
end

#team_idObject (readonly)

Returns the value of attribute team_id.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def team_id
  @team_id
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def total_pages
  @total_pages
end

#total_resultsObject (readonly)

Returns the value of attribute total_results.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def total_results
  @total_results
end

#user_idObject (readonly)

Returns the value of attribute user_id.



11
12
13
# File 'lib/ruby-lokalise-api/collections/base.rb', line 11

def user_id
  @user_id
end

Class Method Details

.all(client, path, params = {}) ⇒ Object

Performs a batch query fetching multiple records



34
35
36
37
# File 'lib/ruby-lokalise-api/collections/base.rb', line 34

def all(client, path, params = {})
  new get(path, client, params),
      params
end

Instance Method Details

#first_page?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/ruby-lokalise-api/collections/base.rb', line 56

def first_page?
  !prev_page?
end

#last_page?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/ruby-lokalise-api/collections/base.rb', line 46

def last_page?
  !next_page?
end

#next_pageInteger

Returns:

  • (Integer)


61
62
63
64
65
# File 'lib/ruby-lokalise-api/collections/base.rb', line 61

def next_page
  return nil if last_page?

  fetch_page @current_page + 1
end

#next_page?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ruby-lokalise-api/collections/base.rb', line 41

def next_page?
  @current_page.positive? && @current_page < @total_pages
end

#prev_pageInteger

Returns:

  • (Integer)


68
69
70
71
72
# File 'lib/ruby-lokalise-api/collections/base.rb', line 68

def prev_page
  return nil if first_page?

  fetch_page @current_page - 1
end

#prev_page?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/ruby-lokalise-api/collections/base.rb', line 51

def prev_page?
  @current_page > 1
end