phraseapp-ruby 1.0.3 → 1.0.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.rb +3054 -2274
- data/lib/request_handler.rb +40 -38
- data/lib/version.rb +1 -1
- metadata +3 -2
data/lib/request_handler.rb
CHANGED
@@ -4,53 +4,55 @@ module PhraseApp
|
|
4
4
|
|
5
5
|
API_CLIENT_IDENTIFIER = "PhraseApp Ruby " + VERSION
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
module RequestErrors
|
8
|
+
class ErrorResponse
|
9
|
+
attr_accessor :message
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
def initialize(http_response)
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
def error
|
15
|
+
self.message
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
class ValidationErrorResponse
|
20
|
+
attr_accessor :error_response
|
21
|
+
attr_accessor :errors
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def initialize(http_response)
|
24
|
+
hash = JSON.load(http_response.body)
|
25
|
+
puts hash.inspect
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
def errors
|
29
|
+
self.error + "\n" + self.errors.join("\n")
|
30
|
+
end
|
29
31
|
end
|
30
|
-
end
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
class ValidationErrorMessage
|
34
|
+
attr_accessor :resource, :field, :message
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
def to_s
|
37
|
+
return sprintf("\t[%s:%s] %s", self.resource, self.field, self.message)
|
38
|
+
end
|
37
39
|
end
|
38
|
-
end
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
class RateLimitingError
|
42
|
+
attr_accessor :limit, :remaining, :reset
|
43
|
+
|
44
|
+
def initialize(resp)
|
45
|
+
re = RateLimitingError.new(resp)
|
46
|
+
puts resp.body.inspect
|
47
|
+
re.limit = resp["X-Rate-Limit-Limit"].to_i
|
48
|
+
re.remaining = resp["X-Rate-Limit-Remaining"].to_i
|
49
|
+
re.reset = Time.at(resp["X-Rate-Limit-Reset"].to_i)
|
50
|
+
return re, nil
|
51
|
+
end
|
42
52
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
re.limit = resp["X-Rate-Limit-Limit"].to_i
|
47
|
-
re.remaining = resp["X-Rate-Limit-Remaining"].to_i
|
48
|
-
re.reset = Time.at(resp["X-Rate-Limit-Reset"].to_i)
|
49
|
-
return re, nil
|
50
|
-
end
|
51
|
-
|
52
|
-
def to_s
|
53
|
-
sprintf("Rate limit exceeded: from %d requests %d are remaning (reset in %d seconds)", self.limit, self.remaining, int64(rle.Reset.Sub(time.Now()).Seconds()))
|
53
|
+
def to_s
|
54
|
+
sprintf("Rate limit exceeded: from %d requests %d are remaning (reset in %d seconds)", self.limit, self.remaining, int64(rle.Reset.Sub(time.Now()).Seconds()))
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
@@ -129,18 +131,18 @@ module PhraseApp
|
|
129
131
|
when expectedStatus
|
130
132
|
return
|
131
133
|
when 400
|
132
|
-
e = ErrorResponse.new(resp)
|
134
|
+
e = PhraseApp::RequestErrors::ErrorResponse.new(resp)
|
133
135
|
return e
|
134
136
|
when 404
|
135
137
|
return raise("not found")
|
136
138
|
when 422
|
137
|
-
e = ValidationErrorResponse.new(resp)
|
139
|
+
e = PhraseApp::RequestErrors::ValidationErrorResponse.new(resp)
|
138
140
|
if e != nil
|
139
141
|
return e
|
140
142
|
end
|
141
143
|
return e
|
142
144
|
when 429
|
143
|
-
e, err = RateLimitError.new(resp)
|
145
|
+
e, err = PhraseApp::RequestErrors::RateLimitError.new(resp)
|
144
146
|
if err != nil
|
145
147
|
return err
|
146
148
|
end
|
data/lib/version.rb
CHANGED
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.0.
|
4
|
+
version: 1.0.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-
|
11
|
+
date: 2015-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: PhraseApp API client libary
|
14
14
|
email:
|
@@ -46,3 +46,4 @@ signing_key:
|
|
46
46
|
specification_version: 4
|
47
47
|
summary: Interact with the PhraseApp API
|
48
48
|
test_files: []
|
49
|
+
has_rdoc:
|