smartling_api 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 713340cf808262a469600f0001be4079774b902f
4
- data.tar.gz: 19477fba5d20febd6b1dda5265656f101aeee222
3
+ metadata.gz: 1549c7e511da6e551aa91e70c2707976fb301481
4
+ data.tar.gz: b301bd98ab189ea78f8dae633d9ce2a13458d9fc
5
5
  SHA512:
6
- metadata.gz: e9e72780412954073160ec77022c5f275c08c79d7b828511f15c8f18f318a2a0cb52dd0b41986a0e2d2ad9bef26a002961e605abad8aecaea096c7f9b1c76c2c
7
- data.tar.gz: 8dd59928f5d9eb5ab7d7eaf4cb4d5b4d707b727eed95223163ce8efa5c3d4c6044b6dc2d10dc26bad992f41c03b740ad17bd8f0a0040eca4d9ab2b7302b22cd4
6
+ metadata.gz: 86746de96df5ee3a6cea3dfeeeaee6e8e4db71a7202785b1889205b7472c70c2a1fa20a6f31437a16c81cfae32e5f32e37c0b9105d27182e5ee74a9e981582c0
7
+ data.tar.gz: 566a3ab12ccb40dbb806b93e504451481c722642e1ab45f6b753738349f4ad30eba7c2cd77a2d864fb068c11b3c7dc5583dc1e322f4d181c3693e7fbb593a0a0
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.3
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+
5
+ script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,6 +1,13 @@
1
- # Smartling Api
1
+ Smartling Api
2
+ =============
2
3
 
