transifex-ruby 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +119 -0
- data/Rakefile +1 -0
- data/lib/transifex.rb +12 -0
- data/lib/transifex/client.rb +26 -0
- data/lib/transifex/config.rb +16 -0
- data/lib/transifex/error.rb +17 -0
- data/lib/transifex/language.rb +14 -0
- data/lib/transifex/project.rb +30 -0
- data/lib/transifex/request.rb +51 -0
- data/lib/transifex/resource.rb +27 -0
- data/lib/transifex/response/raise_http_exception.rb +30 -0
- data/lib/transifex/stats.rb +18 -0
- data/lib/transifex/version.rb +3 -0
- data/spec/fixtures/languages.json +30 -0
- data/spec/fixtures/project.json +6 -0
- data/spec/fixtures/projects.json +26 -0
- data/spec/fixtures/resource.json +8 -0
- data/spec/fixtures/resources.json +18 -0
- data/spec/fixtures/stats.json +11 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/transifex/client_spec.rb +100 -0
- data/spec/transifex/error_spec.rb +30 -0
- data/spec/transifex_spec.rb +23 -0
- data/transifex-ruby.gemspec +32 -0
- metadata +209 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed8eea4b0e320611fb6b72e808a2b222d2fb2bb5
|
4
|
+
data.tar.gz: e5fc773fee8dcee8d8b1d219f2bf48dedcfde746
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ede60f493498e5c7299509679b207142cba1de9bf90f6d3cf3052d5f13ddac4cea0951cbd468e4962a97b9e1c4ce855a231ec1a9a9a2fded776ab9566e524b9
|
7
|
+
data.tar.gz: 7d7fd79650159b30d190b4d46af721adc53ee84880cb6fe13b67616905bb372446450dcef6caf6415666432dce1c3463e751103d6a332eda960d7d07a268ea98
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Toru Maesaka
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# Ruby Client for the Transifex API
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
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.
|
6
|
+
|
7
|
+
## Status
|
8
|
+
|
9
|
+
transifex-ruby is currently under development and should not be used for mission critical purposes at this stage.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
This gem is only available on GitHub at this time. Add the following line to your Gemfile if you wish to use it.
|
14
|
+
|
15
|
+
gem 'transifex-ruby', git: 'git@github.com:tmaesaka/transifex-ruby.git'
|
16
|
+
|
17
|
+
## Quick Examples
|
18
|
+
|
19
|
+
### It all begins by requiring
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'transifex'
|
23
|
+
```
|
24
|
+
|
25
|
+
### Providing Credentials
|
26
|
+
|
27
|
+
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.
|
28
|
+
|
29
|
+
#### Method 1: Global Scope
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Transifex.configure do |config|
|
33
|
+
config.username = 'banana'
|
34
|
+
config.password = 'smoothy'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
#### Method 2: Credentials per Transifex::Client object
|
39
|
+
|
40
|
+
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.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
Transifex::Client.new(username: 'banana', password: 'smoothy')
|
44
|
+
```
|
45
|
+
|
46
|
+
### Retrieving a list of Projects that the user has access to
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
transifex = Transifex::Client.new
|
50
|
+
transifex.projects # => Array of Transifex::Project objects
|
51
|
+
transifex.projects.each do |project|
|
52
|
+
project.name
|
53
|
+
project.slug
|
54
|
+
project.description
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
### Retrieving a particular Project by its identifier (slug)
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
slug = 'transifex'
|
62
|
+
transifex = Transifex::Client.new
|
63
|
+
transifex.project(slug) # => Transifex::Project object
|
64
|
+
```
|
65
|
+
|
66
|
+
### Retrieving the Resource(s) of a particular Project
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
slug = 'transifex'
|
70
|
+
transifex = Transifex::Client.new
|
71
|
+
project = transifex.project(slug) # => Transifex::Project object
|
72
|
+
project.resources # => Array of Transifex::Resource objects
|
73
|
+
project.resources.each do |resource|
|
74
|
+
resource.name
|
75
|
+
resource.slug
|
76
|
+
...
|
77
|
+
end
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
### Retrieving a particular Resource of a Project by its identifier (slug)
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
project_slug = 'ima_project'
|
85
|
+
resource_slug = 'ima_resource'
|
86
|
+
transifex = Transifex::Client.new
|
87
|
+
project = transifex.project(project_slug) # => Transifex::Project object
|
88
|
+
resource = project.resource(resource_slug) # => Transifex::Resource object
|
89
|
+
resource.translation(:en) # => English Translation (if exists)
|
90
|
+
resource.translation(:ja) # => Japanese Translation (if exists)
|
91
|
+
...
|
92
|
+
```
|
93
|
+
|
94
|
+
### Retrieving the Language(s) of a particular Project
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
slug = 'transifex'
|
98
|
+
transifex = Transifex::Client.new
|
99
|
+
project = transifex.project(slug) # => Transifex::Project object
|
100
|
+
project.languages # => Array of Transifex::Language objects
|
101
|
+
project.languages.each do |language|
|
102
|
+
language.language_code
|
103
|
+
language.reviewers
|
104
|
+
...
|
105
|
+
end
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
## Caching
|
110
|
+
|
111
|
+
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.
|
112
|
+
|
113
|
+
## Thread Safety
|
114
|
+
|
115
|
+
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.
|
116
|
+
|
117
|
+
## Reaching Out
|
118
|
+
|
119
|
+
Please feel free to ping [@tmaesaka](http://twitter.com/tmaesaka) if you'd like to hit the author up or send me a message here on GitHub.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/transifex.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'transifex/request'
|
2
|
+
|
3
|
+
module Transifex
|
4
|
+
class Client
|
5
|
+
include Transifex::Request
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
set_credentials(
|
9
|
+
options[:username] || Transifex.username,
|
10
|
+
options[:password] || Transifex.password
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def projects
|
15
|
+
get('/projects/').map do |project|
|
16
|
+
Transifex::Project.new(project).tap {|p| p.client = self }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def project(slug)
|
21
|
+
Transifex::Project.new(get("/project/#{slug}/")).tap do |project|
|
22
|
+
project.client = self
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'transifex/version'
|
2
|
+
require 'transifex/response/raise_http_exception'
|
3
|
+
|
4
|
+
module Transifex
|
5
|
+
module Config
|
6
|
+
BASE_URL = ENV['TRANSIFEX_BASE_URL'] || 'https://www.transifex.com'
|
7
|
+
USER_AGENT = "transifex-ruby #{Transifex::VERSION}"
|
8
|
+
VALID_OPTIONS = [:username, :password]
|
9
|
+
|
10
|
+
attr_accessor *VALID_OPTIONS
|
11
|
+
|
12
|
+
def configure
|
13
|
+
yield self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Transifex
|
2
|
+
class Error < StandardError
|
3
|
+
attr_accessor :response
|
4
|
+
def initialize(response = nil)
|
5
|
+
@response = response
|
6
|
+
super
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Unauthorized < Error; end
|
11
|
+
class Forbidden < Error; end
|
12
|
+
class NotFound < Error; end
|
13
|
+
class NotAcceptable < Error; end
|
14
|
+
class Conflict < Error; end
|
15
|
+
class UnsupportedMediaType < Error; end
|
16
|
+
class UnprocessableEntity < Error; end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Transifex
|
2
|
+
class Language
|
3
|
+
attr_accessor :client, :language_code, :coordinators, :translators, :reviewers
|
4
|
+
|
5
|
+
def initialize(project_slug, transifex_data)
|
6
|
+
@project_slug = project_slug
|
7
|
+
@language_code = transifex_data[:language_code]
|
8
|
+
@coordinators = transifex_data[:coordinators]
|
9
|
+
@translators = transifex_data[:translators]
|
10
|
+
@reviewers = transifex_data[:reviewers]
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Transifex
|
2
|
+
class Project
|
3
|
+
attr_accessor :client, :name, :description, :source_language_code, :slug
|
4
|
+
|
5
|
+
def initialize(transifex_data)
|
6
|
+
@name = transifex_data[:name]
|
7
|
+
@description = transifex_data[:description]
|
8
|
+
@source_language_code = transifex_data[:source_langauge_code]
|
9
|
+
@slug = transifex_data[:slug]
|
10
|
+
end
|
11
|
+
|
12
|
+
def resources
|
13
|
+
client.get("/project/#{@slug}/resources/").map do |resource|
|
14
|
+
Transifex::Resource.new(@slug, resource).tap {|r| r.client = client }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def resource(resource_slug)
|
19
|
+
resource = client.get("/project/#{@slug}/resource/#{resource_slug}")
|
20
|
+
Transifex::Resource.new(@slug, resource).tap {|r| r.client = client }
|
21
|
+
end
|
22
|
+
|
23
|
+
def languages
|
24
|
+
client.get("/project/#{@slug}/languages/").map do |language|
|
25
|
+
Transifex::Language.new(@slug, language).tap {|r| r.client = client }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Transifex
|
5
|
+
module Request
|
6
|
+
def set_credentials(username, password)
|
7
|
+
@username = username
|
8
|
+
@password = password
|
9
|
+
end
|
10
|
+
|
11
|
+
def connection
|
12
|
+
@connection ||= make_connection(@username, @password)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(path, params = {})
|
16
|
+
response = connection.get(build_path(:v2, path), params)
|
17
|
+
response.body
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def build_path(version, path)
|
23
|
+
"/api/2/#{path}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def make_connection(username, password)
|
27
|
+
options = {
|
28
|
+
headers: {
|
29
|
+
'Accept' => 'application/json',
|
30
|
+
'User-Agent' => Transifex::Config::USER_AGENT,
|
31
|
+
},
|
32
|
+
url: Transifex::Config::BASE_URL
|
33
|
+
}
|
34
|
+
|
35
|
+
Faraday.new(options) do |builder|
|
36
|
+
builder.use FaradayMiddleware::Mashify
|
37
|
+
builder.use Faraday::Response::ParseJson, :content_type => /\bjson$/
|
38
|
+
builder.use Transifex::Response::RaiseHttpException
|
39
|
+
|
40
|
+
# Authentiation
|
41
|
+
builder.basic_auth(username, password)
|
42
|
+
|
43
|
+
# Request Middleware
|
44
|
+
builder.use Faraday::Request::Multipart
|
45
|
+
builder.use Faraday::Request::UrlEncoded
|
46
|
+
|
47
|
+
builder.adapter :net_http
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Transifex
|
2
|
+
class Resource
|
3
|
+
attr_accessor :client, :category, :i18n_type, :source_language_code, :slug, :name
|
4
|
+
|
5
|
+
def initialize(project_slug, transifex_data)
|
6
|
+
@project_slug = project_slug
|
7
|
+
@name = transifex_data[:name]
|
8
|
+
@category = transifex_data[:category]
|
9
|
+
@i18n_type = transifex_data[:i18n_type]
|
10
|
+
@source_language_code = transifex_data[:source_language_code]
|
11
|
+
@slug = transifex_data[:slug]
|
12
|
+
end
|
13
|
+
|
14
|
+
def content
|
15
|
+
client.get("/project/#{@project_slug}/resource/#{@slug}/content/")
|
16
|
+
end
|
17
|
+
|
18
|
+
def translation(lang)
|
19
|
+
client.get("/project/#{@project_slug}/resource/#{@slug}/translation/#{lang}/")
|
20
|
+
end
|
21
|
+
|
22
|
+
def stats(lang)
|
23
|
+
stats = client.get("/project/#{@project_slug}/resource/#{@slug}/stats/#{lang}")
|
24
|
+
Transifex::Stats.new(stats).tap {|r| r.client = client }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'transifex/error'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Transifex
|
5
|
+
module Response
|
6
|
+
class RaiseHttpException < Faraday::Response::Middleware
|
7
|
+
def call(env)
|
8
|
+
@app.call(env).on_complete do |response|
|
9
|
+
resp = response[:response]
|
10
|
+
case response[:status].to_i
|
11
|
+
when 401
|
12
|
+
raise Transifex::Unauthorized.new(resp)
|
13
|
+
when 403
|
14
|
+
raise Transifex::Forbidden.new(resp)
|
15
|
+
when 404
|
16
|
+
raise Transifex::NotFound.new(resp)
|
17
|
+
when 406
|
18
|
+
raise Transifex::NotAcceptable.new(resp)
|
19
|
+
when 409
|
20
|
+
raise Transifex::Conflict.new(resp)
|
21
|
+
when 415
|
22
|
+
raise Transifex::UnsupportedMediaType.new(resp)
|
23
|
+
when 422
|
24
|
+
raise Transifex::UnprocessableEntity.new(resp)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Transifex
|
2
|
+
class Stats
|
3
|
+
attr_accessor :client, :completed, :translated_entities, :untranslated_entities, :translated_words, :untranslated_words, :last_update, :last_committer, :reviewed, :reviewed_percentage
|
4
|
+
|
5
|
+
def initialize(transifex_data)
|
6
|
+
@completed = transifex_data[:completed]
|
7
|
+
@translated_entities = transifex_data[:translated_entities]
|
8
|
+
@untranslated_entities = transifex_data[:untranslated_entities]
|
9
|
+
@translated_words = transifex_data[:translated_words]
|
10
|
+
@untranslated_words = transifex_data[:untranslated_words]
|
11
|
+
@last_update = transifex_data[:last_update]
|
12
|
+
@last_committer = transifex_data[:last_committer]
|
13
|
+
@reviewed = transifex_data[:reviewed]
|
14
|
+
@reviewed_percentage = transifex_data[:reviewed_percentage]
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"language_code": "el",
|
4
|
+
"coordinators": [
|
5
|
+
"kbairak",
|
6
|
+
"glezos"
|
7
|
+
],
|
8
|
+
"translators": [
|
9
|
+
"mpessas",
|
10
|
+
"jkal"
|
11
|
+
],
|
12
|
+
"reviewers": [
|
13
|
+
"sawidis",
|
14
|
+
"ilias"
|
15
|
+
]
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"language_code": "hi",
|
19
|
+
"coordinators": [
|
20
|
+
"rajeshr",
|
21
|
+
"rtnpro"
|
22
|
+
],
|
23
|
+
"translators": [
|
24
|
+
"sayan"
|
25
|
+
],
|
26
|
+
"reviewers": [
|
27
|
+
"chandankumar"
|
28
|
+
]
|
29
|
+
}
|
30
|
+
]
|
@@ -0,0 +1,26 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"description": "test",
|
4
|
+
"source_language_code": "en",
|
5
|
+
"slug": "tesuto",
|
6
|
+
"name": "テスト"
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"description": "test",
|
10
|
+
"source_language_code": "en",
|
11
|
+
"slug": "tesutopuroziekuto",
|
12
|
+
"name": "テストプロジェクト"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"description": "3D printer software",
|
16
|
+
"source_language_code": "en",
|
17
|
+
"slug": "03dzyx",
|
18
|
+
"name": "03dzyx"
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"description": "A simple yet challenging puzzle game.",
|
22
|
+
"source_language_code": "en",
|
23
|
+
"slug": "100boxes",
|
24
|
+
"name": "100 Boxes"
|
25
|
+
}
|
26
|
+
]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"source_language_code": "en",
|
4
|
+
"name": "Core",
|
5
|
+
"i18n_type": "PO",
|
6
|
+
"priority": "0",
|
7
|
+
"slug": "core",
|
8
|
+
"categories": null
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"source_language_code": "en",
|
12
|
+
"name": "www.transifex.com",
|
13
|
+
"i18n_type": "TX",
|
14
|
+
"priority": "0",
|
15
|
+
"slug": "wwwtransifexcom",
|
16
|
+
"categories": null
|
17
|
+
}
|
18
|
+
]
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{
|
2
|
+
"reviewed_percentage": "0%",
|
3
|
+
"completed": "100%",
|
4
|
+
"untranslated_words": 0,
|
5
|
+
"last_commiter": "transifex",
|
6
|
+
"reviewed": 0,
|
7
|
+
"translated_entities": 2210,
|
8
|
+
"translated_words": 15408,
|
9
|
+
"last_update": "2014-10-23 16:16:26",
|
10
|
+
"untranslated_entities": 0
|
11
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'pry'
|
3
|
+
require 'rspec'
|
4
|
+
require 'transifex'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
|
7
|
+
BASE_HEADERS = { :content_type => 'application/json; charset=utf-8' }
|
8
|
+
|
9
|
+
def make_endpoint(path)
|
10
|
+
URI.join(Transifex::Config::BASE_URL, "/api/2/#{path}").to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def stub_get(path)
|
14
|
+
stub_request(:get, make_endpoint(path))
|
15
|
+
end
|
16
|
+
|
17
|
+
def fixture(file)
|
18
|
+
prefix = File.expand_path('../fixtures', __FILE__)
|
19
|
+
File.new(File.join(prefix, file))
|
20
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Transifex::Client do
|
4
|
+
let(:client) { Transifex::Client.new }
|
5
|
+
|
6
|
+
describe '#projects' do
|
7
|
+
subject { client.projects }
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub_get('/projects/').to_return(
|
11
|
+
body: fixture('projects.json'),
|
12
|
+
headers: BASE_HEADERS
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns an array of Project objects' do
|
17
|
+
subject.each {|p| p.should be_a Transifex::Project }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#project' do
|
22
|
+
let(:slug) { 'transifex' }
|
23
|
+
subject { client.project(slug) }
|
24
|
+
|
25
|
+
before do
|
26
|
+
stub_get("/project/#{slug}/").to_return(
|
27
|
+
body: fixture('project.json'),
|
28
|
+
headers: BASE_HEADERS
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns a Project object' do
|
33
|
+
should be_a Transifex::Project
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#resources' do
|
37
|
+
subject { client.project(slug).resources }
|
38
|
+
|
39
|
+
before do
|
40
|
+
stub_get("/project/#{slug}/resources/").to_return(
|
41
|
+
body: fixture('resources.json'),
|
42
|
+
headers: BASE_HEADERS
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns an array of Resource objects' do
|
47
|
+
subject.each {|p| p.should be_a Transifex::Resource }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#resource' do
|
52
|
+
let(:resource_slug) { 'core' }
|
53
|
+
subject { client.project(slug).resource(resource_slug) }
|
54
|
+
|
55
|
+
before do
|
56
|
+
stub_get("/project/#{slug}/resource/#{resource_slug}").to_return(
|
57
|
+
body: fixture('resource.json'),
|
58
|
+
headers: BASE_HEADERS
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns an Resource object' do
|
63
|
+
subject.should be_a Transifex::Resource
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#stats' do
|
67
|
+
let(:resource_slug) { 'core' }
|
68
|
+
let(:lang) { 'en' }
|
69
|
+
subject { client.project(slug).resource(resource_slug).stats(lang) }
|
70
|
+
|
71
|
+
before do
|
72
|
+
stub_get("/project/#{slug}/resource/#{resource_slug}/stats/#{lang}").to_return(
|
73
|
+
body: fixture('stats.json'),
|
74
|
+
headers: BASE_HEADERS
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns an Stats object' do
|
79
|
+
subject.should be_a Transifex::Stats
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#languages' do
|
85
|
+
subject { client.project(slug).languages }
|
86
|
+
|
87
|
+
before do
|
88
|
+
stub_get("/project/#{slug}/languages/").to_return(
|
89
|
+
body: fixture('languages.json'),
|
90
|
+
headers: BASE_HEADERS
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns an array of Language objects' do
|
95
|
+
subject.each {|p| p.should be_a Transifex::Language }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Transifex::Error do
|
4
|
+
let(:client) { Transifex::Client.new }
|
5
|
+
|
6
|
+
{
|
7
|
+
401 => Transifex::Unauthorized,
|
8
|
+
403 => Transifex::Forbidden,
|
9
|
+
404 => Transifex::NotFound,
|
10
|
+
406 => Transifex::NotAcceptable,
|
11
|
+
409 => Transifex::Conflict,
|
12
|
+
415 => Transifex::UnsupportedMediaType,
|
13
|
+
422 => Transifex::UnprocessableEntity,
|
14
|
+
}.each do |status, exception|
|
15
|
+
context "when HTTP response status is #{status}" do
|
16
|
+
before do
|
17
|
+
stub_get('/project/xyz/').to_return(status: status)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise #{exception.name} error" do
|
21
|
+
expect {
|
22
|
+
client.project('xyz')
|
23
|
+
}.to raise_error(exception) { |e|
|
24
|
+
e.should be_a_kind_of(Transifex::Error)
|
25
|
+
e.should respond_to(:response)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Transifex do
|
4
|
+
describe '#configure' do
|
5
|
+
let(:username) { 'nadia' }
|
6
|
+
let(:password) { 'candy' }
|
7
|
+
|
8
|
+
before do
|
9
|
+
Transifex.configure do |config|
|
10
|
+
config.username = username
|
11
|
+
config.password = password
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'stores the username' do
|
16
|
+
expect(Transifex.username).to eql username
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'stores the password' do
|
20
|
+
expect(Transifex.password).to eql password
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'transifex/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.version = Transifex::VERSION
|
9
|
+
s.name = 'transifex-ruby'
|
10
|
+
s.license = 'MIT'
|
11
|
+
s.homepage = 'http://github.com/tmaesaka/transifex-ruby'
|
12
|
+
s.summary = 'Ruby client library for Transifex API'
|
13
|
+
s.description = s.summary
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split($/)
|
16
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
s.authors = ['Toru Maesaka', 'Jason Barnabe']
|
20
|
+
s.email = ['toru@tmaesaka.com', 'jason.barnabe@gmail.com']
|
21
|
+
|
22
|
+
s.add_dependency 'faraday', '~> 0.8.0'
|
23
|
+
s.add_dependency 'faraday_middleware', '~> 0.9.0'
|
24
|
+
s.add_dependency 'hashie', '~> 1.2.0'
|
25
|
+
|
26
|
+
s.add_development_dependency 'bundler', '~> 1.3'
|
27
|
+
s.add_development_dependency 'rake'
|
28
|
+
s.add_development_dependency 'rspec'
|
29
|
+
s.add_development_dependency 'guard-rspec'
|
30
|
+
s.add_development_dependency 'webmock'
|
31
|
+
s.add_development_dependency 'pry'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: transifex-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Toru Maesaka
|
8
|
+
- Jason Barnabe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.8.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.8.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: faraday_middleware
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.9.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.9.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: hashie
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.2.0
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.2.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.3'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.3'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: guard-rspec
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: webmock
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: pry
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
description: Ruby client library for Transifex API
|
141
|
+
email:
|
142
|
+
- toru@tmaesaka.com
|
143
|
+
- jason.barnabe@gmail.com
|
144
|
+
executables: []
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- ".gitignore"
|
149
|
+
- Gemfile
|
150
|
+
- LICENSE
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- lib/transifex.rb
|
154
|
+
- lib/transifex/client.rb
|
155
|
+
- lib/transifex/config.rb
|
156
|
+
- lib/transifex/error.rb
|
157
|
+
- lib/transifex/language.rb
|
158
|
+
- lib/transifex/project.rb
|
159
|
+
- lib/transifex/request.rb
|
160
|
+
- lib/transifex/resource.rb
|
161
|
+
- lib/transifex/response/raise_http_exception.rb
|
162
|
+
- lib/transifex/stats.rb
|
163
|
+
- lib/transifex/version.rb
|
164
|
+
- spec/fixtures/languages.json
|
165
|
+
- spec/fixtures/project.json
|
166
|
+
- spec/fixtures/projects.json
|
167
|
+
- spec/fixtures/resource.json
|
168
|
+
- spec/fixtures/resources.json
|
169
|
+
- spec/fixtures/stats.json
|
170
|
+
- spec/spec_helper.rb
|
171
|
+
- spec/transifex/client_spec.rb
|
172
|
+
- spec/transifex/error_spec.rb
|
173
|
+
- spec/transifex_spec.rb
|
174
|
+
- transifex-ruby.gemspec
|
175
|
+
homepage: http://github.com/tmaesaka/transifex-ruby
|
176
|
+
licenses:
|
177
|
+
- MIT
|
178
|
+
metadata: {}
|
179
|
+
post_install_message:
|
180
|
+
rdoc_options: []
|
181
|
+
require_paths:
|
182
|
+
- lib
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
requirements: []
|
194
|
+
rubyforge_project:
|
195
|
+
rubygems_version: 2.4.2
|
196
|
+
signing_key:
|
197
|
+
specification_version: 4
|
198
|
+
summary: Ruby client library for Transifex API
|
199
|
+
test_files:
|
200
|
+
- spec/fixtures/languages.json
|
201
|
+
- spec/fixtures/project.json
|
202
|
+
- spec/fixtures/projects.json
|
203
|
+
- spec/fixtures/resource.json
|
204
|
+
- spec/fixtures/resources.json
|
205
|
+
- spec/fixtures/stats.json
|
206
|
+
- spec/spec_helper.rb
|
207
|
+
- spec/transifex/client_spec.rb
|
208
|
+
- spec/transifex/error_spec.rb
|
209
|
+
- spec/transifex_spec.rb
|