Class: QordobaRubySdk

Inherits:
Object
  • Object
show all
Defined in:
lib/qordoba_ruby_sdk.rb,
lib/qordoba_ruby_sdk/version.rb

Constant Summary collapse

BASE =

API

'https://devapi.qordoba.com/v2'
PING =
'ping'
LANGUAGES =
'languages'
COUNTRIES =
'countries'
ORG_TEAM =

ORGANIZATION

'organizations/team'
PROJ_LIST =

PROJECTS

'projects/list'
PROJ_DETAIL =
'projects/detail'
PROJ_STATUS =
'projects/status'
PROJ_WORKFLOW =
'projects/workflow'
FILE_LISTFILES =

FILES

'files/list'
FILE_TYPES =
'files/types'
FILE_UPLOAD =
'files/upload'
FILE_EXPORT =
'files/export'
FILE_UPDATE =
'files/update'
FILE_SEGMENTS =
'files/segments/list'
FILE_SEGMENT =
'files/segments/show'
FILE_JSON =
'files/json'
FILE_BULK1 =
'files/bulk1'
FILE_BULK2 =
'files/bulk2'
TM_LIST =

TM

'tms/list'
TM_UPLOAD =
'tms/upload'
TM_SHOW =
'tms/show'
TM_SEGMENTS =
'tms/segments/list'
TM_ADD_SEGMENT =
'tms/segments/add'
TM_UPDATE_SEGMENT =
'tms/segments/update'
TM_DELETE_SEGMENT =
'tms/segments/delete'
CONSUMER_KEY_ERROR =

ERROR MESSAGES

'consumer key must be a 32 digit string'
ORGANIZATION_ID_ERROR =
'organizationId must be a 4 digit number'
PROJECT_ID_ERROR =
'projectId must be a 4 digit number'
LANGUAGE_ID_ERROR =
'languageId must be an valid integer'
FILE_IDS_ERROR =
'must be a valid fileId or array of valid fileIds'
FILE_ID_ERROR =
'must be a valid six digit fileId'
SEGMENT_ID_ERROR =
'must be a valid numberic segmentId'
MILESTONE_ID_ERROR =
'must be a valid 4 digit numeric milestoneId'
VERSION_TAG_ERROR =
'must pass a valid version tag string'
PATH_TO_FILE_ERROR =
'must be a valid filepath'
VERSION =
"0.1.2"

Instance Method Summary collapse

Constructor Details

#initialize(consumerKey, organizationId, projectId) ⇒ QordobaRubySdk

Initialize App ==============


59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/qordoba_ruby_sdk.rb', line 59

def initialize(consumerKey, organizationId, projectId)
  _validate({ 
    :consumerKey => consumerKey, 
    :organizationId => organizationId, 
    :projectId => projectId
  })

  @consumerKey = consumerKey
  @organizationId = organizationId
  @projectId = projectId

end

Instance Method Details

#_clean(response) ⇒ Object

Parse JSON ================


105
106
107
108
109
110
111
# File 'lib/qordoba_ruby_sdk.rb', line 105

def _clean(response)
  if response.is_a?(String)
    JSON.parse(response)
  else
    response
  end
end

#_validate(hash) ⇒ Object

Validate User Inputs ============


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/qordoba_ruby_sdk.rb', line 74

def _validate(hash)
  keys = hash.keys

  keys.each do |key|
    value = hash[key]
    if key == :consumerKey
      raise CONSUMER_KEY_ERROR unless value.kind_of?(String) && value.length == 32 
    elsif key == :organizationId
      raise ORGANIZATION_ID_ERROR unless value.is_a?(Integer) && value.to_s.length == 4
    elsif key == :projectId
      raise PROJECT_ID_ERROR unless value.is_a?(Integer) && value.to_s.length == 4
    elsif key == :languageId
      raise LANGUAGE_ID_ERROR unless value.is_a?(Integer) && value.to_s.length <= 3
    elsif key == :versionTag
      raise VERSION_TAG_ERROR unless value.is_a?(String)
    elsif key == :fileIds
      raise FILE_IDS_ERROR unless value.is_a?(Array) || value.is_a?(Integer)
    elsif key == :fileId
      raise FILE_ID_ERROR unless value.is_a?(Integer)
    elsif key == :segmentId
      raise SEGMENT_ID_ERROR unless value.is_a?(Integer)
    elsif key == :milestoneId
      raise MILESTONE_ID_ERROR unless value.is_a?(Integer) && value.to_s.length == 4
    elsif key == :pathToFile
      raise PATH_TO_FILE_ERROR unless File.exist?(value)
    end
  end
end

#countriesObject



126
127
128
129
# File 'lib/qordoba_ruby_sdk.rb', line 126

def countries
  _clean(RestClient.get "#{BASE}/#{COUNTRIES}", 
    { :consumerKey => @consumerKey })
end

#file_export(languageId, fileIds) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/qordoba_ruby_sdk.rb', line 194

def file_export(languageId, fileIds)
  if fileIds.is_a?(Array)
    fileIds = fileIds.join(',')
  end

  _clean(RestClient.post "#{BASE}/#{FILE_EXPORT}", {}.to_json,
    {
      :consumerKey => @consumerKey,
      :projectId => @projectId,
      :fileIds => fileIds,
      :targetLanguageIds => languageId,
      "content-type" => "application/json"
    })
