phraseapp-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b0eea924c065d13a8e7336118e4de8a796f71733
4
+ data.tar.gz: a1e928e85fe3ac3c9dbbef6e13a76bbee56f0b2c
5
+ SHA512:
6
+ metadata.gz: 8fe5749736f80a222ea9bfc341769e4332215d7d730b405a626753ce1c00dc7fe69ea6057c82427c5befd66b87c50b4bfbb3081a6cce4c3a159f2e686f145972
7
+ data.tar.gz: fecf3b80b1248dcd4e2abb7fc3de9fc018ead7dfe7047cfee7207563ec01f280b8a92a8a2ff9251148f5a118db2b91b90613ce190ac2c2c7ef93fbdbc5244741
@@ -0,0 +1,78 @@
1
+ module PhraseApp
2
+ module Auth
3
+
4
+ class AuthHandler < OpenStruct
5
+ def validate
6
+ if self.username == "" && self.token == ""
7
+ return raise("either username or token must be given")
8
+ else
9
+ return nil
10
+ end
11
+ end
12
+
13
+ def load_config
14
+ path = self.config
15
+ tmpA = AuthHandler.new
16
+
17
+ puts path
18
+ if path && File.exists?(path)
19
+ content = File.read(path)
20
+ tmpA = AuthHandler.new(JSON.load(content))
21
+ end
22
+
23
+ # Only set token if username not specified on commandline.
24
+ if tmpA.token && tmpA.token != "" && self.token.nil? && self.username.nil?
25
+ self.token = tmpA.token
26
+ elsif tmpA.username && tmpA.username != "" && self.username.nil?
27
+ self.username = tmpA.username
28
+ elsif tmpA.password && tmpA.password != "" && self.password.nil?
29
+ self.password = tmpA.password
30
+ end
31
+
32
+ if tmpA.tfa && self.tfa == ""
33
+ self.tfa = tmpA.tfa
34
+ end
35
+
36
+ return nil
37
+ end
38
+ end
39
+
40
+ def self.authH
41
+ defined?(@@authH) && @@authH
42
+ end
43
+
44
+ def self.register_auth_handler(a)
45
+ @@authH = a
46
+ end
47
+
48
+ def self.authenticate(req)
49
+ if authH == nil
50
+ raise("no auth handler registered")
51
+ end
52
+
53
+ if err = authH.load_config
54
+ return err
55
+ end
56
+
57
+ if err = authH.validate
58
+ return err
59
+ end
60
+
61
+ if authH.token && authH.token != ""
62
+ req["Authorization"] = "token #{authH.token}"
63
+ elsif authH.username && authH.username != ""
64
+ req.basic_auth(authH.username, authH.password)
65
+
66
+ if authH.tfa or authH.tfa_token # TFA only required for username+password based login.
67
+ raise "Multi-Factor Token required in config but not provided." unless authH.tfa_token
68
+ req["X-PhraseApp-OTP"] = auth.tfa_token
69
+ end
70
+ else
71
+ raise "No authentication present"
72
+ end
73
+
74
+ return nil
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,1977 @@
1
+
2
+ require 'ostruct'
3
+ require 'net/https'
4
+ require 'uri'
5
+ require 'cgi'
6
+ require 'json'
7
+ require 'date'
8
+ require File.expand_path('../auth', __FILE__)
9
+ require File.expand_path('../request_handler', __FILE__)
10
+
11
+ module PhraseApp
12
+ def self.handle_times(obj)
13
+ obj.each_pair do |k, v|
14
+ if is_a_date?(v)
15
+ obj.send(:"#{k}=", DateTime.parse(v))
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.is_a_date?(str)
21
+ if !str.nil? && str.is_a?(String)
22
+ str.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)
23
+ end
24
+ end
25
+
26
+ class Authorization < ::OpenStruct
27
+ #created_at, hashed_token, id, note, scopes, token_last_eight, updated_at,
28
+ def initialize(hash)
29
+ super(hash)
30
+ PhraseApp.handle_times(self)
31
+ end
32
+ end
33
+
34
+ class AuthorizationWithToken < Authorization
35
+ #token,
36
+ def initialize(hash)
37
+ super(hash)
38
+ PhraseApp.handle_times(self)
39
+ end
40
+ end
41
+
42
+ class BlacklistedKey < ::OpenStruct
43
+ #created_at, id, name, updated_at,
44
+ def initialize(hash)
45
+ super(hash)
46
+ PhraseApp.handle_times(self)
47
+ end
48
+ end
49
+
50
+ class Comment < ::OpenStruct
51
+ #created_at, id, message, updated_at, user,
52
+ def initialize(hash)
53
+ super(hash)
54
+ PhraseApp.handle_times(self)
55
+ end
56
+ end
57
+
58
+ class Format < ::OpenStruct
59
+ #api_name, default_encoding, description, exportable, extension, importable, name,
60
+ def initialize(hash)
61
+ super(hash)
62
+ PhraseApp.handle_times(self)
63
+ end
64
+ end
65
+
66
+ class KeyPreview < ::OpenStruct
67
+ #id, name, plural,
68
+ def initialize(hash)
69
+ super(hash)
70
+ PhraseApp.handle_times(self)
71
+ end
72
+ end
73
+
74
+ class Locale < ::OpenStruct
75
+ #code, created_at, default, id, main, name, rtl, source_locale, updated_at,
76
+ def initialize(hash)
77
+ super(hash)
78
+ PhraseApp.handle_times(self)
79
+ end
80
+ end
81
+
82
+ class LocaleDetails < Locale
83
+ #statistics,
84
+ def initialize(hash)
85
+ super(hash)
86
+ PhraseApp.handle_times(self)
87
+ end
88
+ end
89
+
90
+ class LocaleFileImport < ::OpenStruct
91
+ #created_at, format, id, state, updated_at,
92
+ def initialize(hash)
93
+ super(hash)
94
+ PhraseApp.handle_times(self)
95
+ end
96
+ end
97
+
98
+ class LocaleFileImportWithSummary < LocaleFileImport
99
+ #summary,
100
+ def initialize(hash)
101
+ super(hash)
102
+ PhraseApp.handle_times(self)
103
+ end
104
+ end
105
+
106
+ class LocalePreview < ::OpenStruct
107
+ #code, id, name,
108
+ def initialize(hash)
109
+ super(hash)
110
+ PhraseApp.handle_times(self)
111
+ end
112
+ end
113
+
114
+ class LocaleStatistics < ::OpenStruct
115
+ #keys_total_count, keys_untranslated_count, missing_words_count, translations_completed_count, translations_unverified_count, unverified_words_count, words_total_count,
116
+ def initialize(hash)
117
+ super(hash)
118
+ PhraseApp.handle_times(self)
119
+ end
120
+ end
121
+
122
+ class Project < ::OpenStruct
123
+ #created_at, id, name, updated_at,
124
+ def initialize(hash)
125
+ super(hash)
126
+ PhraseApp.handle_times(self)
127
+ end
128
+ end
129
+
130
+ class ProjectDetails < Project
131
+ #shares_translation_memory,
132
+ def initialize(hash)
133
+ super(hash)
134
+ PhraseApp.handle_times(self)
135
+ end
136
+ end
137
+
138
+ class StatisticsListItem < ::OpenStruct
139
+ #locale, statistics,
140
+ def initialize(hash)
141
+ super(hash)
142
+ PhraseApp.handle_times(self)
143
+ end
144
+ end
145
+
146
+ class StatisticsType < ::OpenStruct
147
+ #keys_total_count, keys_untranslated_count, translations_completed_count, translations_unverified_count,
148
+ def initialize(hash)
149
+ super(hash)
150
+ PhraseApp.handle_times(self)
151
+ end
152
+ end
153
+
154
+ class Styleguide < ::OpenStruct
155
+ #created_at, id, title, updated_at,
156
+ def initialize(hash)
157
+ super(hash)
158
+ PhraseApp.handle_times(self)
159
+ end
160
+ end
161
+
162
+ class StyleguideDetails < Styleguide
163
+ #audience, business, company_branding, formatting, glossary_terms, grammar_consistency, grammatical_person, literal_translation, overall_tone, public_url, samples, target_audience, vocabulary_type,
164
+ def initialize(hash)
165
+ super(hash)
166
+ PhraseApp.handle_times(self)
167
+ end
168
+ end
169
+
170
+ class StyleguidePreview < ::OpenStruct
171
+ #id, public_url,
172
+ def initialize(hash)
173
+ super(hash)
174
+ PhraseApp.handle_times(self)
175
+ end
176
+ end
177
+
178
+ class SummaryType < ::OpenStruct
179
+ #locales_created, tags_created, translation_keys_created, translations_created, translations_updated,
180
+ def initialize(hash)
181
+ super(hash)
182
+ PhraseApp.handle_times(self)
183
+ end
184
+ end
185
+
186
+ class Tag < ::OpenStruct
187
+ #created_at, keys_count, name, updated_at,
188
+ def initialize(hash)
189
+ super(hash)
190
+ PhraseApp.handle_times(self)
191
+ end
192
+ end
193
+
194
+ class TagWithStats < Tag
195
+ #statistics,
196
+ def initialize(hash)
197
+ super(hash)
198
+ PhraseApp.handle_times(self)
199
+ end
200
+ end
201
+
202
+ class Translation < ::OpenStruct
203
+ #content, created_at, excluded, id, key, locale, plural_suffix, unverified, updated_at,
204
+ def initialize(hash)
205
+ super(hash)
206
+ PhraseApp.handle_times(self)
207
+ end
208
+ end
209
+
210
+ class TranslationDetails < Translation
211
+ #user, word_count,
212
+ def initialize(hash)
213
+ super(hash)
214
+ PhraseApp.handle_times(self)
215
+ end
216
+ end
217
+
218
+ class TranslationKey < ::OpenStruct
219
+ #created_at, description, id, name, name_hash, plural, tags, updated_at,
220
+ def initialize(hash)
221
+ super(hash)
222
+ PhraseApp.handle_times(self)
223
+ end
224
+ end
225
+
226
+ class TranslationKeyDetails < TranslationKey
227
+ #comments_count, data_type, format_value_type, max_characters_allowed, name_plural, original_file, screenshot_url, unformatted, xml_space_preserve,
228
+ def initialize(hash)
229
+ super(hash)
230
+ PhraseApp.handle_times(self)
231
+ end
232
+ end
233
+
234
+ class TranslationOrder < ::OpenStruct
235
+ #amount_in_cents, created_at, currency, id, lsp, message, priority, progress_percent, quality, source_locale, state, styleguide, tag, target_locales, translation_type, unverify_translations_upon_delivery, updated_at,
236
+ def initialize(hash)
237
+ super(hash)
238
+ PhraseApp.handle_times(self)
239
+ end
240
+ end
241
+
242
+ class TranslationVersion < ::OpenStruct
243
+ #changed_at, content, created_at, id, key, locale, plural_suffix, updated_at,
244
+ def initialize(hash)
245
+ super(hash)
246
+ PhraseApp.handle_times(self)
247
+ end
248
+ end
249
+
250
+ class TranslationVersionWithUser < TranslationVersion
251
+ #user,
252
+ def initialize(hash)
253
+ super(hash)
254
+ PhraseApp.handle_times(self)
255
+ end
256
+ end
257
+
258
+ class User < ::OpenStruct
259
+ #company, created_at, email, id, name, position, updated_at, username,
260
+ def initialize(hash)
261
+ super(hash)
262
+ PhraseApp.handle_times(self)
263
+ end
264
+ end
265
+
266
+ class UserPreview < ::OpenStruct
267
+ #id, name, username,
268
+ def initialize(hash)
269
+ super(hash)
270
+ PhraseApp.handle_times(self)
271
+ end
272
+ end
273
+
274
+ end
275
+
276
+ class PhraseApp::AuthorizationParams < ::OpenStruct
277
+ # :note, :scopes,
278
+ def note=(val)
279
+ self.note = val
280
+ end
281
+
282
+ def scopes=(val)
283
+ self.scopes = val.split(',')
284
+ end
285
+
286
+ def validate
287
+ if self.note == nil || self.note == ""
288
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"note\" of \"AuthorizationParams\" not set")
289
+ end
290
+ end
291
+ end
292
+
293
+ class PhraseApp::BlacklistedKeyParams < ::OpenStruct
294
+ # :name,
295
+ def name=(val)
296
+ self.name = val
297
+ end
298
+
299
+ def validate
300
+ if self.name == nil || self.name == ""
301
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"name\" of \"BlacklistedKeyParams\" not set")
302
+ end
303
+ end
304
+ end
305
+
306
+ class PhraseApp::CommentParams < ::OpenStruct
307
+ # :message,
308
+ def message=(val)
309
+ self.message = val
310
+ end
311
+
312
+ def validate
313
+ if self.message == nil || self.message == ""
314
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"message\" of \"CommentParams\" not set")
315
+ end
316
+ end
317
+ end
318
+
319
+ class PhraseApp::TranslationKeyParams < ::OpenStruct
320
+ # :data_type, :description, :format_value_type, :max_characters_allowed, :name, :name_plural, :original_file, :plural, :remove_screenshot, :screenshot, :tags, :unformatted, :xml_space_preserve,
321
+ def data_type=(val)
322
+ self.data_type = val
323
+ end
324
+
325
+ def description=(val)
326
+ self.description = val
327
+ end
328
+
329
+ def format_value_type=(val)
330
+ self.format_value_type = val
331
+ end
332
+
333
+ def max_characters_allowed=(val)
334
+ self.max_characters_allowed = i.to_u
335
+ end
336
+
337
+ def name=(val)
338
+ self.name = val
339
+ end
340
+
341
+ def name_plural=(val)
342
+ self.name_plural = val
343
+ end
344
+
345
+ def original_file=(val)
346
+ self.original_file = val
347
+ end
348
+
349
+ def plural=(val)
350
+ if val == "true"
351
+ self.plural = true
352
+ elsif val == "false" #ignore
353
+ self.plural = b
354
+ else
355
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
356
+ end
357
+ end
358
+
359
+ def remove_screenshot=(val)
360
+ if val == "true"
361
+ self.remove_screenshot = true
362
+ elsif val == "false" #ignore
363
+ self.remove_screenshot = b
364
+ else
365
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
366
+ end
367
+ end
368
+
369
+ def screenshot=(val)
370
+ self.screenshot = val
371
+ end
372
+
373
+ def tags=(val)
374
+ self.tags = val.split(',')
375
+ end
376
+
377
+ def unformatted=(val)
378
+ if val == "true"
379
+ self.unformatted = true
380
+ elsif val == "false" #ignore
381
+ self.unformatted = b
382
+ else
383
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
384
+ end
385
+ end
386
+
387
+ def xml_space_preserve=(val)
388
+ if val == "true"
389
+ self.xml_space_preserve = true
390
+ elsif val == "false" #ignore
391
+ self.xml_space_preserve = b
392
+ else
393
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
394
+ end
395
+ end
396
+
397
+ def validate
398
+ if self.name == nil || self.name == ""
399
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"name\" of \"TranslationKeyParams\" not set")
400
+ end
401
+ end
402
+ end
403
+
404
+ class PhraseApp::LocaleParams < ::OpenStruct
405
+ # :code, :default, :main, :name, :rtl, :source_locale_id,
406
+ def code=(val)
407
+ self.code = val
408
+ end
409
+
410
+ def default=(val)
411
+ if val == "true"
412
+ self.default = true
413
+ elsif val == "false" #ignore
414
+ self.default = b
415
+ else
416
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
417
+ end
418
+ end
419
+
420
+ def main=(val)
421
+ if val == "true"
422
+ self.main = true
423
+ elsif val == "false" #ignore
424
+ self.main = b
425
+ else
426
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
427
+ end
428
+ end
429
+
430
+ def name=(val)
431
+ self.name = val
432
+ end
433
+
434
+ def rtl=(val)
435
+ if val == "true"
436
+ self.rtl = true
437
+ elsif val == "false" #ignore
438
+ self.rtl = b
439
+ else
440
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
441
+ end
442
+ end
443
+
444
+ def source_locale_id=(val)
445
+ self.source_locale_id = val
446
+ end
447
+
448
+ def validate
449
+ if self.code == nil || self.code == ""
450
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"code\" of \"LocaleParams\" not set")
451
+ endif self.name == nil || self.name == ""
452
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"name\" of \"LocaleParams\" not set")
453
+ end
454
+ end
455
+ end
456
+
457
+ class PhraseApp::TranslationOrderParams < ::OpenStruct
458
+ # :category, :include_untranslated_keys, :include_unverified_translations, :lsp, :message, :priority, :quality, :source_locale_id, :styleguide_id, :tag, :target_locale_ids, :translation_type, :unverify_translations_upon_delivery,
459
+ def category=(val)
460
+ self.category = val
461
+ end
462
+
463
+ def include_untranslated_keys=(val)
464
+ if val == "true"
465
+ self.include_untranslated_keys = true
466
+ elsif val == "false" #ignore
467
+ self.include_untranslated_keys = b
468
+ else
469
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
470
+ end
471
+ end
472
+
473
+ def include_unverified_translations=(val)
474
+ if val == "true"
475
+ self.include_unverified_translations = true
476
+ elsif val == "false" #ignore
477
+ self.include_unverified_translations = b
478
+ else
479
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
480
+ end
481
+ end
482
+
483
+ def lsp=(val)
484
+ self.lsp = val
485
+ end
486
+
487
+ def message=(val)
488
+ self.message = val
489
+ end
490
+
491
+ def priority=(val)
492
+ if val == "true"
493
+ self.priority = true
494
+ elsif val == "false" #ignore
495
+ self.priority = b
496
+ else
497
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
498
+ end
499
+ end
500
+
501
+ def quality=(val)
502
+ if val == "true"
503
+ self.quality = true
504
+ elsif val == "false" #ignore
505
+ self.quality = b
506
+ else
507
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
508
+ end
509
+ end
510
+
511
+ def source_locale_id=(val)
512
+ self.source_locale_id = val
513
+ end
514
+
515
+ def styleguide_id=(val)
516
+ self.styleguide_id = val
517
+ end
518
+
519
+ def tag=(val)
520
+ self.tag = val
521
+ end
522
+
523
+ def target_locale_ids=(val)
524
+ self.target_locale_ids = val.split(',')
525
+ end
526
+
527
+ def translation_type=(val)
528
+ self.translation_type = val
529
+ end
530
+
531
+ def unverify_translations_upon_delivery=(val)
532
+ if val == "true"
533
+ self.unverify_translations_upon_delivery = true
534
+ elsif val == "false" #ignore
535
+ self.unverify_translations_upon_delivery = b
536
+ else
537
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
538
+ end
539
+ end
540
+
541
+ def validate
542
+ if self.category == nil || self.category == ""
543
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"category\" of \"TranslationOrderParams\" not set")
544
+ endif self.lsp == nil || self.lsp == ""
545
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"lsp\" of \"TranslationOrderParams\" not set")
546
+ endif self.source_locale_id == nil
547
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"source_locale_id\" of \"TranslationOrderParams\" not set")
548
+ endif self.target_locale_ids == nil
549
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"target_locale_ids\" of \"TranslationOrderParams\" not set")
550
+ endif self.translation_type == nil || self.translation_type == ""
551
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"translation_type\" of \"TranslationOrderParams\" not set")
552
+ end
553
+ end
554
+ end
555
+
556
+ class PhraseApp::ProjectParams < ::OpenStruct
557
+ # :name, :shares_translation_memory,
558
+ def name=(val)
559
+ self.name = val
560
+ end
561
+
562
+ def shares_translation_memory=(val)
563
+ if val == "true"
564
+ self.shares_translation_memory = true
565
+ elsif val == "false" #ignore
566
+ self.shares_translation_memory = b
567
+ else
568
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
569
+ end
570
+ end
571
+
572
+ def validate
573
+ if self.name == nil || self.name == ""
574
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"name\" of \"ProjectParams\" not set")
575
+ end
576
+ end
577
+ end
578
+
579
+ class PhraseApp::StyleguideParams < ::OpenStruct
580
+ # :audience, :business, :company_branding, :formatting, :glossary_terms, :grammar_consistency, :grammatical_person, :literal_translation, :overall_tone, :samples, :target_audience, :title, :vocabulary_type,
581
+ def audience=(val)
582
+ self.audience = val
583
+ end
584
+
585
+ def business=(val)
586
+ self.business = val
587
+ end
588
+
589
+ def company_branding=(val)
590
+ self.company_branding = val
591
+ end
592
+
593
+ def formatting=(val)
594
+ self.formatting = val
595
+ end
596
+
597
+ def glossary_terms=(val)
598
+ self.glossary_terms = val
599
+ end
600
+
601
+ def grammar_consistency=(val)
602
+ self.grammar_consistency = val
603
+ end
604
+
605
+ def grammatical_person=(val)
606
+ self.grammatical_person = val
607
+ end
608
+
609
+ def literal_translation=(val)
610
+ self.literal_translation = val
611
+ end
612
+
613
+ def overall_tone=(val)
614
+ self.overall_tone = val
615
+ end
616
+
617
+ def samples=(val)
618
+ self.samples = val
619
+ end
620
+
621
+ def target_audience=(val)
622
+ self.target_audience = val
623
+ end
624
+
625
+ def title=(val)
626
+ self.title = val
627
+ end
628
+
629
+ def vocabulary_type=(val)
630
+ self.vocabulary_type = val
631
+ end
632
+
633
+ def validate
634
+ if self.title == nil || self.title == ""
635
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"title\" of \"StyleguideParams\" not set")
636
+ end
637
+ end
638
+ end
639
+
640
+ class PhraseApp::TagParams < ::OpenStruct
641
+ # :name,
642
+ def name=(val)
643
+ self.name = val
644
+ end
645
+
646
+ def validate
647
+ if self.name == nil || self.name == ""
648
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"name\" of \"TagParams\" not set")
649
+ end
650
+ end
651
+ end
652
+
653
+ class PhraseApp::TranslationParams < ::OpenStruct
654
+ # :content, :excluded, :key_id, :locale_id, :plural_suffix, :unverified,
655
+ def content=(val)
656
+ self.content = val
657
+ end
658
+
659
+ def excluded=(val)
660
+ if val == "true"
661
+ self.excluded = true
662
+ elsif val == "false" #ignore
663
+ self.excluded = b
664
+ else
665
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
666
+ end
667
+ end
668
+
669
+ def key_id=(val)
670
+ self.key_id = val
671
+ end
672
+
673
+ def locale_id=(val)
674
+ self.locale_id = val
675
+ end
676
+
677
+ def plural_suffix=(val)
678
+ self.plural_suffix = val
679
+ end
680
+
681
+ def unverified=(val)
682
+ if val == "true"
683
+ self.unverified = true
684
+ elsif val == "false" #ignore
685
+ self.unverified = b
686
+ else
687
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
688
+ end
689
+ end
690
+
691
+ def validate
692
+ if self.content == nil || self.content == ""
693
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"content\" of \"TranslationParams\" not set")
694
+ endif self.key_id == nil
695
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"key_id\" of \"TranslationParams\" not set")
696
+ endif self.locale_id == nil
697
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"locale_id\" of \"TranslationParams\" not set")
698
+ end
699
+ end
700
+ end
701
+
702
+ class PhraseApp::LocaleFileImportParams < ::OpenStruct
703
+ # :convert_emoji, :file, :format, :format_options, :locale_id, :skip_unverification, :skip_upload_tags, :tags, :update_translations,
704
+ def convert_emoji=(val)
705
+ if val == "true"
706
+ self.convert_emoji = true
707
+ elsif val == "false" #ignore
708
+ self.convert_emoji = b
709
+ else
710
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
711
+ end
712
+ end
713
+
714
+ def file=(val)
715
+ self.file = val
716
+ end
717
+
718
+ def format=(val)
719
+ self.format = val
720
+ end
721
+
722
+ def format_options=(val)
723
+ self.format_options = JSON.load(val)
724
+ end
725
+
726
+ def locale_id=(val)
727
+ self.locale_id = val
728
+ end
729
+
730
+ def skip_unverification=(val)
731
+ if val == "true"
732
+ self.skip_unverification = true
733
+ elsif val == "false" #ignore
734
+ self.skip_unverification = b
735
+ else
736
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
737
+ end
738
+ end
739
+
740
+ def skip_upload_tags=(val)
741
+ if val == "true"
742
+ self.skip_upload_tags = true
743
+ elsif val == "false" #ignore
744
+ self.skip_upload_tags = b
745
+ else
746
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
747
+ end
748
+ end
749
+
750
+ def tags=(val)
751
+ self.tags = val.split(',')
752
+ end
753
+
754
+ def update_translations=(val)
755
+ if val == "true"
756
+ self.update_translations = true
757
+ elsif val == "false" #ignore
758
+ self.update_translations = b
759
+ else
760
+ PhraseApp::ParamsValidationError.new("invalid value #{val}")
761
+ end
762
+ end
763
+
764
+ def validate
765
+ if self.file == nil
766
+ raise PhraseApp::ParamsValidationError.new("Required parameter \"file\" of \"LocaleFileImportParams\" not set")
767
+ end
768
+ end
769
+ end
770
+
771
+ module PhraseApp
772
+ MULTIPART_BOUNDARY = "{PHRASE!!EOF}"
773
+ URL = "https://api.phraseapp.com"
774
+
775
+ class ParamsValidationError < StandardError
776
+ end
777
+ end
778
+
779
+ class PhraseApp::RequestHelper
780
+ def initialize(data_hash, post_body=nil)
781
+ @data_hash = data_hash
782
+ @post_body = post_body
783
+ end
784
+
785
+ def body
786
+ if @post_body != nil
787
+ body = @post_body.join+PhraseApp.multipart(@data_hash)
788
+ body << "--#{PhraseApp::MULTIPART_BOUNDARY}--\r\n"
789
+ elsif defined?(@data_hash) && @data_hash.is_a?(Hash) && @data_hash.keys.any?
790
+ JSON.dump(@data_hash)
791
+ else
792
+ nil
793
+ end
794
+ end
795
+
796
+ def ctype
797
+ if @post_body != nil
798
+ return "multipart/form-data; boundary=#{PhraseApp::MULTIPART_BOUNDARY}"
799
+ elsif defined?(@data_hash) && @data_hash.is_a?(Hash) && @data_hash.keys.any?
800
+ return "application/json"
801
+ else
802
+ return ""
803
+ end
804
+ end
805
+ end
806
+
807
+ class PhraseApp::Client
808
+
809
+ # Create a new authorization.
810
+ def self.authorization_create(params)
811
+ path = sprintf("/v2/authorizations")
812
+ data_hash = {}
813
+ post_body = nil
814
+
815
+ data_hash = params.to_h
816
+ err = params.validate
817
+ if err != nil
818
+ return nil, err
819
+ end
820
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
821
+ rc, err = PhraseApp.send_request("POST", path, reqHelper.ctype, reqHelper.body, 201)
822
+ if err != nil
823
+ return nil, err
824
+ end
825
+
826
+ return PhraseApp::AuthorizationWithToken.new(JSON.load(rc.body)), err
827
+ end
828
+
829
+ # Delete an existing authorization. Please note that this will revoke access for that token, so API calls using that token will stop working.
830
+ def self.authorization_delete(id)
831
+ path = sprintf("/v2/authorizations/%s", id)
832
+ data_hash = {}
833
+ post_body = nil
834
+
835
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
836
+ rc, err = PhraseApp.send_request("DELETE", path, reqHelper.ctype, reqHelper.body, 204)
837
+ if err != nil
838
+ return nil, err
839
+ end
840
+
841
+ return err
842
+ end
843
+
844
+ # List all your authorizations.
845
+ def self.authorization_list(page, per_page)
846
+ path = sprintf("/v2/authorizations")
847
+ data_hash = {}
848
+ post_body = nil
849
+
850
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
851
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
852
+ if err != nil
853
+ return nil, err
854
+ end
855
+
856
+ return JSON.load(rc.body).map { |item| PhraseApp::Authorization.new(item) }, err
857
+ end
858
+
859
+ # Get details on a single authorization.
860
+ def self.authorization_show(id)
861
+ path = sprintf("/v2/authorizations/%s", id)
862
+ data_hash = {}
863
+ post_body = nil
864
+
865
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
866
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
867
+ if err != nil
868
+ return nil, err
869
+ end
870
+
871
+ return PhraseApp::Authorization.new(JSON.load(rc.body)), err
872
+ end
873
+
874
+ # Update an existing authorization.
875
+ def self.authorization_update(id, params)
876
+ path = sprintf("/v2/authorizations/%s", id)
877
+ data_hash = {}
878
+ post_body = nil
879
+
880
+ data_hash = params.to_h
881
+ err = params.validate
882
+ if err != nil
883
+ return nil, err
884
+ end
885
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
886
+ rc, err = PhraseApp.send_request("PATCH", path, reqHelper.ctype, reqHelper.body, 200)
887
+ if err != nil
888
+ return nil, err
889
+ end
890
+
891
+ return PhraseApp::Authorization.new(JSON.load(rc.body)), err
892
+ end
893
+
894
+ # Create a new blacklisted key.
895
+ def self.blacklist_key_create(project_id, params)
896
+ path = sprintf("/v2/projects/%s/blacklisted_keys", project_id)
897
+ data_hash = {}
898
+ post_body = nil
899
+
900
+ data_hash = params.to_h
901
+ err = params.validate
902
+ if err != nil
903
+ return nil, err
904
+ end
905
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
906
+ rc, err = PhraseApp.send_request("POST", path, reqHelper.ctype, reqHelper.body, 201)
907
+ if err != nil
908
+ return nil, err
909
+ end
910
+
911
+ return PhraseApp::BlacklistedKey.new(JSON.load(rc.body)), err
912
+ end
913
+
914
+ # Delete an existing blacklisted key.
915
+ def self.blacklist_key_delete(project_id, id)
916
+ path = sprintf("/v2/projects/%s/blacklisted_keys/%s", project_id, id)
917
+ data_hash = {}
918
+ post_body = nil
919
+
920
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
921
+ rc, err = PhraseApp.send_request("DELETE", path, reqHelper.ctype, reqHelper.body, 204)
922
+ if err != nil
923
+ return nil, err
924
+ end
925
+
926
+ return err
927
+ end
928
+
929
+ # Get details on a single blacklisted key for a given project.
930
+ def self.blacklist_key_show(project_id, id)
931
+ path = sprintf("/v2/projects/%s/blacklisted_keys/%s", project_id, id)
932
+ data_hash = {}
933
+ post_body = nil
934
+
935
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
936
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
937
+ if err != nil
938
+ return nil, err
939
+ end
940
+
941
+ return PhraseApp::BlacklistedKey.new(JSON.load(rc.body)), err
942
+ end
943
+
944
+ # Update an existing blacklisted key.
945
+ def self.blacklist_key_update(project_id, id, params)
946
+ path = sprintf("/v2/projects/%s/blacklisted_keys/%s", project_id, id)
947
+ data_hash = {}
948
+ post_body = nil
949
+
950
+ data_hash = params.to_h
951
+ err = params.validate
952
+ if err != nil
953
+ return nil, err
954
+ end
955
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
956
+ rc, err = PhraseApp.send_request("PATCH", path, reqHelper.ctype, reqHelper.body, 200)
957
+ if err != nil
958
+ return nil, err
959
+ end
960
+
961
+ return PhraseApp::BlacklistedKey.new(JSON.load(rc.body)), err
962
+ end
963
+
964
+ # List all blacklisted keys for the given project.
965
+ def self.blacklist_show(project_id, page, per_page)
966
+ path = sprintf("/v2/projects/%s/blacklisted_keys", project_id)
967
+ data_hash = {}
968
+ post_body = nil
969
+
970
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
971
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
972
+ if err != nil
973
+ return nil, err
974
+ end
975
+
976
+ return JSON.load(rc.body).map { |item| PhraseApp::BlacklistedKey.new(item) }, err
977
+ end
978
+
979
+ # Create a new comment for a key.
980
+ def self.comment_create(project_id, key_id, params)
981
+ path = sprintf("/v2/projects/%s/keys/%s/comments", project_id, key_id)
982
+ data_hash = {}
983
+ post_body = nil
984
+
985
+ data_hash = params.to_h
986
+ err = params.validate
987
+ if err != nil
988
+ return nil, err
989
+ end
990
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
991
+ rc, err = PhraseApp.send_request("POST", path, reqHelper.ctype, reqHelper.body, 201)
992
+ if err != nil
993
+ return nil, err
994
+ end
995
+
996
+ return PhraseApp::Comment.new(JSON.load(rc.body)), err
997
+ end
998
+
999
+ # Delete an existing comment.
1000
+ def self.comment_delete(project_id, key_id, id)
1001
+ path = sprintf("/v2/projects/%s/keys/%s/comments/%s", project_id, key_id, id)
1002
+ data_hash = {}
1003
+ post_body = nil
1004
+
1005
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1006
+ rc, err = PhraseApp.send_request("DELETE", path, reqHelper.ctype, reqHelper.body, 204)
1007
+ if err != nil
1008
+ return nil, err
1009
+ end
1010
+
1011
+ return err
1012
+ end
1013
+
1014
+ # List all comments for a key.
1015
+ def self.comment_list(project_id, key_id, page, per_page)
1016
+ path = sprintf("/v2/projects/%s/keys/%s/comments", project_id, key_id)
1017
+ data_hash = {}
1018
+ post_body = nil
1019
+
1020
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1021
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1022
+ if err != nil
1023
+ return nil, err
1024
+ end
1025
+
1026
+ return JSON.load(rc.body).map { |item| PhraseApp::Comment.new(item) }, err
1027
+ end
1028
+
1029
+ # Check if comment was marked as read. Returns 204 if read, 404 if unread.
1030
+ def self.comment_mark_check(project_id, key_id, id)
1031
+ path = sprintf("/v2/projects/%s/keys/%s/comments/%s/read", project_id, key_id, id)
1032
+ data_hash = {}
1033
+ post_body = nil
1034
+
1035
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1036
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 204)
1037
+ if err != nil
1038
+ return nil, err
1039
+ end
1040
+
1041
+ return err
1042
+ end
1043
+
1044
+ # Mark a comment as read
1045
+ def self.comment_mark_read(project_id, key_id, id)
1046
+ path = sprintf("/v2/projects/%s/keys/%s/comments/%s/read", project_id, key_id, id)
1047
+ data_hash = {}
1048
+ post_body = nil
1049
+
1050
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1051
+ rc, err = PhraseApp.send_request("PUT", path, reqHelper.ctype, reqHelper.body, 204)
1052
+ if err != nil
1053
+ return nil, err
1054
+ end
1055
+
1056
+ return err
1057
+ end
1058
+
1059
+ # Mark a comment as unread
1060
+ def self.comment_mark_unread(project_id, key_id, id)
1061
+ path = sprintf("/v2/projects/%s/keys/%s/comments/%s/read", project_id, key_id, id)
1062
+ data_hash = {}
1063
+ post_body = nil
1064
+
1065
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1066
+ rc, err = PhraseApp.send_request("DELETE", path, reqHelper.ctype, reqHelper.body, 204)
1067
+ if err != nil
1068
+ return nil, err
1069
+ end
1070
+
1071
+ return err
1072
+ end
1073
+
1074
+ # Get details on a single comment.
1075
+ def self.comment_show(project_id, key_id, id)
1076
+ path = sprintf("/v2/projects/%s/keys/%s/comments/%s", project_id, key_id, id)
1077
+ data_hash = {}
1078
+ post_body = nil
1079
+
1080
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1081
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1082
+ if err != nil
1083
+ return nil, err
1084
+ end
1085
+
1086
+ return PhraseApp::Comment.new(JSON.load(rc.body)), err
1087
+ end
1088
+
1089
+ # Update an existing comment.
1090
+ def self.comment_update(project_id, key_id, id, params)
1091
+ path = sprintf("/v2/projects/%s/keys/%s/comments/%s", project_id, key_id, id)
1092
+ data_hash = {}
1093
+ post_body = nil
1094
+
1095
+ data_hash = params.to_h
1096
+ err = params.validate
1097
+ if err != nil
1098
+ return nil, err
1099
+ end
1100
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1101
+ rc, err = PhraseApp.send_request("PATCH", path, reqHelper.ctype, reqHelper.body, 200)
1102
+ if err != nil
1103
+ return nil, err
1104
+ end
1105
+
1106
+ return PhraseApp::Comment.new(JSON.load(rc.body)), err
1107
+ end
1108
+
1109
+ # Get a handy list of all localization file formats supported in PhraseApp.
1110
+ def self.formats_list(page, per_page)
1111
+ path = sprintf("/v2/formats")
1112
+ data_hash = {}
1113
+ post_body = nil
1114
+
1115
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1116
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1117
+ if err != nil
1118
+ return nil, err
1119
+ end
1120
+
1121
+ return JSON.load(rc.body).map { |item| PhraseApp::Format.new(item) }, err
1122
+ end
1123
+
1124
+ # Create a new key.
1125
+ def self.key_create(project_id, params)
1126
+ path = sprintf("/v2/projects/%s/keys", project_id)
1127
+ data_hash = {}
1128
+ post_body = nil
1129
+ if params.data_type != nil
1130
+ data_hash["data_type"] = params.data_type
1131
+ end
1132
+
1133
+ if params.description != nil
1134
+ data_hash["description"] = params.description
1135
+ end
1136
+
1137
+ if params.format_value_type != nil
1138
+ data_hash["format_value_type"] = params.format_value_type
1139
+ end
1140
+
1141
+ if params.max_characters_allowed != nil
1142
+ data_hash["max_characters_allowed"] = params.max_characters_allowed.to_i
1143
+ end
1144
+
1145
+ if params.name != nil
1146
+ data_hash["name"] = params.name
1147
+ end
1148
+
1149
+ if params.name_plural != nil
1150
+ data_hash["name_plural"] = params.name_plural
1151
+ end
1152
+
1153
+ if params.original_file != nil
1154
+ data_hash["original_file"] = params.original_file
1155
+ end
1156
+
1157
+ if params.plural != nil
1158
+ data_hash["plural"] = (params.plural == "true")
1159
+ end
1160
+
1161
+ if params.remove_screenshot != nil
1162
+ data_hash["remove_screenshot"] = (params.remove_screenshot == "true")
1163
+ end
1164
+
1165
+ if params.screenshot != nil
1166
+ post_body = []
1167
+ post_body << "--#{PhraseApp::MULTIPART_BOUNDARY}\r\n"
1168
+ post_body << "Content-Disposition: form-data; name=\"screenshot\"; filename=\"#{File.basename(params.screenshot )}\"\r\n"
1169
+ post_body << "Content-Type: text/plain\r\n"
1170
+ post_body << "\r\n"
1171
+ post_body << File.read(params.screenshot)
1172
+ post_body << "\r\n"
1173
+ end
1174
+
1175
+ if params.tags != nil
1176
+ data_hash["tags"] = params.tags
1177
+ end
1178
+
1179
+ if params.unformatted != nil
1180
+ data_hash["unformatted"] = (params.unformatted == "true")
1181
+ end
1182
+
1183
+ if params.xml_space_preserve != nil
1184
+ data_hash["xml_space_preserve"] = (params.xml_space_preserve == "true")
1185
+ end
1186
+
1187
+
1188
+
1189
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1190
+ rc, err = PhraseApp.send_request("POST", path, reqHelper.ctype, reqHelper.body, 201)
1191
+ if err != nil
1192
+ return nil, err
1193
+ end
1194
+
1195
+ return PhraseApp::TranslationKeyDetails.new(JSON.load(rc.body)), err
1196
+ end
1197
+
1198
+ # Delete an existing key.
1199
+ def self.key_delete(project_id, id)
1200
+ path = sprintf("/v2/projects/%s/keys/%s", project_id, id)
1201
+ data_hash = {}
1202
+ post_body = nil
1203
+
1204
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1205
+ rc, err = PhraseApp.send_request("DELETE", path, reqHelper.ctype, reqHelper.body, 204)
1206
+ if err != nil
1207
+ return nil, err
1208
+ end
1209
+
1210
+ return err
1211
+ end
1212
+
1213
+ # List all keys for the given project.
1214
+ def self.key_list(project_id, page, per_page, params)
1215
+ path = sprintf("/v2/projects/%s/keys", project_id)
1216
+ data_hash = {}
1217
+ post_body = nil
1218
+
1219
+ data_hash = params.to_h
1220
+ err = params.validate
1221
+ if err != nil
1222
+ return nil, err
1223
+ end
1224
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1225
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1226
+ if err != nil
1227
+ return nil, err
1228
+ end
1229
+
1230
+ return JSON.load(rc.body).map { |item| PhraseApp::TranslationKey.new(item) }, err
1231
+ end
1232
+
1233
+ # Get details on a single key for a given project.
1234
+ def self.key_show(project_id, id)
1235
+ path = sprintf("/v2/projects/%s/keys/%s", project_id, id)
1236
+ data_hash = {}
1237
+ post_body = nil
1238
+
1239
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1240
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1241
+ if err != nil
1242
+ return nil, err
1243
+ end
1244
+
1245
+ return PhraseApp::TranslationKeyDetails.new(JSON.load(rc.body)), err
1246
+ end
1247
+
1248
+ # Update an existing key.
1249
+ def self.key_update(project_id, id, params)
1250
+ path = sprintf("/v2/projects/%s/keys/%s", project_id, id)
1251
+ data_hash = {}
1252
+ post_body = nil
1253
+ if params.data_type != nil
1254
+ data_hash["data_type"] = params.data_type
1255
+ end
1256
+
1257
+ if params.description != nil
1258
+ data_hash["description"] = params.description
1259
+ end
1260
+
1261
+ if params.format_value_type != nil
1262
+ data_hash["format_value_type"] = params.format_value_type
1263
+ end
1264
+
1265
+ if params.max_characters_allowed != nil
1266
+ data_hash["max_characters_allowed"] = params.max_characters_allowed.to_i
1267
+ end
1268
+
1269
+ if params.name != nil
1270
+ data_hash["name"] = params.name
1271
+ end
1272
+
1273
+ if params.name_plural != nil
1274
+ data_hash["name_plural"] = params.name_plural
1275
+ end
1276
+
1277
+ if params.original_file != nil
1278
+ data_hash["original_file"] = params.original_file
1279
+ end
1280
+
1281
+ if params.plural != nil
1282
+ data_hash["plural"] = (params.plural == "true")
1283
+ end
1284
+
1285
+ if params.remove_screenshot != nil
1286
+ data_hash["remove_screenshot"] = (params.remove_screenshot == "true")
1287
+ end
1288
+
1289
+ if params.screenshot != nil
1290
+ post_body = []
1291
+ post_body << "--#{PhraseApp::MULTIPART_BOUNDARY}\r\n"
1292
+ post_body << "Content-Disposition: form-data; name=\"screenshot\"; filename=\"#{File.basename(params.screenshot )}\"\r\n"
1293
+ post_body << "Content-Type: text/plain\r\n"
1294
+ post_body << "\r\n"
1295
+ post_body << File.read(params.screenshot)
1296
+ post_body << "\r\n"
1297
+ end
1298
+
1299
+ if params.tags != nil
1300
+ data_hash["tags"] = params.tags
1301
+ end
1302
+
1303
+ if params.unformatted != nil
1304
+ data_hash["unformatted"] = (params.unformatted == "true")
1305
+ end
1306
+
1307
+ if params.xml_space_preserve != nil
1308
+ data_hash["xml_space_preserve"] = (params.xml_space_preserve == "true")
1309
+ end
1310
+
1311
+
1312
+
1313
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1314
+ rc, err = PhraseApp.send_request("PATCH", path, reqHelper.ctype, reqHelper.body, 200)
1315
+ if err != nil
1316
+ return nil, err
1317
+ end
1318
+
1319
+ return PhraseApp::TranslationKeyDetails.new(JSON.load(rc.body)), err
1320
+ end
1321
+
1322
+ # Create a new locale.
1323
+ def self.locale_create(project_id, params)
1324
+ path = sprintf("/v2/projects/%s/locales", project_id)
1325
+ data_hash = {}
1326
+ post_body = nil
1327
+
1328
+ data_hash = params.to_h
1329
+ err = params.validate
1330
+ if err != nil
1331
+ return nil, err
1332
+ end
1333
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1334
+ rc, err = PhraseApp.send_request("POST", path, reqHelper.ctype, reqHelper.body, 201)
1335
+ if err != nil
1336
+ return nil, err
1337
+ end
1338
+
1339
+ return PhraseApp::LocaleDetails.new(JSON.load(rc.body)), err
1340
+ end
1341
+
1342
+ # Delete an existing locale.
1343
+ def self.locale_delete(project_id, id)
1344
+ path = sprintf("/v2/projects/%s/locales/%s", project_id, id)
1345
+ data_hash = {}
1346
+ post_body = nil
1347
+
1348
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1349
+ rc, err = PhraseApp.send_request("DELETE", path, reqHelper.ctype, reqHelper.body, 204)
1350
+ if err != nil
1351
+ return nil, err
1352
+ end
1353
+
1354
+ return err
1355
+ end
1356
+
1357
+ # Download a locale in a specific file format.
1358
+ def self.locale_download(project_id, id, params)
1359
+ path = sprintf("/v2/projects/%s/locales/%s/download", project_id, id)
1360
+ data_hash = {}
1361
+ post_body = nil
1362
+
1363
+ data_hash = params.to_h
1364
+ err = params.validate
1365
+ if err != nil
1366
+ return nil, err
1367
+ end
1368
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1369
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1370
+ if err != nil
1371
+ return nil, err
1372
+ end
1373
+ return rc.body
1374
+ return err
1375
+ end
1376
+
1377
+ # List all locales for the given project.
1378
+ def self.locale_list(project_id, page, per_page)
1379
+ path = sprintf("/v2/projects/%s/locales", project_id)
1380
+ data_hash = {}
1381
+ post_body = nil
1382
+
1383
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1384
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1385
+ if err != nil
1386
+ return nil, err
1387
+ end
1388
+
1389
+ return JSON.load(rc.body).map { |item| PhraseApp::Locale.new(item) }, err
1390
+ end
1391
+
1392
+ # Get details on a single locale for a given project.
1393
+ def self.locale_show(project_id, id)
1394
+ path = sprintf("/v2/projects/%s/locales/%s", project_id, id)
1395
+ data_hash = {}
1396
+ post_body = nil
1397
+
1398
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1399
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1400
+ if err != nil
1401
+ return nil, err
1402
+ end
1403
+
1404
+ return PhraseApp::LocaleDetails.new(JSON.load(rc.body)), err
1405
+ end
1406
+
1407
+ # Update an existing locale.
1408
+ def self.locale_update(project_id, id, params)
1409
+ path = sprintf("/v2/projects/%s/locales/%s", project_id, id)
1410
+ data_hash = {}
1411
+ post_body = nil
1412
+
1413
+ data_hash = params.to_h
1414
+ err = params.validate
1415
+ if err != nil
1416
+ return nil, err
1417
+ end
1418
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1419
+ rc, err = PhraseApp.send_request("PATCH", path, reqHelper.ctype, reqHelper.body, 200)
1420
+ if err != nil
1421
+ return nil, err
1422
+ end
1423
+
1424
+ return PhraseApp::LocaleDetails.new(JSON.load(rc.body)), err
1425
+ end
1426
+
1427
+ # Confirm an existing order. Sends the order to the language service provider for processing. Please note that your access token must include the <code>orders.create</code> scope to confirm orders.
1428
+ def self.order_confirm(project_id, id)
1429
+ path = sprintf("/v2/projects/%s/orders/%s/confirm", project_id, id)
1430
+ data_hash = {}
1431
+ post_body = nil
1432
+
1433
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1434
+ rc, err = PhraseApp.send_request("PATCH", path, reqHelper.ctype, reqHelper.body, 200)
1435
+ if err != nil
1436
+ return nil, err
1437
+ end
1438
+
1439
+ return PhraseApp::TranslationOrder.new(JSON.load(rc.body)), err
1440
+ end
1441
+
1442
+ # Create a new order. Please note that your access token must include the <code>orders.create</code> scope to create orders.
1443
+ def self.order_create(project_id, params)
1444
+ path = sprintf("/v2/projects/%s/orders", project_id)
1445
+ data_hash = {}
1446
+ post_body = nil
1447
+
1448
+ data_hash = params.to_h
1449
+ err = params.validate
1450
+ if err != nil
1451
+ return nil, err
1452
+ end
1453
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1454
+ rc, err = PhraseApp.send_request("POST", path, reqHelper.ctype, reqHelper.body, 201)
1455
+ if err != nil
1456
+ return nil, err
1457
+ end
1458
+
1459
+ return PhraseApp::TranslationOrder.new(JSON.load(rc.body)), err
1460
+ end
1461
+
1462
+ # Cancel an existing order. Must not yet be confirmed.
1463
+ def self.order_delete(project_id, id)
1464
+ path = sprintf("/v2/projects/%s/orders/%s", project_id, id)
1465
+ data_hash = {}
1466
+ post_body = nil
1467
+
1468
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1469
+ rc, err = PhraseApp.send_request("DELETE", path, reqHelper.ctype, reqHelper.body, 204)
1470
+ if err != nil
1471
+ return nil, err
1472
+ end
1473
+
1474
+ return err
1475
+ end
1476
+
1477
+ # List all orders for the given project.
1478
+ def self.order_list(project_id, page, per_page)
1479
+ path = sprintf("/v2/projects/%s/orders", project_id)
1480
+ data_hash = {}
1481
+ post_body = nil
1482
+
1483
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1484
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1485
+ if err != nil
1486
+ return nil, err
1487
+ end
1488
+
1489
+ return JSON.load(rc.body).map { |item| PhraseApp::TranslationOrder.new(item) }, err
1490
+ end
1491
+
1492
+ # Get details on a single order.
1493
+ def self.order_show(project_id, id)
1494
+ path = sprintf("/v2/projects/%s/orders/%s", project_id, id)
1495
+ data_hash = {}
1496
+ post_body = nil
1497
+
1498
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1499
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1500
+ if err != nil
1501
+ return nil, err
1502
+ end
1503
+
1504
+ return PhraseApp::TranslationOrder.new(JSON.load(rc.body)), err
1505
+ end
1506
+
1507
+ # Create a new project.
1508
+ def self.project_create(params)
1509
+ path = sprintf("/v2/projects")
1510
+ data_hash = {}
1511
+ post_body = nil
1512
+
1513
+ data_hash = params.to_h
1514
+ err = params.validate
1515
+ if err != nil
1516
+ return nil, err
1517
+ end
1518
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1519
+ rc, err = PhraseApp.send_request("POST", path, reqHelper.ctype, reqHelper.body, 201)
1520
+ if err != nil
1521
+ return nil, err
1522
+ end
1523
+
1524
+ return PhraseApp::ProjectDetails.new(JSON.load(rc.body)), err
1525
+ end
1526
+
1527
+ # Delete an existing project.
1528
+ def self.project_delete(id)
1529
+ path = sprintf("/v2/projects/%s", id)
1530
+ data_hash = {}
1531
+ post_body = nil
1532
+
1533
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1534
+ rc, err = PhraseApp.send_request("DELETE", path, reqHelper.ctype, reqHelper.body, 204)
1535
+ if err != nil
1536
+ return nil, err
1537
+ end
1538
+
1539
+ return err
1540
+ end
1541
+
1542
+ # List all projects the current user has access to.
1543
+ def self.project_list(page, per_page)
1544
+ path = sprintf("/v2/projects")
1545
+ data_hash = {}
1546
+ post_body = nil
1547
+
1548
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1549
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1550
+ if err != nil
1551
+ return nil, err
1552
+ end
1553
+
1554
+ return JSON.load(rc.body).map { |item| PhraseApp::Project.new(item) }, err
1555
+ end
1556
+
1557
+ # Get details on a single project.
1558
+ def self.project_show(id)
1559
+ path = sprintf("/v2/projects/%s", id)
1560
+ data_hash = {}
1561
+ post_body = nil
1562
+
1563
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1564
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1565
+ if err != nil
1566
+ return nil, err
1567
+ end
1568
+
1569
+ return PhraseApp::ProjectDetails.new(JSON.load(rc.body)), err
1570
+ end
1571
+
1572
+ # Update an existing project.
1573
+ def self.project_update(id, params)
1574
+ path = sprintf("/v2/projects/%s", id)
1575
+ data_hash = {}
1576
+ post_body = nil
1577
+
1578
+ data_hash = params.to_h
1579
+ err = params.validate
1580
+ if err != nil
1581
+ return nil, err
1582
+ end
1583
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1584
+ rc, err = PhraseApp.send_request("PATCH", path, reqHelper.ctype, reqHelper.body, 200)
1585
+ if err != nil
1586
+ return nil, err
1587
+ end
1588
+
1589
+ return PhraseApp::ProjectDetails.new(JSON.load(rc.body)), err
1590
+ end
1591
+
1592
+ # Show details for current User.
1593
+ def self.show_user()
1594
+ path = sprintf("/v2/user")
1595
+ data_hash = {}
1596
+ post_body = nil
1597
+
1598
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1599
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1600
+ if err != nil
1601
+ return nil, err
1602
+ end
1603
+
1604
+ return PhraseApp::User.new(JSON.load(rc.body)), err
1605
+ end
1606
+
1607
+ # Create a new style guide.
1608
+ def self.styleguide_create(project_id, params)
1609
+ path = sprintf("/v2/projects/%s/styleguides", project_id)
1610
+ data_hash = {}
1611
+ post_body = nil
1612
+
1613
+ data_hash = params.to_h
1614
+ err = params.validate
1615
+ if err != nil
1616
+ return nil, err
1617
+ end
1618
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1619
+ rc, err = PhraseApp.send_request("POST", path, reqHelper.ctype, reqHelper.body, 201)
1620
+ if err != nil
1621
+ return nil, err
1622
+ end
1623
+
1624
+ return PhraseApp::StyleguideDetails.new(JSON.load(rc.body)), err
1625
+ end
1626
+
1627
+ # Delete an existing style guide.
1628
+ def self.styleguide_delete(project_id, id)
1629
+ path = sprintf("/v2/projects/%s/styleguides/%s", project_id, id)
1630
+ data_hash = {}
1631
+ post_body = nil
1632
+
1633
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1634
+ rc, err = PhraseApp.send_request("DELETE", path, reqHelper.ctype, reqHelper.body, 204)
1635
+ if err != nil
1636
+ return nil, err
1637
+ end
1638
+
1639
+ return err
1640
+ end
1641
+
1642
+ # List all styleguides for the given project.
1643
+ def self.styleguide_list(project_id, page, per_page)
1644
+ path = sprintf("/v2/projects/%s/styleguides", project_id)
1645
+ data_hash = {}
1646
+ post_body = nil
1647
+
1648
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1649
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1650
+ if err != nil
1651
+ return nil, err
1652
+ end
1653
+
1654
+ return JSON.load(rc.body).map { |item| PhraseApp::Styleguide.new(item) }, err
1655
+ end
1656
+
1657
+ # Get details on a single style guide.
1658
+ def self.styleguide_show(project_id, id)
1659
+ path = sprintf("/v2/projects/%s/styleguides/%s", project_id, id)
1660
+ data_hash = {}
1661
+ post_body = nil
1662
+
1663
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1664
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1665
+ if err != nil
1666
+ return nil, err
1667
+ end
1668
+
1669
+ return PhraseApp::StyleguideDetails.new(JSON.load(rc.body)), err
1670
+ end
1671
+
1672
+ # Update an existing style guide.
1673
+ def self.styleguide_update(project_id, id, params)
1674
+ path = sprintf("/v2/projects/%s/styleguides/%s", project_id, id)
1675
+ data_hash = {}
1676
+ post_body = nil
1677
+
1678
+ data_hash = params.to_h
1679
+ err = params.validate
1680
+ if err != nil
1681
+ return nil, err
1682
+ end
1683
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1684
+ rc, err = PhraseApp.send_request("PATCH", path, reqHelper.ctype, reqHelper.body, 200)
1685
+ if err != nil
1686
+ return nil, err
1687
+ end
1688
+
1689
+ return PhraseApp::StyleguideDetails.new(JSON.load(rc.body)), err
1690
+ end
1691
+
1692
+ # Create a new tag.
1693
+ def self.tag_create(project_id, params)
1694
+ path = sprintf("/v2/projects/%s/tags", project_id)
1695
+ data_hash = {}
1696
+ post_body = nil
1697
+
1698
+ data_hash = params.to_h
1699
+ err = params.validate
1700
+ if err != nil
1701
+ return nil, err
1702
+ end
1703
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1704
+ rc, err = PhraseApp.send_request("POST", path, reqHelper.ctype, reqHelper.body, 201)
1705
+ if err != nil
1706
+ return nil, err
1707
+ end
1708
+
1709
+ return PhraseApp::TagWithStats.new(JSON.load(rc.body)), err
1710
+ end
1711
+
1712
+ # Delete an existing tag.
1713
+ def self.tag_delete(project_id, name)
1714
+ path = sprintf("/v2/projects/%s/tags/%s", project_id, name)
1715
+ data_hash = {}
1716
+ post_body = nil
1717
+
1718
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1719
+ rc, err = PhraseApp.send_request("DELETE", path, reqHelper.ctype, reqHelper.body, 204)
1720
+ if err != nil
1721
+ return nil, err
1722
+ end
1723
+
1724
+ return err
1725
+ end
1726
+
1727
+ # List all tags for the given project.
1728
+ def self.tag_list(project_id, page, per_page)
1729
+ path = sprintf("/v2/projects/%s/tags", project_id)
1730
+ data_hash = {}
1731
+ post_body = nil
1732
+
1733
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1734
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1735
+ if err != nil
1736
+ return nil, err
1737
+ end
1738
+
1739
+ return JSON.load(rc.body).map { |item| PhraseApp::Tag.new(item) }, err
1740
+ end
1741
+
1742
+ # Get details and progress information on a single tag for a given project.
1743
+ def self.tag_show(project_id, name)
1744
+ path = sprintf("/v2/projects/%s/tags/%s", project_id, name)
1745
+ data_hash = {}
1746
+ post_body = nil
1747
+
1748
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1749
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1750
+ if err != nil
1751
+ return nil, err
1752
+ end
1753
+
1754
+ return PhraseApp::TagWithStats.new(JSON.load(rc.body)), err
1755
+ end
1756
+
1757
+ # Create a translation.
1758
+ def self.translation_create(project_id, params)
1759
+ path = sprintf("/v2/projects/%s/translations", project_id)
1760
+ data_hash = {}
1761
+ post_body = nil
1762
+
1763
+ data_hash = params.to_h
1764
+ err = params.validate
1765
+ if err != nil
1766
+ return nil, err
1767
+ end
1768
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1769
+ rc, err = PhraseApp.send_request("POST", path, reqHelper.ctype, reqHelper.body, 201)
1770
+ if err != nil
1771
+ return nil, err
1772
+ end
1773
+
1774
+ return PhraseApp::TranslationDetails.new(JSON.load(rc.body)), err
1775
+ end
1776
+
1777
+ # List translations for the given project.
1778
+ def self.translation_list_all(project_id, page, per_page, params)
1779
+ path = sprintf("/v2/projects/%s/translations", project_id)
1780
+ data_hash = {}
1781
+ post_body = nil
1782
+
1783
+ data_hash = params.to_h
1784
+ err = params.validate
1785
+ if err != nil
1786
+ return nil, err
1787
+ end
1788
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1789
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1790
+ if err != nil
1791
+ return nil, err
1792
+ end
1793
+
1794
+ return JSON.load(rc.body).map { |item| PhraseApp::Translation.new(item) }, err
1795
+ end
1796
+
1797
+ # List translations for a specific key.
1798
+ def self.translation_list_key(project_id, key_id, page, per_page, params)
1799
+ path = sprintf("/v2/projects/%s/keys/%s/translations", project_id, key_id)
1800
+ data_hash = {}
1801
+ post_body = nil
1802
+
1803
+ data_hash = params.to_h
1804
+ err = params.validate
1805
+ if err != nil
1806
+ return nil, err
1807
+ end
1808
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1809
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1810
+ if err != nil
1811
+ return nil, err
1812
+ end
1813
+
1814
+ return JSON.load(rc.body).map { |item| PhraseApp::Translation.new(item) }, err
1815
+ end
1816
+
1817
+ # List translations for a specific locale.
1818
+ def self.translation_list_locale(project_id, locale_id, page, per_page, params)
1819
+ path = sprintf("/v2/projects/%s/locales/%s/translations", project_id, locale_id)
1820
+ data_hash = {}
1821
+ post_body = nil
1822
+
1823
+ data_hash = params.to_h
1824
+ err = params.validate
1825
+ if err != nil
1826
+ return nil, err
1827
+ end
1828
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1829
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1830
+ if err != nil
1831
+ return nil, err
1832
+ end
1833
+
1834
+ return JSON.load(rc.body).map { |item| PhraseApp::Translation.new(item) }, err
1835
+ end
1836
+
1837
+ # Get details on a single translation.
1838
+ def self.translation_show(project_id, id)
1839
+ path = sprintf("/v2/projects/%s/translations/%s", project_id, id)
1840
+ data_hash = {}
1841
+ post_body = nil
1842
+
1843
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1844
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1845
+ if err != nil
1846
+ return nil, err
1847
+ end
1848
+
1849
+ return PhraseApp::TranslationDetails.new(JSON.load(rc.body)), err
1850
+ end
1851
+
1852
+ # Update an existing translation.
1853
+ def self.translation_update(project_id, id, params)
1854
+ path = sprintf("/v2/projects/%s/translations/%s", project_id, id)
1855
+ data_hash = {}
1856
+ post_body = nil
1857
+
1858
+ data_hash = params.to_h
1859
+ err = params.validate
1860
+ if err != nil
1861
+ return nil, err
1862
+ end
1863
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1864
+ rc, err = PhraseApp.send_request("PATCH", path, reqHelper.ctype, reqHelper.body, 200)
1865
+ if err != nil
1866
+ return nil, err
1867
+ end
1868
+
1869
+ return PhraseApp::TranslationDetails.new(JSON.load(rc.body)), err
1870
+ end
1871
+
1872
+ # Upload a new file to your project. This will extract all new content such as keys, translations, locales, tags etc. and store them in your project.
1873
+ def self.upload_create(project_id, params)
1874
+ path = sprintf("/v2/projects/%s/uploads", project_id)
1875
+ data_hash = {}
1876
+ post_body = nil
1877
+ if params.convert_emoji != nil
1878
+ data_hash["convert_emoji"] = (params.convert_emoji == "true")
1879
+ end
1880
+
1881
+ if params.file != nil
1882
+ post_body = []
1883
+ post_body << "--#{PhraseApp::MULTIPART_BOUNDARY}\r\n"
1884
+ post_body << "Content-Disposition: form-data; name=\"file\"; filename=\"#{File.basename(params.file )}\"\r\n"
1885
+ post_body << "Content-Type: text/plain\r\n"
1886
+ post_body << "\r\n"
1887
+ post_body << File.read(params.file)
1888
+ post_body << "\r\n"
1889
+ end
1890
+
1891
+ if params.format != nil
1892
+ data_hash["format"] = params.format
1893
+ end
1894
+
1895
+ if params.format_options != nil
1896
+ params.format_options.each do |key, value|
1897
+ data_hash["format_options"][key] = value
1898
+ end
1899
+ end
1900
+
1901
+ if params.locale_id != nil
1902
+ data_hash["locale_id"] = params.locale_id
1903
+ end
1904
+
1905
+ if params.skip_unverification != nil
1906
+ data_hash["skip_unverification"] = (params.skip_unverification == "true")
1907
+ end
1908
+
1909
+ if params.skip_upload_tags != nil
1910
+ data_hash["skip_upload_tags"] = (params.skip_upload_tags == "true")
1911
+ end
1912
+
1913
+ if params.tags != nil
1914
+ data_hash["tags"] = params.tags
1915
+ end
1916
+
1917
+ if params.update_translations != nil
1918
+ data_hash["update_translations"] = (params.update_translations == "true")
1919
+ end
1920
+
1921
+
1922
+
1923
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1924
+ rc, err = PhraseApp.send_request("POST", path, reqHelper.ctype, reqHelper.body, 201)
1925
+ if err != nil
1926
+ return nil, err
1927
+ end
1928
+
1929
+ return PhraseApp::LocaleFileImportWithSummary.new(JSON.load(rc.body)), err
1930
+ end
1931
+
1932
+ # View details and summary for a single upload.
1933
+ def self.upload_show(project_id, id)
1934
+ path = sprintf("/v2/projects/%s/uploads/%s", project_id, id)
1935
+ data_hash = {}
1936
+ post_body = nil
1937
+
1938
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1939
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1940
+ if err != nil
1941
+ return nil, err
1942
+ end
1943
+
1944
+ return PhraseApp::LocaleFileImportWithSummary.new(JSON.load(rc.body)), err
1945
+ end
1946
+
1947
+ # List all versions for the given translation.
1948
+ def self.version_list(project_id, translation_id, page, per_page)
1949
+ path = sprintf("/v2/projects/%s/translations/%s/versions", project_id, translation_id)
1950
+ data_hash = {}
1951
+ post_body = nil
1952
+
1953
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1954
+ rc, err = PhraseApp.send_request_paginated("GET", path, reqHelper.ctype, reqHelper.body, 200, page, per_page)
1955
+ if err != nil
1956
+ return nil, err
1957
+ end
1958
+
1959
+ return JSON.load(rc.body).map { |item| PhraseApp::TranslationVersion.new(item) }, err
1960
+ end
1961
+
1962
+ # Get details on a single version.
1963
+ def self.version_show(project_id, translation_id, id)
1964
+ path = sprintf("/v2/projects/%s/translations/%s/versions/%s", project_id, translation_id, id)
1965
+ data_hash = {}
1966
+ post_body = nil
1967
+
1968
+ reqHelper = PhraseApp::RequestHelper.new(data_hash, post_body)
1969
+ rc, err = PhraseApp.send_request("GET", path, reqHelper.ctype, reqHelper.body, 200)
1970
+ if err != nil
1971
+ return nil, err
1972
+ end
1973
+
1974
+ return PhraseApp::TranslationVersionWithUser.new(JSON.load(rc.body)), err
1975
+ end
1976
+
1977
+ end