transifex 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 575d548058d7c020184041af79a38fe6fae7a179
4
+ data.tar.gz: 9902104e9e3c901af78d694ffabbe7a853518a2e
5
+ SHA512:
6
+ metadata.gz: 79e687d8952341ef2dc0bc9b325c674bbb6f113e7c72f62c5087616f44851994382c5616fbfef0e185e70e42dfebb395690d21eeb86625406f8ae6be1ee85389
7
+ data.tar.gz: f26252e008d6da37de5720c48d7da2ec4b182a52d70e22553fa67a61161fa48de74c49fc0acc6fa2e4c6b6c9080c9044a455e51b3cfb4ee4ab69c4c3823ccce0
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.1.2
5
+ - 2.0.0
6
+ - 1.9.3
7
+ script: bundle exec rspec --tag ~no_travis spec
8
+ bundler_args: --without production
9
+ cache: bundler
10
+ addons:
11
+ code_climate:
12
+ repo_token: f0f77a48e7d3ac45f5d36dcf0f6c1628ebde0ba75acb211dce76b7b36e943d59
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in transifex.gemspec
4
+ gem "codeclimate-test-reporter", group: :test, require: nil
5
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.("routing/#{m[1]}_routing"),
51
+ rspec.spec.("controllers/#{m[1]}_controller"),
52
+ rspec.spec.("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Transifex
2
+
3
+ This is a small gem that allows you to retrive information from a transifex account.
4
+
5
+ [![Build Status](https://travis-ci.org/Albin-trialbee/transifex.png?branch=master)](https://travis-ci.org/Albin-trialbee/transifex)
6
+
7
+ [![Code Climate](https://codeclimate.com/github/Albin-trialbee/transifex/badges/gpa.svg)](https://codeclimate.com/github/Albin-trialbee/transifex)
8
+
9
+ [![Test Coverage](https://codeclimate.com/github/Albin-trialbee/transifex/badges/coverage.svg)](https://codeclimate.com/github/Albin-trialbee/transifex)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'transifex'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install transifex
26
+
27
+ ## Usage
28
+
29
+ The base of everything is the account class which can be used to retrieve projects as shown below.
30
+
31
+ ```ruby
32
+ account = Transifex::Account.new('email', 'pwd')
33
+ projects = account.projects
34
+ project = account.project('project_name')
35
+ ```
36
+
37
+ Projects can the be used to find out what languages it is translated to, what resources are avaliable and retrieve those resources.
38
+
39
+ With a resource you can then retreive the translations for a given language.
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it ( https://github.com/albin-trialbee/transifex/fork )
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "transifex"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require 'transifex/request'
2
+
3
+ module Transifex
4
+ class Account
5
+ include Transifex::Request
6
+
7
+ def initialize(username, password)
8
+ set_credentials(username, password)
9
+ end
10
+
11
+ def projects
12
+ initializ_projects(get('/projects/'))
13
+ end
14
+
15
+ def project(name)
16
+ data = get("/project/#{name}/")
17
+ return if data == 'Not Found'
18
+ Project.new(data, self)
19
+ end
20
+
21
+ private
22
+
23
+ def initializ_projects(project_data_array)
24
+ project_data_array.map do |project_data|
25
+ Project.new(project_data, self)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ require 'transifex/version'
2
+
3
+ module Transifex
4
+ module Config
5
+ BASE_URL = 'https://www.transifex.com'
6
+ USER_AGENT = "transifex #{Transifex::VERSION}"
7
+ VALID_OPTIONS = [:username, :password]
8
+
9
+ attr_accessor *VALID_OPTIONS
10
+ end
11
+ end
@@ -0,0 +1,46 @@
1
+ module Transifex
2
+ class Project
3
+ attr_accessor :name, :description, :slug, :main_language, :account
4
+ def initialize(project_data, account)
5
+ @name = project_data.name
6
+ @description = project_data.description
7
+ @slug = project_data.slug
8
+ @main_language = project_data.source_language_code
9
+ @account = account
10
+ end
11
+
12
+ def resources
13
+ @resources ||= initializ_resources(account.get("#{base_path}/resources/"))
14
+ end
15
+
16
+ def resource(resource_slug)
17
+ resource_data = account.get(resource_path(resource_slug))
18
+ return if resource_data == 'Not Found'
19
+ Resource.new(resource_data, self)
20
+ end
21
+
22
+ def languages
23
+ @languages ||= account.get("#{base_path}/languages/").map(&:language_code)
24
+ end
25
+
26
+ def translation(resource, language_code)
27
+ Translation.new(account.get("#{resource_path(resource.slug)}translation/#{language_code}/"), resource)
28
+ end
29
+
30
+ private
31
+
32
+ def resource_path(resource_slug)
33
+ "#{base_path}/resource/#{resource_slug}/"
34
+ end
35
+
36
+ def base_path
37
+ "/project/#{slug}"
38
+ end
39
+
40
+ def initializ_resources(resource_data_array)
41
+ resource_data_array.map do |resource_data|
42
+ Resource.new(resource_data, self)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,49 @@
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
+ connection.get(build_path(path), params).body
17
+ end
18
+
19
+ private
20
+
21
+ def build_path(path)
22
+ "/api/2/#{path}"
23
+ end
24
+
25
+ def make_connection(username, password)
26
+ options = {
27
+ headers: {
28
+ 'Accept' => 'application/json',
29
+ 'User-Agent' => Transifex::Config::USER_AGENT,
30
+ },
31
+ url: Transifex::Config::BASE_URL
32
+ }
33
+
34
+ Faraday.new(options) do |builder|
35
+ builder.use FaradayMiddleware::Mashify
36
+ builder.use Faraday::Response::ParseJson, :content_type => /\bjson$/
37
+
38
+ # Authentiation
39
+ builder.basic_auth(username, password)
40
+
41
+ # Request Middleware
42
+ builder.use Faraday::Request::Multipart
43
+ builder.use Faraday::Request::UrlEncoded
44
+
45
+ builder.adapter :net_http
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ module Transifex
2
+ class Resource
3
+ attr_accessor :name, :type, :slug, :main_language, :project
4
+ def initialize(data, project)
5
+ @name = data.name
6
+ @type = data.i18n_type
7
+ @slug = data.slug
8
+ @main_language = data.source_language_code
9
+ @project = project
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ require 'yaml'
2
+ module Transifex
3
+ class Translation
4
+ attr_accessor :resource, :content
5
+
6
+ def initialize(data, resource)
7
+ @content = data.content
8
+ @resource = resource
9
+ end
10
+
11
+ def content_hash
12
+ case resource.type.downcase
13
+ when 'yml' then return convert_from_yml
14
+ else
15
+ raise "Unrecognized content type: #{resource.type}"
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def convert_from_yml
22
+ @content_hash ||= YAML.load(content)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Transifex
2
+ VERSION = "0.1.0"
3
+ end
data/lib/transifex.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "transifex/config"
2
+
3
+ module Transifex
4
+
5
+ end
6
+
7
+ require 'transifex/request'
8
+ require 'transifex/account'
9
+ require 'transifex/project'
10
+ require 'transifex/resource'
11
+ require 'transifex/translation'
data/transifex.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'transifex/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "transifex"
8
+ spec.version = Transifex::VERSION
9
+ spec.authors = ["Albin Willman"]
10
+ spec.email = ["j.albin.willman@gmail.com"]
11
+ spec.license = 'MIT'
12
+
13
+ spec.summary = %q{A gem to help comunicate with transifex api}
14
+ spec.description = %q{A gem to help retreive and verify resources on transifex.}
15
+ spec.homepage = "https://github.com/Albin-trialbee/transifex"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'faraday', '~> 0.9.1'
23
+ spec.add_dependency 'faraday_middleware', '~> 0.10.0'
24
+ spec.add_dependency 'hashie', '~> 3.4'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency 'rspec', '~> 3' #, '~> 2.0'
29
+ spec.add_development_dependency 'guard', '~> 2'
30
+ spec.add_development_dependency 'guard-rspec', '~> 4'
31
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transifex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Albin Willman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4'
125
+ description: A gem to help retreive and verify resources on transifex.
126
+ email:
127
+ - j.albin.willman@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - CODE_OF_CONDUCT.md
136
+ - Gemfile
137
+ - Guardfile
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - lib/transifex.rb
143
+ - lib/transifex/account.rb
144
+ - lib/transifex/config.rb
145
+ - lib/transifex/project.rb
146
+ - lib/transifex/request.rb
147
+ - lib/transifex/resource.rb
148
+ - lib/transifex/translation.rb
149
+ - lib/transifex/version.rb
150
+ - transifex.gemspec
151
+ homepage: https://github.com/Albin-trialbee/transifex
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.4.6
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: A gem to help comunicate with transifex api
175
+ test_files: []
176
+ has_rdoc: