Skip to content

Commit

Permalink
Merge pull request #11 from thewoolleyman/master
Browse files Browse the repository at this point in the history
Add HTTP proxy support
  • Loading branch information
billthompson authored Oct 24, 2017
2 parents b355e28 + c09e5bb commit 9144cb2
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
source "http://rubygems.org"

# chrisk is updating it, but hasn't released a gem yet - see https://github.com/chrisk/fakeweb/issues/57#issuecomment-325515168
# Once a gem is released, remove this line and uncomment the one in enom.gemspec
gem 'fakeweb', git: 'https://github.com/chrisk/fakeweb.git'
gem "jruby-openssl", :platform => :jruby

gemspec
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Enom::Client.username = "foo"
Enom::Client.password = "bar"
Enom::Client.test = true
# Declaring test mode is optional, defaults to false (production)
# Test mode will run commands on Enom's reseller test platform
# Test mode will run commands on Enom's resellertest.enom.com test platform
```

Once these are set, subsequent commands will make calls to the API using your credentials (HTTPS). Any methods in the library that charge or refund the account in any way end with a bang (!).
Expand Down Expand Up @@ -102,6 +102,18 @@ d.renew!
d.renew!(:years => 3)
```

## Host Override and Proxy/Tunnel Support

If you want to use an HTTP proxy server to avoid having to add an IP to the Enom IP whitelist
(which has been known to be slow/flaky to recognize new IPs), you can set the
`proxyaddr` client option to point to your proxy server:

```
Enom::Client.proxyaddr = 'enom-proxy.example.com'
```

You can also optionally set `proxyport`, `proxyuser`, and `proxypass`.

## Copyright

Copyright (c) 2011-2013 James Miller
18 changes: 18 additions & 0 deletions bin/enom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def usage
You can run commands from the test interface with the -t flag:
enom -u username -p password -t command
You can set an http proxy host with the --proxyaddr flag, e.g. to use a proxy
server with an already-whitelisted IP. You can also optionally specify
the proxy port, user, and password.
enom -u username -p password --proxyaddr enom-proxy.example.com --proxyport 1080 --proxyuser user --proxypass pass
== Commands
All commands are executed as enom [options] command [command-options] args
Expand Down Expand Up @@ -55,6 +61,18 @@ def usage
opts.on("-t") do
Enom::Client.test = true
end
opts.on("--proxyaddr [ARG]") do |proxyaddr|
Enom::Client.proxyaddr = proxyaddr
end
opts.on("--proxyport [ARG]") do |proxyport|
Enom::Client.proxyport = proxyport
end
opts.on("--proxyuser [ARG]") do |proxyuser|
Enom::Client.proxyuser = proxyuser
end
opts.on("--proxypass [ARG]") do |proxypass|
Enom::Client.proxypass = proxypass
end
end

global.order!
Expand Down
10 changes: 6 additions & 4 deletions enom.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ Gem::Specification.new do |s|
s.email = "[email protected]"
s.files = %w( README.md Rakefile LICENSE ) + ["lib/enom.rb"] + Dir.glob("lib/enom/*.rb") + Dir.glob("lib/enom/commands/*.rb") + Dir.glob("test/**/*") + Dir.glob("bin/*")
s.has_rdoc = false
s.add_dependency "httparty", "~> 0.10.0"
s.add_dependency "httparty", "~> 0.15"
s.add_dependency "public_suffix", "~> 3.0.0"
s.add_dependency "activesupport", "> 4.2"
s.add_development_dependency "test-unit"
s.add_development_dependency "shoulda"
s.add_development_dependency "fakeweb"
s.add_development_dependency "rake", "~> 0.9"
s.add_development_dependency "shoulda", "~> 3.5"
# chrisk is updating fakeweb, but hasn't released a gem yet - see https://github.com/chrisk/fakeweb/issues/57#issuecomment-325515168
# Once a gem is released, remove the line in the Gemfile and uncomment this one
# s.add_development_dependency "fakeweb"
s.add_development_dependency "rake", "~> 12.0"
s.executables = %w(enom)
s.default_executable = "enom"
end
3 changes: 2 additions & 1 deletion lib/enom/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Client
include HTTParty

class << self
attr_accessor :username, :password, :test
attr_accessor :username, :password, :test, :proxyaddr, :proxyport, :proxyuser, :proxypass
alias_method :test?, :test

# All requests must contain the UID, PW, and ResponseType query parameters
Expand All @@ -24,6 +24,7 @@ def base_uri
# or other helpful statuses -- everything comes back as a 200.
def request(params = {})
params.merge!(default_params)
http_proxy(proxyaddr, proxyport, proxyuser, proxypass)
response = get(base_uri, :query => params)
case response.code
when 200
Expand Down
2 changes: 1 addition & 1 deletion lib/enom/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def set_extended_domain_attributes(attributes)
#
# @raise [Enom::InterfaceError] If response is invalid
def validate_response!(response)
unless response.is_a?(Hash) && response.key?('interface_response')
unless response.respond_to?(:key?) && response.key?('interface_response')
raise Enom::InterfaceError, response.inspect
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Test::Unit::TestCase
},
{
:command => "Check Many with default (*) TLD list (Success)",
:request => "https://reseller.enom.com/interface.asp?Command=Check&SLD=test123456test123456&TLD=*&TLDList=&UID=resellid&PW=resellpw&ResponseType=xml",
:request => "https://reseller.enom.com/interface.asp?Command=Check&SLD=test123456test123456&TLD=%2A&TLDList=&UID=resellid&PW=resellpw&ResponseType=xml",
:response => <<-EOF
<?xml version="1.0"?>
<interface-response>
Expand Down

0 comments on commit 9144cb2

Please sign in to comment.