GithubHelp home page GithubHelp logo

qpc-github / opensrs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shopify/opensrs

1.0 2.0 1.0 140 KB

Provides support to utilise the OpenSRS API with Ruby/Rails.

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

License: MIT License

Shell 0.42% Ruby 99.58%

opensrs's Introduction

OpenSRS

![Gitter](https://badges.gitter.im/Join Chat.svg)

Build Status Code Climate 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 >= 1.9.2 or >= 2.0.0 or >= 2.1.2

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

Usage

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

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

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.

Since OpenSRS only allows up to 5 IPs to be whitelisted, you may wish to use a proxy. OpenSRS::Server uses Net::HTTP, so you can configure an unauthenticated proxy with the http_proxy environment variable. If the proxy requires authentication, you must supply it explicitly:

server = OpenSRS::Server.new(
  server:   "https://rr-n1-tor.opensrs.net:55443/",
  username: "testing",
  password: "53cr3t",
  key:      "c633be3170c7fb3fb29e2f99b84be2410...",
  proxy:    "http://user:[email protected]:8080",
)

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,
  sanitize_logs: false
)

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.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)

Copyright

Copyright (c) 2010-2016 Joshua Delsman.

Distributed under the MIT license. See LICENSE for details.

Bitdeli Badge

opensrs's People

Contributors

jsaubry avatar voxxit avatar byroot avatar strikyflo avatar afeld avatar jstorimer avatar casperisfine avatar miazbikowski avatar rtlechow avatar rorymckinley avatar glennr avatar apfritts avatar bitdeli-chef avatar cjoudrey avatar fw42 avatar pbevin avatar gitter-badger avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.