qordoba_ruby_sdk 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 564a067980c8d7b0b0c09d02bf240d304104ae88
4
+ data.tar.gz: 06e7a879af06f1e5337b1289e12521ed569ea220
5
+ SHA512:
6
+ metadata.gz: bca7e914f3e91bca74789f41ff962c3f264a9810b4c24ca31ce13dd5f6216bc4c89e079f8f2a2cb9b75165654877e9126f02a8f215f22804bf4f9d7899dacd1d
7
+ data.tar.gz: c3f098802f4caae23d39a5ac11ff20c32e905107b715060ee4dabaab27eee3eac8130aa471710e1d57b726c87a611a058e9dfe79cf26761abd38798159d495e8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qordoba_ruby_sdk.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # QordobaRubySdk
2
+
3
+ ## Installation
4
+
5
+ ## Usage
6
+
7
+ ## Development
8
+
9
+ ## Contributing
10
+
11
+ ## License
12
+
13
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
14
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "qordoba_ruby_sdk"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module QordobaRubySdk
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,247 @@
1
+ require "qordoba_ruby_sdk/version"
2
+ require 'rest-client'
3
+ require 'json'
4
+
5
+ class QordobaRubySdk
6
+
7
+ # =========== Constant Vars ==============
8
+
9
+ # API
10
+ BASE = 'https://devapi.qordoba.com/v2'
11
+ PING = 'ping'
12
+ LANGUAGES = 'languages'
13
+ COUNTRIES = 'countries'
14
+
15
+ # ORGANIZATION
16
+ ORG_TEAM = 'organizations/team'
17
+
18
+ # PROJECTS
19
+ PROJ_LIST = 'projects/list'
20
+ PROJ_DETAIL = 'projects/detail'
21
+ PROJ_STATUS = 'projects/status'
22
+ PROJ_WORKFLOW = 'projects/workflow'
23
+
24
+ # FILES
25
+ FILE_LISTFILES = 'files/list'
26
+ FILE_TYPES = 'files/types'
27
+ FILE_UPLOAD = 'files/upload'
28
+ FILE_EXPORT = 'files/export'
29
+ FILE_UPDATE = 'files/update'
30
+ FILE_SEGMENTS = 'files/segments/list'
31
+ FILE_SEGMENT = 'files/segments/show'
32
+ FILE_JSON = 'files/json'
33
+ FILE_BULK1 = 'files/bulk1'
34
+ FILE_BULK2 = 'files/bulk2'
35
+
36
+ # TM
37
+ TM_LIST = 'tms/list'
38
+ TM_UPLOAD = 'tms/upload'
39
+ TM_SHOW = 'tms/show'
40
+ TM_SEGMENTS = 'tms/segments/list'
41
+ TM_ADD_SEGMENT = 'tms/segments/add'
42
+ TM_UPDATE_SEGMENT = 'tms/segments/update'
43
+ TM_DELETE_SEGMENT = 'tms/segments/delete'
44
+
45
+ # ERROR MESSAGES
46
+ CONSUMER_KEY_ERROR = 'consumer key must be a 32 digit string'
47
+ ORGANIZATION_ID_ERROR = 'organizationId must be a 4 digit number'
48
+ PROJECT_ID_ERROR = 'projectId must be a 4 digit number'
49
+ LANGUAGE_ID_ERROR = 'languageId must be an valid integer'
50
+ FILE_IDS_ERROR = 'must be a valid fileId or array of valid fileIds'
51
+ FILE_ID_ERROR = 'must be a valid six digit fileId'
52
+ SEGMENT_ID_ERROR = 'must be a valid numberic segmentId'
53
+ MILESTONE_ID_ERROR = 'must be a valid 4 digit numeric milestoneId'
54
+ VERSION_TAG_ERROR = 'must pass a valid version tag string'
55
+ PATH_TO_FILE_ERROR = 'must be a valid filepath'
56
+
57
+ # =========== Initialize App ==============
58
+
59
+ def initialize(consumerKey, organizationId, projectId)
60
+ _validate({
61
+ :consumerKey => consumerKey,
62
+ :organizationId => organizationId,
63
+ :projectId => projectId
64
+ })
65
+
66
+ @consumerKey = consumerKey
67
+ @organizationId = organizationId
68
+ @projectId = projectId
69
+
70
+ end
71
+
72
+ # ========= Validate User Inputs ============
73
+
74
+ def _validate(hash)
75
+ keys = hash.keys
76
+
77
+ keys.each do |key|
78
+ value = hash[key]
79
+ if key == :consumerKey
80
+ raise CONSUMER_KEY_ERROR unless value.kind_of?(String) && value.length == 32
81
+ elsif key == :organizationId
82
+ raise ORGANIZATION_ID_ERROR unless value.is_a?(Integer) && value.to_s.length == 4
83
+ elsif key == :projectId
84
+ raise PROJECT_ID_ERROR unless value.is_a?(Integer) && value.to_s.length == 4
85
+ elsif key == :languageId
86
+ raise LANGUAGE_ID_ERROR unless value.is_a?(Integer) && value.to_s.length <= 3
87
+ elsif key == :versionTag
88
+ raise VERSION_TAG_ERROR unless value.is_a?(String)
89
+ elsif key == :fileIds
90
+ raise FILE_IDS_ERROR unless value.is_a?(Array) || value.is_a?(Integer)
91
+ elsif key == :fileId
92
+ raise FILE_ID_ERROR unless value.is_a?(Integer)
93
+ elsif key == :segmentId
94
+ raise SEGMENT_ID_ERROR unless value.is_a?(Integer)
95
+ elsif key == :milestoneId
96
+ raise MILESTONE_ID_ERROR unless value.is_a?(Integer) && value.to_s.length == 4
97
+ elsif key == :pathToFile
98
+ raise PATH_TO_FILE_ERROR unless File.exist?(value)
99
+ end
100
+ end
101
+ end
102
+
103
+ # ============= Parse JSON ================
104
+
105
+ def _clean(response)
106
+ if response.is_a?(String)
107
+ JSON.parse(response)
108
+ else
109
+ response
110
+ end
111
+ end
112
+
113
+
114
+ # =========== Getting Started ==============
115
+
116
+ def ping
117
+ _clean(RestClient.get "#{BASE}/#{PING}",
118
+ { :consumerKey => @consumerKey })
119
+ end
120
+
121
+ def languages
122
+ _clean(RestClient.get "#{BASE}/#{LANGUAGES}",
123
+ { :consumerKey => @consumerKey })
124
+ end
125
+
126
+ def countries
127
+ _clean(RestClient.get "#{BASE}/#{COUNTRIES}",
128
+ { :consumerKey => @consumerKey })
129
+ end
130
+
131
+ # ============= Organization ================
132
+
133
+ def organization_team
134
+ _clean(RestClient.get "#{BASE}/#{ORG_TEAM}",
135
+ { :consumerKey => @consumerKey,
136
+ :organizationId => @organizationId })
137
+ end
138
+
139
+ # =============== Project ===================
140
+
141
+ def project_list
142
+ _clean(RestClient.get "#{BASE}/#{PROJ_LIST}",
143
+ { :consumerKey => @consumerKey,
144
+ :organizationId => @organizationId })
145
+ end
146
+
147
+ def project_detail
148
+ _clean(RestClient.get "#{BASE}/#{PROJ_DETAIL}",
149
+ { :consumerKey => @consumerKey,
150
+ :projectId => @projectId })
151
+ end
152
+
153
+ def project_status
154
+ _clean(RestClient.get "#{BASE}/#{PROJ_STATUS}",
155
+ { :consumerKey => @consumerKey,
156
+ :projectId => @projectId })
157
+ end
158
+
159
+ def project_workflow
160
+ _clean(RestClient.get "#{BASE}/#{PROJ_WORKFLOW}",
161
+ { :consumerKey => @consumerKey,
162
+ :projectId => @projectId })
163
+ end
164
+
165
+ # ================ FILE ====================
166
+
167
+ def file_list(languageId)
168
+ _clean(RestClient.post "#{BASE}/#{FILE_LISTFILES}", {}.to_json,
169
+ { :consumerKey => @consumerKey,
170
+ :languageId => languageId,
171
+ :projectId => @projectId,
172
+ "content-type" => "application/json" })
173
+ end
174
+
175
+ def file_types
176
+ _clean(RestClient.get "#{BASE}/#{FILE_TYPES}",
177
+ { :consumerKey => @consumerKey,
178
+ :projectId => @projectId })
179
+ end
180
+
181
+ def file_upload(pathToFile, versionTag)
182
+ _clean(RestClient.post "#{BASE}/#{FILE_UPLOAD}",
183
+ { :file_names => '[]',
184
+ :file => File.open(pathToFile),
185
+ :multipart => true
186
+ },
187
+ { :consumerKey => @consumerKey,
188
+ :versionTag => versionTag,
189
+ :projectId => @projectId,
190
+ :organizationId => @organizationId,
191
+ :params => { :type => "JSON" } })
192
+ end
193
+
194
+ def file_export(languageId, fileIds)
195
+ if fileIds.is_a?(Array)
196
+ fileIds = fileIds.join(',')
197
+ end
198
+
199
+ _clean(RestClient.post "#{BASE}/#{FILE_EXPORT}", {}.to_json,
200
+ {
201
+ :consumerKey => @consumerKey,
202
+ :projectId => @projectId,
203
+ :fileIds => fileIds,
204
+ :targetLanguageIds => languageId,
205
+ "content-type" => "application/json"
206
+ })
207
+ end
208
+
209
+ def file_update(pathToFile, fileId)
210
+ _clean(RestClient.post "#{BASE}/#{FILE_UPDATE}",
211
+ { :file_names => '[]',
212
+ :file => File.open(pathToFile),
213
+ :multipart => true
214
+ }, {
215
+ :consumerKey => @consumerKey,
216
+ :projectId => @projectId,
217
+ :fileId => fileId,
218
+ :params => { "type" => "JSON" }
219
+ })
220
+ end
221
+
222
+ def file_segments(languageId, fileId)
223
+ _clean(RestClient.get "#{BASE}/#{FILE_SEGMENTS}",
224
+ { :consumerKey => @consumerKey,
225
+ :projectId => @projectId,
226
+ :languageId => languageId,
227
+ :fileId => fileId })
228
+ end
229
+
230
+ def file_segment(languageId, fileId, segmentId)
231
+ _clean(RestClient.get "#{BASE}/#{FILE_SEGMENT}",
232
+ { :consumerKey => @consumerKey,
233
+ :projectId => @projectId,
234
+ :languageId => languageId,
235
+ :fileId => fileId,
236
+ :segmentId => segmentId })
237
+ end
238
+
239
+ def file_json(languageId, milestoneId, fileId)
240
+ _clean(RestClient.get "#{BASE}/#{FILE_JSON}",
241
+ { :consumerKey => @consumerKey,
242
+ :projectId => @projectId,
243
+ :languageId => languageId,
244
+ :fileId => fileId,
245
+ :milestoneId => milestoneId })
246
+ end
247
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'qordoba_ruby_sdk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "qordoba_ruby_sdk"
8
+ spec.version = QordobaRubySdk::VERSION
9
+ spec.authors = ["Erik Suddath"]
10
+ spec.email = ["erik@qordoba.com"]
11
+
12
+ spec.summary = %q{Ruby SDK for Qordoba V2 API.}
13
+ spec.description = %q{A Ruby Client to interact with the Qordoba V2 API. The SDK gives developers programmatic access to everything on the Qordoba web platform in an easy to use interface.}
14
+ spec.homepage = "https://www.qordoba.com/"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "rest-client"
25
+ spec.add_development_dependency "bundler", "~> 1.14"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qordoba_ruby_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Erik Suddath
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: A Ruby Client to interact with the Qordoba V2 API. The SDK gives developers
56
+ programmatic access to everything on the Qordoba web platform in an easy to use
57
+ interface.
58
+ email:
59
+ - erik@qordoba.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/qordoba_ruby_sdk.rb
72
+ - lib/qordoba_ruby_sdk/version.rb
73
+ - qordoba_ruby_sdk.gemspec
74
+ homepage: https://www.qordoba.com/
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.6.10
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Ruby SDK for Qordoba V2 API.
98
+ test_files: []