yatapp 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -3
- data/lib/yatapp.rb +16 -1
- data/lib/yatapp/railtie.rb +1 -1
- data/lib/yatapp/version.rb +1 -1
- data/lib/yatapp/yata_api_caller.rb +33 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dbe1c5a64e29009ab512366f7a2e6ede27c50e7
|
4
|
+
data.tar.gz: 5654dee734b05c1c0f1f4f428232a50c465a879b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d02007ced84f0a3a8360e8ac81d8846a378870b2f519bb143fd268da84127edac8d7586ee56ae78c0550415dd2601e7dc8b96e856665ba7cbcbbc779d5a14f7b
|
7
|
+
data.tar.gz: 6230cc9d356e9e8422dfad4fb7e152504f55691fba050edc5b091ca807a5ae2d48913e366f16040e3186fa6fe2b0de6e7b66fa5aab6ca577d283b9e506bfe892
|
data/README.md
CHANGED
@@ -25,12 +25,17 @@ in your rails project:
|
|
25
25
|
|
26
26
|
|
27
27
|
```ruby
|
28
|
+
|
28
29
|
include Yatapp
|
29
30
|
|
30
31
|
Yatapp.configure do |c|
|
31
|
-
c.
|
32
|
-
|
33
|
-
|
32
|
+
c.api_access_token = ENV['YATA_API_KEY'] # access key to Yata
|
33
|
+
end
|
34
|
+
|
35
|
+
yata_project do
|
36
|
+
project_id 'your-project-id' # project id you wish to fetch from (you can find it under settings of your organization)
|
37
|
+
languages ['en', 'de'] # add any languages you wish by language code
|
38
|
+
format :json # format you wish to get files in, available for now are (yaml and json)
|
34
39
|
end
|
35
40
|
|
36
41
|
```
|
data/lib/yatapp.rb
CHANGED
@@ -15,10 +15,25 @@ module Yatapp
|
|
15
15
|
def api_caller
|
16
16
|
@api_caller ||= YataApiCaller.new
|
17
17
|
end
|
18
|
-
|
19
18
|
end
|
20
19
|
|
21
20
|
module Methods
|
21
|
+
def yata_project
|
22
|
+
yield
|
23
|
+
end
|
24
|
+
|
25
|
+
def languages(languages)
|
26
|
+
Yatapp.api_caller.set_languages(languages)
|
27
|
+
end
|
28
|
+
|
29
|
+
def project_id(project_id)
|
30
|
+
Yatapp.api_caller.set_project_id(project_id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def translations_format(frmt)
|
34
|
+
Yatapp.api_caller.set_translation_format(frmt)
|
35
|
+
end
|
36
|
+
|
22
37
|
def get_translations
|
23
38
|
Yatapp.api_caller.get_translations
|
24
39
|
end
|
data/lib/yatapp/railtie.rb
CHANGED
data/lib/yatapp/version.rb
CHANGED
@@ -5,26 +5,41 @@ require 'pry'
|
|
5
5
|
|
6
6
|
module Yatapp
|
7
7
|
class YataApiCaller
|
8
|
-
|
9
|
-
|
8
|
+
ALLOWED_FORMATS = %w(json yaml)
|
9
|
+
API_VERSION = 'v1'
|
10
|
+
API_END_POINT_URL = "/api/:api_version/project/:project_id/:lang/:format"
|
10
11
|
API_BASE_URL = "http://api.yatapp.net"
|
12
|
+
API_CALLER_ATTRIBUTES = [
|
13
|
+
:connection,
|
14
|
+
:languages,
|
15
|
+
:project_id,
|
16
|
+
:translation_format
|
17
|
+
].freeze
|
11
18
|
|
12
19
|
attr_accessor *Yatapp::Configuration::CONFIGURATION_OPTIONS
|
13
20
|
attr_reader *API_CALLER_ATTRIBUTES
|
14
21
|
|
15
22
|
def initialize
|
16
23
|
initialize_configuration
|
17
|
-
@
|
24
|
+
@translation_format = 'json'
|
25
|
+
@connection = make_connection
|
18
26
|
end
|
19
27
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
def set_languages(languages)
|
29
|
+
@languages = languages
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_project_id(project_id)
|
33
|
+
@project_id = project_id
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_translation_format(translation_format)
|
37
|
+
@translation_format = translation_format
|
24
38
|
end
|
25
39
|
|
26
40
|
def get_translations
|
27
41
|
languages.each do |lang|
|
42
|
+
puts "Getting translation for #{lang}"
|
28
43
|
api_url = download_url(lang)
|
29
44
|
api_response = connection.get(api_url)
|
30
45
|
save_translation(lang, api_response)
|
@@ -39,9 +54,16 @@ module Yatapp
|
|
39
54
|
end
|
40
55
|
end
|
41
56
|
|
57
|
+
def make_connection
|
58
|
+
Faraday.new(url: API_BASE_URL) do |faraday|
|
59
|
+
faraday.adapter :typhoeus
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
42
63
|
def save_translation(lang, response)
|
43
64
|
bfp = base_file_path
|
44
|
-
File.open("#{bfp}#{lang}.yata
|
65
|
+
File.open("#{bfp}#{lang}.yata.#{translation_format}", 'wb') { |f| f.write(response.body) }
|
66
|
+
puts "#{lang}.yata.#{translation_format} saved"
|
45
67
|
end
|
46
68
|
|
47
69
|
def base_file_path
|
@@ -49,7 +71,9 @@ module Yatapp
|
|
49
71
|
end
|
50
72
|
|
51
73
|
def download_url(lang)
|
52
|
-
url = API_END_POINT_URL.sub(':project_id',
|
74
|
+
url = API_END_POINT_URL.sub(':project_id', project_id)
|
75
|
+
url = url.sub(':format', translation_format)
|
76
|
+
url = url.sub(':api_version', API_VERSION)
|
53
77
|
url = url.sub(':lang', lang)
|
54
78
|
end
|
55
79
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yatapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- luki3k5
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|