Skip to content

prefers IPv6 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/mandrill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,25 @@ def initialize(apikey=nil, debug=false)
@host = 'https://mandrillapp.com'
@path = '/api/1.0/'

@session = Excon.new @host
# IPv6を優先して使うようにする
prefers_ipv6_dns_resolver = Class.new(Resolv::DNS) do
def each_address(name)
return super unless use_ipv6?
addresses = []
super do |address|
if Resolv::IPv6::Regex =~ address
addresses.unshift address
else
addresses << resource.address
end
end
addresses.each {|address| yield address}
true
end
end.new
resolver = Resolv.new([Resolv::Hosts.new, prefers_ipv6_dns_resolver])

@session = Excon.new @host, resolv_resolver: resolver
@debug = debug

if not apikey
Expand Down
2 changes: 1 addition & 1 deletion mandrill-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Gem::Specification.new do |s|
s.files = ['lib/mandrill.rb', 'lib/mandrill/api.rb', 'lib/mandrill/errors.rb']
s.homepage = 'https://bitbucket.org/mailchimp/mandrill-api-ruby/'
s.add_dependency 'json', '>= 1.7.7'
s.add_dependency 'excon', '>= 0.16.0', '< 1.0'
s.add_dependency 'excon', '>= 0.104.0', '< 1.0'
end