da_face 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 868b1428a056a9be26cea60cb95d55b9ed0810b7
4
- data.tar.gz: 9fcc13e2e0724b38977f32abd7e11d76959dc05b
3
+ metadata.gz: a2942804b9b9fc4b13b567d03c17d29c9d8b2687
4
+ data.tar.gz: 79b0915bdf5852fefd3e782fe7b1fc2cec85831d
5
5
  SHA512:
6
- metadata.gz: 2172ad20e3370a2a205d08dfdb93e4c8784e7234dee42a81be55bd9e0c3e51fe668ee97e1f87e61115bef01bd361adf9757def0252a789f20ee06a5adfd2f977
7
- data.tar.gz: fc860afe4305c39b942f15b71ffbf7a987bcfe553910a46813f9a9856cf7123551cf0e26f97152a54bf9b17686a0ad2182f2fa1dc53cc1204f41ee88b480eb68
6
+ metadata.gz: 2f54d40c636aee06417a7c66da31435f4db54569dd202884ccd14fbe6f902bd510f4b17caa30cc4fc517f4003d69a5120d1c804224c5d8b31ae36506da594658
7
+ data.tar.gz: 0f30a636b8154103aa6462dfb7928941623ccce58b171c33dd1f354e1306c235a8fed4a18594ca78886831984bee6c948ae8d765a1c148463c4cbc35d9a98444
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- da_face (0.0.9)
4
+ da_face (0.0.10)
5
5
  excon
6
6
  json
7
7
  yajl-ruby
@@ -45,6 +45,11 @@ module DaFace
45
45
  @rate_limit_status ||= DaFace::Api::RateLimitStatus.new
46
46
  end
47
47
 
48
+ def set_rate_limit_status
49
+ yield(rate_limit_status)
50
+ self.rate_limit_status
51
+ end
52
+
48
53
  def configure
49
54
  yield(configuration)
50
55
  self.configuration
@@ -53,7 +53,10 @@ module DaFace
53
53
  end
54
54
 
55
55
  def set_rate_limit_status rate_limit, remaining
56
- DaFace.rate_limit_status = DaFace::Api::RateLimitStatus.new(:limit => rate_limit, :remaining => remaining)
56
+ DaFace.set_rate_limit_status do |status|
57
+ status.limit = rate_limit
58
+ status.remaining = remaining
59
+ end
57
60
  end
58
61
 
59
62
  end
@@ -30,16 +30,28 @@ module DaFace
30
30
  end
31
31
 
32
32
  def handle_response response
33
- rate_limit_info = extract_rate_limit_info(response)
33
+ rate_limit_info = extract_rate_limit_info(response.headers)
34
34
  set_rate_limit_status(rate_limit_info[:limit], rate_limit_info[:remaining])
35
35
  return parse_body(response.body)
36
36
  end
37
37
 
38
- def extract_rate_limit_info response
39
- {
40
- :limit => response.headers['x-ratelimit-limit'],
41
- :remaining => response.headers['x-ratelimit-remaining']
42
- }
38
+ def extract_rate_limit_info headers
39
+ if headers.select{|header| header[0] == 'x'}.any?
40
+ {
41
+ :limit => headers['x-ratelimit-limit'],
42
+ :remaining => headers['x-ratelimit-remaining']
43
+ }
44
+ elsif headers.select{|header| header[0] == 'X'}.any?
45
+ {
46
+ :limit => headers['X-RateLimit-Limit'],
47
+ :remaining => headers['X-RateLimit-Remaining']
48
+ }
49
+ else
50
+ {
51
+ :limit => nil,
52
+ :remaining => nil
53
+ }
54
+ end
43
55
  end
44
56
  end
45
57
  end
@@ -5,7 +5,7 @@ module DaFace
5
5
 
6
6
  def initialize data
7
7
  @request_time = Time.at data[:request_time]
8
- @sucess = data[:success]
8
+ @success = data[:success]
9
9
  @subscription_id = data[:subscription_id]
10
10
  @message = data[:message]
11
11
  end
@@ -1,13 +1,8 @@
1
1
  module DaFace
2
2
  module Api
3
3
  class RateLimitStatus
4
- attr_reader :limit, :remaining
5
-
6
- def initialize attrs={}
7
- @rate_limit = attrs[:limit]
8
- @remaining_credits = attrs[:remaining]
9
- end
10
-
4
+ attr_accessor :limit, :remaining
5
+
11
6
  end
12
7
  end
13
8
  end
@@ -1,3 +1,3 @@
1
1
  module DaFace
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: da_face
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rayko