Class: RubyLokaliseApi::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 Utils::AttributeHelpers

Utils::AttributeHelpers::UNIFIED_RESOURCES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseRequest

#delete, #get, #patch, #post, #put

Methods included from RubyLokaliseApi::Connection

#connection

Methods included from JsonHandler

#custom_dump, #custom_load

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 = {}) ⇒ RubyLokaliseApi::Collections::Base

Initializes a new collection based on the response

Parameters:

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


21
22
23
24
25
26
# File 'lib/ruby_lokalise_api/collections/base.rb', line 21

def initialize(response, params = {})
  produce_collection_for response
  populate_pagination_data_for response
  @request_params = params
  popular_common_attrs response
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def branch
  @branch
end

#clientObject (readonly)

Returns the value of attribute client.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def client
  @client
end

#collectionObject (readonly)

Returns the value of attribute collection.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def collection
  @collection
end

#current_pageObject (readonly)

Returns the value of attribute current_page.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def current_page
  @current_page
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def path
  @path
end

#project_idObject (readonly)

Returns the value of attribute project_id.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def project_id
  @project_id
end

#request_paramsObject (readonly)

Returns the value of attribute request_params.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def request_params
  @request_params
end

#results_per_pageObject (readonly)

Returns the value of attribute results_per_page.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def results_per_page
  @results_per_page
end

#team_idObject (readonly)

Returns the value of attribute team_id.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def team_id
  @team_id
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def total_pages
  @total_pages
end

#total_resultsObject (readonly)

Returns the value of attribute total_results.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def total_results
  @total_results
end

#user_idObject (readonly)

Returns the value of attribute user_id.



13
14
15
# File 'lib/ruby_lokalise_api/collections/base.rb', line 13

def user_id
  @user_id
end

Class Method Details

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

Performs a batch query fetching multiple records



30
31
32
33
# File 'lib/ruby_lokalise_api/collections/base.rb', line 30

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

Instance Method Details

#first_page?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/ruby_lokalise_api/collections/base.rb', line 52

def first_page?
  !prev_page?
end

#last_page?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/ruby_lokalise_api/collections/base.rb', line 42

def last_page?
  !next_page?
end

#next_pageInteger

Returns:

  • (Integer)


57
58
59
60
61
# File 'lib/ruby_lokalise_api/collections/base.rb', line 57

def next_page
  return nil if last_page?

  fetch_page @current_page + 1
end

#next_page?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/ruby_lokalise_api/collections/base.rb', line 37

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

#prev_pageInteger

Returns:

  • (Integer)


64
65
66
67
68
# File 'lib/ruby_lokalise_api/collections/base.rb', line 64

def prev_page
  return nil if first_page?

  fetch_page @current_page - 1
end

#prev_page?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/ruby_lokalise_api/collections/base.rb', line 47

def prev_page?
  @current_page > 1
end