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.
@@ -4,53 +4,55 @@ module PhraseApp
4
4
 
5
5
  API_CLIENT_IDENTIFIER = "PhraseApp Ruby " + VERSION
6
6
 
7
- class ErrorResponse
8
- attr_accessor :message
7
+ module RequestErrors
8
+ class ErrorResponse
9
+ attr_accessor :message
9
10
 
10
- def initialize(http_response)
11
- end
11
+ def initialize(http_response)
12
+ end
12
13
 
13
- def error
14
- self.message
14
+ def error
15
+ self.message
16
+ end
15
17
  end
16
- end
17
18
 
18
- class ValidationErrorResponse
19
- attr_accessor :error_response
20
- attr_accessor :errors
19
+ class ValidationErrorResponse
20
+ attr_accessor :error_response
21
+ attr_accessor :errors
21
22
 
22
- def initialize(http_response)
23
- hash = JSON.load(http_response.body)
24
- puts hash.inspect
25
- end
23
+ def initialize(http_response)
24
+ hash = JSON.load(http_response.body)
25
+ puts hash.inspect
26
+ end
26
27
 
27
- def errors
28
- self.error + "\n" + self.errors.join("\n")
28
+ def errors
29
+ self.error + "\n" + self.errors.join("\n")
30
+ end
29
31
  end
30
- end
31
32
 
32
- class ValidationErrorMessage
33
- attr_accessor :resource, :field, :message
33
+ class ValidationErrorMessage
34
+ attr_accessor :resource, :field, :message
34
35
 
35
- def to_s
36
- return sprintf("\t[%s:%s] %s", self.resource, self.field, self.message)
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
- class RateLimitingError
41
- attr_accessor :limit, :remaining, :reset
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
- def initialize(resp)
44
- re = RateLimitingError.new(resp)
45
- puts resp.body.inspect
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
@@ -1,3 +1,3 @@
1
1
  module PhraseApp
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  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.0.3
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-06-18 00:00:00.000000000 Z
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: