GithubHelp home page GithubHelp logo

voxxit / opensrs Goto Github PK

View Code? Open in Web Editor NEW
59.0 4.0 43.0 152 KB

Ruby wrapper for the OpenSRS API

Home Page: https://github.com/voxxit/opensrs

License: MIT License

Ruby 99.73% Shell 0.27%
ruby rails opensrs domains api

opensrs's Introduction

OpenSRS

Coverage Status

This unofficial OpenSRS gem provides basic support to connect to and utilize the OpenSRS API. This library has been well-tested in high-performance production environments.

Requirements

  • Ruby >= 2.5

Installation

You can install this gem by doing the following:

$ gem install opensrs

You can then include it in a Ruby project, like so:

require 'opensrs'

For Rails 3.x and above, add it to the Gemfile:

gem 'opensrs'
gem 'nokogiri'    # if you want to use nokogiri as the XML parser
gem 'libxml-ruby' # if you want to use libxml as the XML parser

Usage

This library provides basic functionality for interacting with the OpenSRS XML API.

  • Connection handling
  • Error reporting
  • XML encoding
  • XML decoding

Currently, the library supports LibXML and Nokogiri as XML parsers. By default, it uses LibXML to parse and generate XML. If you'd like to use Nokogiri (1.4.7 and below) for parsing XML, then in one of your app initializers add the following line:

OpenSRS::Server.xml_processor = :nokogiri

or

OpenSRS::Server.xml_processor = :libxml

To connect, instantiate a new OpenSRS::Server object:

server = OpenSRS::Server.new(
  server:   "https://rr-n1-tor.opensrs.net:55443/",
  username: "testing",
  password: "53cr3t",
  key:      "c633be3170c7fb3fb29e2f99b84be2410..."
)

NOTE: Connecting to OpenSRS requires that you add the IP(s) you're connecting from to their whitelist. Log in to the testing or production servers, and add your IP(s) under Profile Management > Add IPs for Script/API Access. IP changes take about one hour to take effect.

If you would like, you can provide OpenSRS::Server with a logger to write the contents of the requests and responses with OpenSRS. The assumption is you are using a Rails-like logger, but as long as your logger has an info method you are fine. You can simply assign the logger or pass it in as an initialization option:

server = OpenSRS::Server.new(
  server:   "https://rr-n1-tor.opensrs.net:55443/",
  username: "testing",
  password: "53cr3t",
  key:      "c633be3170c7fb3fb29e2f99b84be2410...",
  logger:   Rails.logger
)

or, if you can change it later:

server.logger = Rails.logger

Once you have a server connection class, you can build from this to create the methods that you need. For instance, let's say we want to grab our account balance. The OpenSRS XML API takes a couple of attributes for all commands. You can include those here:

def get_balance
  server.call(
    action: "GET_BALANCE",
    object: "BALANCE"
  )
end

Sometimes you might need to include attributes for the command, such as a cookie, or the data attributes themselves. You can do this, too:

def create_nameserver(nameserver)
  server.call(
    action: "CREATE",
    object: "NAMESERVER",
    cookie: "366828736:3210384",
    attributes: {
      name: nameserver.hostname,
      ipaddress: "212.112.123.11"
    }
  )
end

Responses from OpenSRS are returned in an OpenSRS::Response object, which gives you access to a multitude of things.

Method Description
response.response This gives you the response in a Hash form, which is highly accessible to most other actions in your application.
response.errors If there are errors which come back from OpenSRS, they are returned here. If not, it returns nil.
response.success? Returns true if the response was labeled as successful. If not, it returns false.
response.request_xml Returns raw request XML.
response.response_xml Returns raw response XML.

Bugs/Feature Requests

If you have any bugs or feature requests for this gem, feel free to open an issue.

How To Contribute

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add specs for it.
  • Commit, but do not mess with Rakefile or version.
  • Send me a pull request. Bonus points for topic branches!

Contributors (in order of appearance)

See "Contributors" section of GitHub Insights.

Copyright

Copyright (c) 2010-2022 Joshua Delsman.

Distributed under the MIT license. See LICENSE for details.

opensrs's People

Contributors

afeld avatar apfritts avatar bitdeli-chef avatar choxi avatar cjoudrey avatar dependabot[bot] avatar fw42 avatar gitter-badger avatar glennr avatar jloppert avatar jsaubry avatar jstorimer avatar pbevin avatar rorymckinley avatar strikyflo avatar voxxit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

opensrs's Issues

undefined method

error