3
- ## Overview
4
+ ![Build Status](https://travis-ci.org/redbubble/smartling_api.svg?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/redbubble/smartling_api/badges/gpa.svg)](https://codeclimate.com/github/redbubble/smartling_api)
6
+ [![Gem Version](https://badge.fury.io/rb/smartling_api.svg)](https://badge.fury.io/rb/smartling_api)
7
+ ![Docs](https://inch-ci.org/github/redbubble/smartling_api.svg?branch=master)
8
+
9
+ Overview
10
+ --------
4
11
 
5
12
  Ruby wrapper for accessing the Smartling Translation API V2.
6
13
 
@@ -8,21 +15,31 @@ The Smartling Translation API lets developers to internationalize their website
8
15
 
9
16
  [Smartling API V2](http://docs.smartling.com/pages/API/v2/)
10
17
 
11
- ## Requirements
18
+
19
+ Installation
20
+ ------------
21
+
22
+ ### Requirements
12
23
 
13
24
  - ruby 2.0+
14
25
 
15
- ## Installation
26
+ ### Setup
16
27
 
17
28
  Add this line to your application's Gemfile:
18
29
 
19
30
  gem 'smartling_api', '0.2.0'
31
+
32
+ ### Run Tests
33
+
34
+ bundle exec rspec
35
+
20
36
 
21
- ## Usage
37
+ Usage
38
+ -----
22
39
 
23
- ### Configure
40
+ ### Config
24
41
 
25
- You will need to configure smartling user id and secret. In Rails you would put it in an initializer file.
42
+ You will need to configure smartling user id and secret. In Rails you would put it in an initializer file. eg. `<project_home>/config/smartling_api.rb`
26
43
 
27
44
  SmartlingApi.configure do |config|
28
45
  config.id = <id>
@@ -34,92 +51,11 @@ You can obtain an id, secret via [Create Authentication Tokens](http://docs.smar
34
51
 
35
52
  The `project_id` is optional. If you are only using a single `project_id` per application then you may add your `project_id` here. If not you will have to pass the `project_id` when you create your api call. Examples below.
36
53
 
37
- ## Authentication Api
38
-
39
-
40
- ### Retrieve Access Token
41
-
42
- - [Authenticate API](http://docs.smartling.com/pages/API/v2/Authentication/Authenticate). Retrieve OAuth2 access token to be used with each api call.
43
-
44
-
45
- > SmartlingApi::Authentication.new.access_token
46
- => "Token"
47
-
48
- The Authentication API will throw `SmartlingApi::Errors::Credentials` if the Smartling id and/or secret has not been set.
49
-
50
- ## Project Api
51
-
52
- Create a Project Api via,
53
-
54
- @param `token`: Optional ( Will default to using authentication api to retrieve access token )
55
-
56
- @param `project_id`: Optional ( Will default to using configured project_id )
57
-
58
- > SmartlingApi::Project.new
59
- or
60
- > SmartlingApi::Project.new(token: 'token', project_id: 'project_id')
61
-
62
-
63
- - [List Locales API](http://docs.smartling.com/pages/API/v2/Projects/List-Projects/). Retrieve a list of all locales available.
64
-
65
- > SmartlingApi::Project.new.list_locales
66
- => { "locales" => [{ "localeId" => "de-DE", "description" => "German (Germany)" }, ...] }
67
-
68
-
69
- ## File Api
70
- Create a Project Api via,
71
-
72
- @param `token`: Optional ( Will default to using authentication api to retrieve access token )
73
-
74
- @param `project_id`: Optional ( Will default to using configured project_id )
75
-
76
- > SmartlingApi::File.new
77
- or
78
- > SmartlingApi::File.new(token: 'token', project_id: 'project_id')
79
-
80
-
81
- - [Delete File API](http://docs.smartling.com/pages/API/v2/FileAPI/Delete/). Delete a file within Smartling.
82
-
83
- @param `file_uri`: File path within Smartling to delete
84
-
85
- > SmartlingApi::File.new.delete(file_uri: '/translations/website')
86
- => { "code" => "SUCCESS" }
87
-
88
-
89
-
90
- - [Download Locale File API](http://docs.smartling.com/pages/API/v2/FileAPI/Download-File/Single-Locale/). Returns the content of a file for the given locale and path.
91
-
92
- @param `file_uri`: File path within Smartling to download
93
-
94
- @param `locale_id`: Locale Id of file to download
95
-
96
- > SmartlingApi::File.new.download_locale(locale_id: 'fr-Fr', file_uri: '/translation/website')
97
- => "translations"
98
-
99
-
100
- - [List File API](http://docs.smartling.com/pages/API/v2/FileAPI/List/). Retrieve list of files for a given project.
101
-
102
- @param `**options`: Additional options for the given request. NOTE: If using a hash as parameters ensure all keys are symbols and then use `**options`. See Smartling API Doc for options.
103
-
104
- > SmartlingApi::File.new.list_files(uriMask: '.json')
105
- => [{"fileUri" => "[/translate/file.json]", ...}]
106
-
107
-
108
- - [Upload File API](http://docs.smartling.com/pages/API/v2/FileAPI/Upload-File/). Upload a file to the given path.
109
-
110
- @param `file_path`: Location of file to upload
111
-
112
- @param `file_uri`: File path within smartling
113
-
114
- @param `file_type`: Type of file to upload. See Smartling API DOC for types.
115
-
116
- @param `**options`: Additional options for the given request. NOTE: If using a hash as parameters ensure all keys are symbols and then use `**options`. See Smartling API Doc for options.
54
+ ### Api Reference
117
55
 
118
- SmartlingApi::File.new.upload(file_path: 'website.pot', file_uri: '/translation/website', file_type: 'gettext')
119
- => { "code" => "SUCCESS" }
120
-
56
+ Reference documentation on accessing the smartling api can be found on: [Api documentation](./doc/api.md)
121
57
 
122
- ## Errors
58
+ ### Errors
123
59
 
124
60
  SmartlingApi will handle errors according to the response received from Smartling. The errors that might be thrown on a request are,
125
61
 
@@ -131,7 +67,8 @@ SmartlingApi will handle errors according to the response received from Smartlin
131
67
 
132
68
  The errors all inherit, and will default to `SmartlingApi::Errors::Client` if any other response other than 2xx or 3xx is received.
133
69
 
134
- ## Todo
70
+ Todo
71
+ ----
135
72
 
136
73
  The following apis still need to be implemented:
137
74
 
@@ -144,20 +81,22 @@ The following apis still need to be implemented:
144
81
  - File Api: Last Modified: Single Locale
145
82
  - File Api: Last Modified: All Locales
146
83
  - File Api: Import Translations
147
- - File Api: Get Translations
84
+ - ~~File Api: Get Translations~~
148
85
  - File Api: Download Translated Files: Original File
149
86
  - File Api: Download Translated Files: Multiple Locales as ZIP
150
87
  - File Api: Download Translated Files: All Locales as ZIP
151
88
  - File Api: Download Translated Files: All Locales in one File - CSV
152
89
 
153
- ## Credits
90
+ Maintainers
91
+ -------
154
92
 
155
- [![](/redbubble.png)][redbubble]
93
+ [![](/doc/redbubble.png)][redbubble]
156
94
 
157
95
  smartling api is maintained and funded by [Redbubble][redbubble].
158
96
 
159
97
  [redbubble]: https://www.redbubble.com
160
98
 
161
- ## License
99
+ License
100
+ -------
162
101
 
163
102
  Licensed under [MIT](./LICENCE.txt)
@@ -53,7 +53,10 @@ module SmartlingApi
53
53
  # @return [Hash] Response returned from request
54
54
  # @raise [Errors::Client] If response does not return a 2xx or 3xx
55
55
  def upload(url:, token:, body:)
56
- multipart_connection.post(url, body, header(token)).body.fetch('response')
56
+ response = multipart_connection.post(url, body, header(token)).body
57
+ return response if response.is_a?(String)
58
+
59
+ response.fetch('response')
57
60
  end
58
61
 
59
62
  # Download a file from smartling for the given url
@@ -77,6 +77,27 @@ module SmartlingApi
77
77
  smartling.post(url: "/files-api/v2/projects/#{project_id}/file/delete", token: token, body: { fileUri: file_uri })
78
78
  end
79
79
 
80
+ # Temporarily uploads a file, then returns a translated version for requested locales.
81
+ #
82
+ # @see http://docs.smartling.com/pages/API/v2/FileAPI/Get-Translations/
83
+ #
84
+ # @example Get Translations
85
+ # SmartlingApi::File.new.get_translations(file: 'translations.pot', file_uri: '/translations/website.pot') #=> { "code" => "SUCCESS" }
86
+ #
87
+ # @param file_path [String] File path of contents to upload
88
+ # @param file_uri [String] File path within Smartling to base off
89
+ # @param locale_id [String] Locale id for the given file
90
+ # @param options [Hash] Additional options for the given request.
91
+ # @return [Hash] Details of tranlsations
92
+ def get_translations(file_path:, file_uri:, locale_id:, **options)
93
+ body = {
94
+ file: Faraday::UploadIO.new(file_path, 'text/plain'),
95
+ fileUri: file_uri,
96
+ }.merge(options)
97
+
98
+ smartling.upload(url: "/files-api/v2/projects/#{project_id}/locales/#{locale_id}/file/get-translations", token: token, body: body)
99
+ end
100
+
80
101
  private
81
102
 
82
103
  attr_reader :smartling, :token, :project_id
@@ -1,3 +1,3 @@
1
1
  module SmartlingApi
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["developers@redbubble.com"]
11
11
 
12
12
  spec.summary = %q{Wrapper for the Smartling API.}
13
- spec.homepage = "https://www.redbubble.com/"
13
+ spec.homepage = "https://github.com/redbubble/smartling_api"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartling_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Redbubble
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-26 00:00:00.000000000 Z
11
+ date: 2017-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -116,11 +116,15 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
+ - ".ruby-version"
120
+ - ".travis.yml"
119
121
  - Gemfile
120
122
  - LICENCE.txt
121
123
  - README.md
122
124
  - bin/console
123
125
  - bin/setup
126
+ - doc/api.md
127
+ - doc/redbubble.png
124
128
  - lib/smartling_api.rb
125
129
  - lib/smartling_api/authentication.rb
126
130
  - lib/smartling_api/clients/smartling.rb
@@ -134,9 +138,8 @@ files:
134
138
  - lib/smartling_api/file.rb
135
139
  - lib/smartling_api/project.rb
136
140
  - lib/smartling_api/version.rb
137
- - redbubble.png
138
141
  - smartling_api.gemspec
139
- homepage: https://www.redbubble.com/
142
+ homepage: https://github.com/redbubble/smartling_api
140
143
  licenses:
141
144
  - MIT
142
145
  metadata: {}
@@ -156,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
159
  version: '0'
157
160
  requirements: []
158
161
  rubyforge_project:
159
- rubygems_version: 2.2.2
162
+ rubygems_version: 2.4.5.1
160
163
  signing_key:
161
164
  specification_version: 4
162
165
  summary: Wrapper for the Smartling API.
data/redbubble.png DELETED
Binary file