phraseapp-ruby 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/phraseapp-ruby/request_handler.rb +18 -23
- data/lib/phraseapp-ruby/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11e4707b7b9c2da831994392d1fdd9812de354e9
|
4
|
+
data.tar.gz: 22ff9f24809cc29e66dd4f5292e8c01da1517d93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2d4640c59a99f737a8c5f831fa08d2011f98a0b9e0ecbac9897fc06651a561bccc68d8459b5471bf637a85143f3bdd9041ab0a118dd668e5e2bebec41b7f051
|
7
|
+
data.tar.gz: 21ea75c0ff64a75643ae777546e1597918aeb00cf712b480318c159c699658bc4a07dd2930521a66f3fde9d3384cac44c00ca9e09d59517eddaa8ed4c6d0ed83
|
@@ -6,9 +6,11 @@ module PhraseApp
|
|
6
6
|
|
7
7
|
module RequestErrors
|
8
8
|
class ErrorResponse
|
9
|
-
|
9
|
+
attr_reader :message
|
10
10
|
|
11
11
|
def initialize(http_response)
|
12
|
+
hash = JSON.load(http_response.body)
|
13
|
+
self.message = hash['message']
|
12
14
|
end
|
13
15
|
|
14
16
|
def error
|
@@ -17,21 +19,24 @@ module PhraseApp
|
|
17
19
|
end
|
18
20
|
|
19
21
|
class ValidationErrorResponse
|
20
|
-
|
21
|
-
|
22
|
+
attr_reader :message
|
23
|
+
attr_reader :errors
|
22
24
|
|
23
25
|
def initialize(http_response)
|
24
26
|
hash = JSON.load(http_response.body)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def errors
|
29
|
-
self.error + "\n" + self.errors.join("\n")
|
27
|
+
self.message = hash['message']
|
28
|
+
self.errors = hash['errors'].map { |error| ValidationErrorMessage.new(error) }
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
32
|
class ValidationErrorMessage
|
34
|
-
|
33
|
+
attr_reader :resource, :field, :message
|
34
|
+
|
35
|
+
def initialize(error)
|
36
|
+
self.resource = error["resource"]
|
37
|
+
self.field = error["field"]
|
38
|
+
self.message = error["message"]
|
39
|
+
end
|
35
40
|
|
36
41
|
def to_s
|
37
42
|
return sprintf("\t[%s:%s] %s", self.resource, self.field, self.message)
|
@@ -39,13 +44,12 @@ module PhraseApp
|
|
39
44
|
end
|
40
45
|
|
41
46
|
class RateLimitingError
|
42
|
-
|
47
|
+
attr_reader :limit, :remaining, :reset
|
43
48
|
|
44
49
|
def initialize(resp)
|
45
50
|
self.limit = resp["X-Rate-Limit-Limit"].to_i
|
46
51
|
self.remaining = resp["X-Rate-Limit-Remaining"].to_i
|
47
52
|
self.reset = Time.at(resp["X-Rate-Limit-Reset"].to_i)
|
48
|
-
return re, nil
|
49
53
|
end
|
50
54
|
|
51
55
|
def to_s
|
@@ -157,22 +161,13 @@ module PhraseApp
|
|
157
161
|
when expectedStatus
|
158
162
|
return
|
159
163
|
when 400
|
160
|
-
|
161
|
-
return e
|
164
|
+
return PhraseApp::RequestErrors::ErrorResponse.new(resp)
|
162
165
|
when 404
|
163
166
|
return raise("not found")
|
164
167
|
when 422
|
165
|
-
|
166
|
-
if e != nil
|
167
|
-
return e
|
168
|
-
end
|
169
|
-
return e
|
168
|
+
return PhraseApp::RequestErrors::ValidationErrorResponse.new(resp)
|
170
169
|
when 429
|
171
|
-
|
172
|
-
if err != nil
|
173
|
-
return err
|
174
|
-
end
|
175
|
-
return e
|
170
|
+
return PhraseApp::RequestErrors::RateLimitingError.new(resp)
|
176
171
|
else
|
177
172
|
return raise("unexpected status code (#{resp.code}) received; expected #{expectedStatus}")
|
178
173
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phraseapp-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PhraseApp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: PhraseApp API client libary
|
14
14
|
email:
|
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
43
|
rubyforge_project:
|
44
|
-
rubygems_version: 2.4.
|
44
|
+
rubygems_version: 2.4.5.1
|
45
45
|
signing_key:
|
46
46
|
specification_version: 4
|
47
47
|
summary: Interact with the PhraseApp API
|