tyler@rww-ubuntu:~/pdxbrain$ ruby new_dns.rb
/usr/lib/ruby/1.8/net/http.rb:1060:in request': undefined methodclosed?' for nil:NilClass (NoMethodError)
from /usr/lib/ruby/1.8/net/http.rb:845:in post' from /usr/lib/ruby/gems/1.8/gems/opensrs-0.1.1/lib/opensrs/server.rb:24:incall'
from new_dns.rb:12

in the file

response = server.call(
:action => "get_balance",
:object => "balance"
)

Blank arrays & hashes when empty variables are passed back

Arrays and hashes that should have blank/null objects in them are completely left out when processed into the Ruby object by the OpenSRS gem.

Getting this back from OpenSRS:

[item key="attributes"]
[dt_assoc]
[item key="forwarding_email"/]
[/dt_assoc]
[/item]

Results in "attributes" not even existing in the result hash in Ruby. Currently trying to find where in the XML processing this is happening, but if you have any ideas Voxxit I'd like to hear it.

This seems like something that should be easily worked around in Ruby, but trust me when I say that we can't work around this the way we're using the resulting data. :)

EOFError: end of file reached

Getting this issue on some, not all, HTTPS calls to OpenSRS

System info
Debian GNU/Linux 6.0 \n \l
OpenSSL 0.9.8o 01 Jun 2010
ruby 1.9.3p194 (2012-04-20) [x86_64-linux]
OpenSRS Gem 0.3.3

Note the gem paths in the trace say 1.9.1 but its actually 1.9.3.

/usr/lib/ruby/1.9.1/openssl/buffering.rb:174:in `sysread_nonblock'

/usr/lib/ruby/1.9.1/openssl/buffering.rb:174:in `read_nonblock'

/usr/lib/ruby/1.9.1/net/protocol.rb:141:in `rbuf_fill'

/usr/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'

/usr/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'

/usr/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line'

/usr/lib/ruby/1.9.1/net/http.rb:2551:in `read_new'

/usr/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request'

/usr/lib/ruby/1.9.1/net/http.rb:1316:in `catch'

/usr/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request'

/usr/lib/ruby/1.9.1/net/http.rb:1293:in `request'

[GEM_ROOT]/gems/rest-client-1.6.7/lib/restclient/net_http_ext.rb:51:in `request'

[GEM_ROOT]/gems/newrelic_rpm-3.5.3.25/lib/new_relic/agent/instrumentation/net.rb:22:in `block in request_with_newrelic_trace'

[GEM_ROOT]/gems/newrelic_rpm-3.5.3.25/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'

[GEM_ROOT]/gems/newrelic_rpm-3.5.3.25/lib/new_relic/agent/instrumentation/net.rb:21:in `request_with_newrelic_trace'

/usr/lib/ruby/1.9.1/net/http.rb:1286:in `block in request'

/usr/lib/ruby/1.9.1/net/http.rb:745:in `start'

/usr/lib/ruby/1.9.1/net/http.rb:1284:in `request'

[GEM_ROOT]/gems/rest-client-1.6.7/lib/restclient/net_http_ext.rb:51:in `request'

[GEM_ROOT]/gems/newrelic_rpm-3.5.3.25/lib/new_relic/agent/instrumentation/net.rb:22:in `block in request_with_newrelic_trace'

[GEM_ROOT]/gems/newrelic_rpm-3.5.3.25/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'

[GEM_ROOT]/gems/newrelic_rpm-3.5.3.25/lib/new_relic/agent/instrumentation/net.rb:21:in `request_with_newrelic_trace'

/usr/lib/ruby/1.9.1/net/http.rb:1307:in `send_entity'

/usr/lib/ruby/1.9.1/net/http.rb:1096:in `post'

[GEM_ROOT]/gems/glennr_opensrs-0.3.3/lib/opensrs/server.rb:26:in `call'
...

Looking around the interwebs, I'm finding examples saying Net::HTTP on ruby 1.9.3-p194 has 'problems' ie.

sferik/twitter-ruby#354

And that switching to Typhoeus (e.g. via Faraday) is the solution, however I'd like to find a more practical workaround if possible.

libxml-ruby 1.1.4 problems on 64-bit machines

Hi-
So we ran across a problem today trying to deploy an app that uses this gem - libxml-ruby 1.1.4 apparently has some problems on 64-bit machines (see here). You might want to make a note about this, and/or restrict the dependency to be > 1.0.0, <= 1.1.4. I assume this is something they have fixed in 2.x... Thanks!

-Aidan

items with key 0,1,2

