Skip to content

Commit

Permalink
Merge pull request #146 from Shopify/enhance_throttle_for_ns1
Browse files Browse the repository at this point in the history
Add API rate limit for NS1 provider and bump up the version to 5.7.1
  • Loading branch information
gooallen committed Nov 11, 2019
2 parents c55edc2 + 664bfa3 commit ed9db71
Show file tree
Hide file tree
Showing 23 changed files with 5,532 additions and 6,243 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,7 @@
# CHANGELOG
## 5.7.1
- add API rate limit for NS1 provider [FEATURE]

## 5.7.0
- add OCI library as runtime dependency [FEATURE]

Expand Down
1 change: 1 addition & 0 deletions lib/record_store/provider/ns1.rb
@@ -1,4 +1,5 @@
require_relative 'ns1/client'
require_relative 'ns1/patch_api_header'

module RecordStore
class Provider::NS1 < Provider
Expand Down
21 changes: 21 additions & 0 deletions lib/record_store/provider/ns1/patch_api_header.rb
@@ -0,0 +1,21 @@
require 'net/http'

# Patch the method which retrieves headers for API rate limit dynamically
module NS1::Transport
class NetHttp
def process_response(response)
sleep(response.to_hash["x-ratelimit-period"].first.to_i /
[1, response.to_hash["x-ratelimit-remaining"].first.to_i].max.to_f)

body = JSON.parse(response.body)
case response
when Net::HTTPOK
NS1::Response::Success.new(body, response.code.to_i)
else
NS1::Response::Error.new(body, response.code.to_i)
end
rescue JSON::ParserError
raise NS1::Transport::ResponseParseError
end
end
end
2 changes: 1 addition & 1 deletion lib/record_store/version.rb
@@ -1,3 +1,3 @@
module RecordStore
VERSION = '5.7.0'.freeze
VERSION = '5.7.1'.freeze
end
325 changes: 103 additions & 222 deletions test/fixtures/vcr_cassettes/ns1_add_a_changeset.yml

Large diffs are not rendered by default.

378 changes: 306 additions & 72 deletions test/fixtures/vcr_cassettes/ns1_add_alias_changeset.yml

Large diffs are not rendered by default.

433 changes: 163 additions & 270 deletions test/fixtures/vcr_cassettes/ns1_add_caa_changeset.yml

Large diffs are not rendered by default.

32 changes: 18 additions & 14 deletions test/fixtures/vcr_cassettes/ns1_add_changeset.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 16 additions & 12 deletions test/fixtures/vcr_cassettes/ns1_add_changeset_missing_zone.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ed9db71

Please sign in to comment.