end

#file_json(languageId, milestoneId, fileId) ⇒ Object



239
240
241
242
243
244
245
246
# File 'lib/qordoba_ruby_sdk.rb', line 239

def file_json(languageId, milestoneId, fileId)
  _clean(RestClient.get "#{BASE}/#{FILE_JSON}",
    { :consumerKey => @consumerKey,
      :projectId => @projectId,
      :languageId => languageId,
      :fileId => fileId,
      :milestoneId => milestoneId })
end

#file_list(languageId) ⇒ Object

FILE ====================


167
168
169
170
171
172
173
# File 'lib/qordoba_ruby_sdk.rb', line 167

def file_list(languageId)
  _clean(RestClient.post "#{BASE}/#{FILE_LISTFILES}", {}.to_json,
    { :consumerKey => @consumerKey,
      :languageId => languageId,
      :projectId => @projectId,
      "content-type" => "application/json" })
end

#file_segment(languageId, fileId, segmentId) ⇒ Object



230
231
232
233
234
235
236
237
# File 'lib/qordoba_ruby_sdk.rb', line 230

def file_segment(languageId, fileId, segmentId)
  _clean(RestClient.get "#{BASE}/#{FILE_SEGMENT}",
    { :consumerKey => @consumerKey,
      :projectId => @projectId,
      :languageId => languageId,
      :fileId => fileId,
      :segmentId => segmentId })
end

#file_segments(languageId, fileId) ⇒ Object



222
223
224
225
226
227
228
# File 'lib/qordoba_ruby_sdk.rb', line 222

def file_segments(languageId, fileId)
  _clean(RestClient.get "#{BASE}/#{FILE_SEGMENTS}",
    { :consumerKey => @consumerKey,
      :projectId => @projectId,
      :languageId => languageId,
      :fileId => fileId })
end

#file_typesObject



175
176
177
178
179
# File 'lib/qordoba_ruby_sdk.rb', line 175

def file_types
  _clean(RestClient.get "#{BASE}/#{FILE_TYPES}",
    { :consumerKey => @consumerKey,
      :projectId => @projectId })
end

#file_update(pathToFile, fileId) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/qordoba_ruby_sdk.rb', line 209

def file_update(pathToFile, fileId)
  _clean(RestClient.post "#{BASE}/#{FILE_UPDATE}",
    { :file_names => '[]', 
      :file => File.open(pathToFile), 
      :multipart => true
    }, {
      :consumerKey => @consumerKey,
      :projectId => @projectId,
      :fileId => fileId,
      :params => { "type" => "JSON" }
    })
end

#file_upload(pathToFile, versionTag) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/qordoba_ruby_sdk.rb', line 181

def file_upload(pathToFile, versionTag)
  _clean(RestClient.post "#{BASE}/#{FILE_UPLOAD}",
    { :file_names => '[]', 
      :file => File.open(pathToFile), 
      :multipart => true
    }, 
    { :consumerKey => @consumerKey,
      :versionTag => versionTag,
      :projectId => @projectId,
      :organizationId => @organizationId,
      :params => { :type => "JSON" } })
end

#languagesObject



121
122
123
124
# File 'lib/qordoba_ruby_sdk.rb', line 121

def languages
  _clean(RestClient.get "#{BASE}/#{LANGUAGES}", 
    { :consumerKey => @consumerKey })
end

#organization_teamObject

Organization ================


133
134
135
136
137
# File 'lib/qordoba_ruby_sdk.rb', line 133

def organization_team
  _clean(RestClient.get "#{BASE}/#{ORG_TEAM}", 
    { :consumerKey => @consumerKey,
      :organizationId => @organizationId })
end

#pingObject

Getting Started ==============


116
117
118
119
# File 'lib/qordoba_ruby_sdk.rb', line 116

def ping
  _clean(RestClient.get "#{BASE}/#{PING}", 
    { :consumerKey => @consumerKey })
end

#project_detailObject



147
148
149
150
151
# File 'lib/qordoba_ruby_sdk.rb', line 147

def project_detail
  _clean(RestClient.get "#{BASE}/#{PROJ_DETAIL}", 
    { :consumerKey => @consumerKey,
      :projectId => @projectId })
end

#project_listObject

Project ===================


141
142
143
144
145
# File 'lib/qordoba_ruby_sdk.rb', line 141

def project_list
  _clean(RestClient.get "#{BASE}/#{PROJ_LIST}", 
    { :consumerKey => @consumerKey,
      :organizationId => @organizationId })
end

#project_statusObject



153
154
155
156
157
# File 'lib/qordoba_ruby_sdk.rb', line 153

def project_status
  _clean(RestClient.get "#{BASE}/#{PROJ_STATUS}", 
    { :consumerKey => @consumerKey,
      :projectId => @projectId })
end

#project_workflowObject



159
160
161
162
163
# File 'lib/qordoba_ruby_sdk.rb', line 159

def project_workflow
  _clean(RestClient.get "#{BASE}/#{PROJ_WORKFLOW}", 
    { :consumerKey => @consumerKey,
      :projectId => @projectId })
end