Hi
I am getting this response error "response_text"=>"List of nameservers is not provided"
I ma trying to call advanced_update_nameservers api using this code
@server.call(
protocol: "XCP",
action: "advanced_update_nameservers",
object: "DOMAIN",
domain: domain,
attributes:{
add_ns: [
0=>"ns1.systemdns.com",1=>"ns2.systemdns.com",2=>"ns3.systemdns.com"
],
op_type: "assign"
}
)

Documented XML for calling this api method is given below

<OPS_envelope>

0.9 XCP advanced_update_nameservers domain 781236777:3352 ns1.example.com ns2.example.com ns3.example.com ns4.example.com assign

Waiting for your response and help

Thanks

Net::HTTPBadResponse: wrong status line

Hi there,

I tried to use your opensrs gem. When I tried to use get_balance function and lookup domain availability, I found this error:

Net::HTTPBadResponse: wrong status line: "<?xml version='1.0' encoding=\"UTF-8\" standalone=\"no\" ?>"
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2022:in `read_status_line'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2009:in `read_new'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:1050:in `request'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:1037:in `request'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:543:in `start'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:1035:in `request'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:845:in `post'
from /Library/Ruby/Gems/1.8/gems/opensrs-0.1.1/lib/opensrs/server.rb:24:in `call'
from (irb):55

It happens to every request. I tried this in Ruby 1.9.1 and 1.9.2 with the same result.

Can you help me to debug this problem? Thank you very much.

Requires libxml-ruby 1.0.0 specifically

Trying to install the opensrs gem on a Win32 system is a nightmare due to the libxml-ruby requirement. One must install libxml-ruby 1.0.0 specifically, then install opensrs, uninstall libxml-ruby, then install libxml-ruby 1.1.4, copy a few files to Ruby's /bin directory from the libxml gem's directory, and only then can opensrs be used.

It's such a wrinkle that I simply have users install opensrs 0.2.1, which doesn't have any difficulties installing on Win32 installs.

Tested with the latest version of rubygems on Ruby 1.9.2 p180 32-bit RubyInstaller on Windows 7 64-bit.

Server.call got error

I tried to use opensrs gem. When I use server.call I got an error stated: HTTP request path is empty. Is there something wrong?

LibXML::XML::Error during name_suggest

I get the following when calling OpenSRS's name_suggest API call:

LibXML::XML::Error: LibXML::XML::Error.
from /var/lib/gems/1.8/gems/opensrs-0.2.0/lib/opensrs/xml.rb:105:in <<' from /var/lib/gems/1.8/gems/opensrs-0.2.0/lib/opensrs/xml.rb:105:inencode_dt_assoc'
from /var/lib/gems/1.8/gems/opensrs-0.2.0/lib/opensrs/xml.rb:102:in each' from /var/lib/gems/1.8/gems/opensrs-0.2.0/lib/opensrs/xml.rb:102:inencode_dt_assoc'
from /var/lib/gems/1.8/gems/opensrs-0.2.0/lib/opensrs/xml.rb:71:in encode_data' from /var/lib/gems/1.8/gems/opensrs-0.2.0/lib/opensrs/xml.rb:105:inencode_dt_assoc'
from /var/lib/gems/1.8/gems/opensrs-0.2.0/lib/opensrs/xml.rb:102:in each' from /var/lib/gems/1.8/gems/opensrs-0.2.0/lib/opensrs/xml.rb:102:inencode_dt_assoc'
from /var/lib/gems/1.8/gems/opensrs-0.2.0/lib/opensrs/xml.rb:71:in encode_data' from /var/lib/gems/1.8/gems/opensrs-0.2.0/lib/opensrs/xml.rb:18:inbuild'
from /var/lib/gems/1.8/gems/opensrs-0.2.0/lib/opensrs/server.rb:22:in `call'

OpenSRS::Response#success?

Hi,

I was wondering how come the success? method on the OpenSRS::Response returns true when the is_success attribute is not set on the response?

I would expect that the absence of this attribute is more likely a sign of failure or problem than a sign of success. Any thoughts?

Crashes webrick on subsequent request

Hi Josh,

First, many thanks for the gem.

On next request, after completing a request that involves using opensrs, it crashes webrick with:

ruby(44044,0x106687000) malloc: *** error for object 0x1062affb0: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Abort trap

I am using Rails 3.0.6 on Snow Leopard.

Guess its related to libxml since it works fine with Nokogiri. I am in the process of adding nokogiri support to your gem as I am using nokogiri for other stuff in my project and it can be the case for others as well. I will send a pull request once thats done.

Thanks

Nas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.