intercom 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1105afd003920f148d703151927542f8174aae57
4
- data.tar.gz: 13cd1a35776e6b353ed85884157992b9f7750a77
3
+ metadata.gz: d9e9fc89a1afe0812e99ba788f34abb10a2efee6
4
+ data.tar.gz: 22a8b523d0118dca4f92f9429ddc046ab3126d1d
5
5
  SHA512:
6
- metadata.gz: 37bf3114fcb13dda58f34ce37623ab33adee640ded7d45c1aeb4e452ee4ebe7492fcc3f76ce48d53bfddd559795e1dc83e76e6e0a48eef696b3590a866729769
7
- data.tar.gz: 8bc6eb1b8e44ca74e095ea3f74ea848bba15cafadf1421802921b3f43f599d31154d2f5fc124824eb72a703ff8a70a239a0e31377be7f0d310c7d2bcfa952235
6
+ metadata.gz: 06825933a4db65f7ea657c6525bc350d9df83cb3ad84a5baf4bb7043f061f32ccd8d7480d8a0bbe73614dda861375f4bd990c80d140f5b6feb90b60bab99ea94
7
+ data.tar.gz: f7059cecea4a6add02f0fcf1d28ea717a78829631393ed7f6d4e017e342e366da481affe6c9d4bf0aa95fa37f5d94f106f723126a30999f60e0594848d8c6e88
data/README.md CHANGED
@@ -19,7 +19,7 @@ Additionally, the new version uses Ruby 2.
19
19
 
20
20
  Using bundler:
21
21
 
22
- gem 'intercom', "~> 2.2.2"
22
+ gem 'intercom', "~> 2.2.3"
23
23
 
24
24
  ## Basic Usage
25
25
 
@@ -343,3 +343,13 @@ Intercom::BadRequestError
343
343
  Intercom::RateLimitExceeded
344
344
  Intercom::AttributeNotSetError # Raised when you try to call a getter that does not exist on an object
345
345
  ```
346
+
347
+ ### Rate Limiting
348
+
349
+ Calling `Intercom.rate_limit_details` returns a Hash that contains details about your app's current rate limit.
350
+
351
+ ```ruby
352
+ Intercom.rate_limit_details
353
+ #=> {:limit=>180, :remaining=>179, :reset_at=>2014-10-07 14:58:00 +0100}
354
+ ```
355
+
@@ -1,3 +1,6 @@
1
+ 2.2.3
2
+ - Add rate limiting details to Intercom.rate_limiting_details
3
+
1
4
  2.2.2
2
5
  - Improve spec strings (thanks to @jkeyes)
3
6
  - Improve README readability (thanks to @jkeyes)
@@ -36,6 +36,7 @@ module Intercom
36
36
  @current_endpoint = nil
37
37
  @app_id = nil
38
38
  @app_api_key = nil
39
+ @rate_limit_details = {}
39
40
 
40
41
  def self.app_id=(app_id)
41
42
  @app_id = app_id
@@ -48,10 +49,19 @@ module Intercom
48
49
  def self.app_api_key=(app_api_key)
49
50
  @app_api_key = app_api_key
50
51
  end
52
+
51
53
  def self.app_api_key
52
54
  @app_api_key
53
55
  end
54
56
 
57
+ def self.rate_limit_details=(rate_limit_details)
58
+ @rate_limit_details = rate_limit_details
59
+ end
60
+
61
+ def self.rate_limit_details
62
+ @rate_limit_details
63
+ end
64
+
55
65
  # This method is obsolete and used to warn of backwards incompatible changes on upgrading
56
66
  def self.api_key=(val)
57
67
  raise ArgumentError, "#{compatibility_warning_text} #{compatibility_workaround_text} #{related_docs_text}"
@@ -61,6 +61,7 @@ module Intercom
61
61
  client(base_uri).start do |http|
62
62
  begin
63
63
  response = http.request(net_http_method)
64
+ set_rate_limit_details(response)
64
65
  decoded = decode(response['content-encoding'], response.body)
65
66
  unless decoded.strip.empty?
66
67
  parsed_body = JSON.parse(decoded)
@@ -77,6 +78,14 @@ module Intercom
77
78
  end
78
79
  end
79
80
 
81
+ def set_rate_limit_details(response)
82
+ rate_limit_details = {}
83
+ rate_limit_details[:limit] = response['X-RateLimit-Limit'].to_i if response['X-RateLimit-Limit']
84
+ rate_limit_details[:remaining] = response['X-RateLimit-Remaining'].to_i if response['X-RateLimit-Remaining']
85
+ rate_limit_details[:reset_at] = Time.at(response['X-RateLimit-Reset'].to_i) if response['X-RateLimit-Reset']
86
+ Intercom.rate_limit_details = rate_limit_details
87
+ end
88
+
80
89
  def decode(content_encoding, body)
81
90
  return body if (!body) || body.empty? || content_encoding != 'gzip'
82
91
  Zlib::GzipReader.new(StringIO.new(body)).read
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "2.2.2"
2
+ VERSION = "2.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercom
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben McRedmond
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2014-10-03 00:00:00.000000000 Z
18
+ date: 2014-10-07 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: minitest