Lokalise APIv2 Ruby SDK

Ruby interface for the Lokalise APIv2 that represents returned data as Ruby objects.

View the Project on GitHub lokalise/ruby-lokalise-api




Branches

Fetch branches

Doc

@client.branches(project_id, params = {})   # Input:
                                            ## project_id (string, required)
                                            ## params (hash)
                                            ### :page and :limit
                                            # Output:
                                            ## Collection of branches

For example:

branches = @client.branches '123.abc', limit: 1, page: 1

branches.project_id # => '123.abc'
branches[0].branch_id # => 123
branches[0].name # => 'branch_name'

Alternatively:

project = @client.project '123.abc'

branches = project.branches limit: 1, page: 1

Fetch branch

Doc

@client.branch(project_id, branch_id)   # Input:
                                        ## project_id (string, required)
                                        ## branch_id (string or integer, required)
                                        # Output:
                                        ## Branch inside the given project

For example:

branch_id = 1234

branch = @client.branch '123.abc', branch_id

branch.branch_id # => 1234
branch.name # => 'branch_name'

Alternatively:

project = @client.project '123.abc'

branch = project.branch branch_id

Create branch

Doc

@client.create_branch(project_id, params)   # Input:
                                            ## project_id (string, required)
                                            ## params (hash, required):
                                            ### :name (string) - name of the branch
                                            # Output:
                                            ## Created branch

For example:

branch = @client.create_branch '123.abc', name: 'ruby-branch'

branch.branch_id # => 1234
branch.name  # => 'ruby-branch'

Alternatively:

project = @client.project '123.abc'

branch = project.create_branch name: 'ruby-branch'

Update branch

Doc

@client.update_branch(project_id, branch_id, params)    # Input:
                                                        ## project_id (string, required)
                                                        ## branch_id (string or integer, required)
                                                        ## params (hash, required):
                                                        ### :name (string) - name of the branch
                                                        # Output:
                                                        ## Updated branch

For example:

branch_id = 1234

branch = @client.update_branch '123.abc', branch_id, name: 'updated-ruby-branch'

branch.name # => 'updated-ruby-branch'

Alternatively:

branch = @client.branch '123.abc', branch_id
updated_branch = branch.update params

# OR

project = @client.project '123.abc'

branch = project.update_branch branch_id, name: 'updated-ruby-branch'

Delete branch

Doc

@client.destroy_branch(project_id, branch_id)   # Input:
                                                ## project_id (string, required)
                                                ## branch_id (string or integer, required)
                                                # Output:
                                                ## Generic object with `branch_deleted` method

For example:

branch_id = 1234

result = @client.destroy_branch '123.abc', branch_id

result.project_id # => '123.abc'
result.branch_deleted # => true

Alternatively:

branch = @client.branch '123.abc', branch_id
result = branch.destroy

# OR

project = @client.project '123.abc'

result = project.destroy_branch branch_id

result.branch_deleted # => true

Merge branch

Doc

@client.merge_branch(project_id, branch_id, params) # Input:
                                                    ## project_id (string, required)
                                                    ## branch_id (string or integer, required)
                                                    ## params (hash)
                                                    # Output:
                                                    ## Generic object with the project's id, "branch_merged"=>true, and branch attributes

For example:

branch_source = 1234
data = {
  force_conflict_resolve_using: 'source',
  target_branch_id: 6789
}

result = @client.merge_branch '123.abc', branch_source, data

result.branch_merged # => true
result.branch['branch_id'] # => 1234
result.target_branch['branch_id'] # => 6789

Alternatively:

branch = @client.branch '123.abc', branch_source
result = branch.merge data

# OR

project = @client.project '123.abc'
result = project.merge_branch branch_source, data