Skip to content

Latest commit

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Ruby Client for the Transifex API

This project only works with the now-discontinued Transifex API v2. Visit the Transifex Developer Hub for current API options.

Introduction

transifex-ruby is a Ruby client library for mechanically accessing Transifex via its API. It is intended to be simple and only provide a primitive interface to the API.

Status

transifex-ruby is currently under development and should not be used for mission critical purposes at this stage.

Installation

This gem is only available on GitHub at this time. Add the following line to your Gemfile if you wish to use it.

 gem 'transifex-ruby', git: 'git@github.com:tmaesaka/transifex-ruby.git'

Quick Examples

It all begins by requiring

require'transifex'

Providing Credentials

For obvious reasons you must authenticate the user in order to use the API. There are two ways to setup the library with your Transifex credentials.

Method 1: Global Scope

Transifex.configuredo |config|
config.username='banana'config.password='smoothy'end

Method 2: Credentials per Transifex::Client object

This is the preferred way if your application is intended for multiple Transifex users. Object level credentials have greater precedence than the globally scoped ones shown in method 1.

Transifex::Client.new(username: 'banana',password: 'smoothy')

Retrieving a list of Projects that the user has access to

transifex=Transifex::Client.newtransifex.projects# => Array of Transifex::Project objectstransifex.projects.eachdo |project|
project.nameproject.slugproject.descriptionend

Retrieving a particular Project by its identifier (slug)

slug='transifex'transifex=Transifex::Client.newtransifex.project(slug)# => Transifex::Project object

Retrieving the Resource(s) of a particular Project

slug='transifex'transifex=Transifex::Client.newproject=transifex.project(slug)# => Transifex::Project objectproject.resources# => Array of Transifex::Resource objectsproject.resources.eachdo |resource|
resource.nameresource.slug
...
end

Retrieving a particular Resource of a Project by its identifier (slug)

project_slug='ima_project'resource_slug='ima_resource'transifex=Transifex::Client.newproject=transifex.project(project_slug)# => Transifex::Project objectresource=project.resource(resource_slug)# => Transifex::Resource objectresource.translation(:en)# => English Translation (if exists)resource.translation(:ja)# => Japanese Translation (if exists)
...

Retrieving the Language(s) of a particular Project

slug='transifex'transifex=Transifex::Client.newproject=transifex.project(slug)# => Transifex::Project objectproject.languages# => Array of Transifex::Language objectsproject.languages.eachdo |language|
language.language_codelanguage.reviewers
...
end

Caching

transifex-ruby won't do any read-through caching so your application is responsible for caching the results in order to avoid throwing wasteful HTTP requests. Response caching at the library level may be supported in the future but we're not too concerned about this right now.

Thread Safety

The first version of transifex-ruby is naive in a way that Transifex::Resource and Transifex::Project objects will reuse the connection of the Transifex::Client object that had instantiated them. We will change this design if there's enough demand.

Reaching Out

Please feel free to ping @tmaesaka if you'd like to hit the author up or send me a message here on GitHub.

About

Ruby client library for the Transifex API

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages