Giter Site home page Giter Site logo

ripe-db's Introduction

RIPE for Ruby

This is a Ruby client for the RIPE Database service. It can be used by any LIR to view & make changes to their RIPE database objects.

Installation

The library is distributed using RubyGems.

gem 'ripe-db', '~> 1.0'

Usage

Usage of the library is designed to be simple and support managing of all types of objects supported by the RIPE database. At present, it doesn't support additional services like searching, abuse contacts, meta data or geolocation.

Getting started

require 'ripe/client'

# Initialize a new instance of the client. This accepts the mode and your maintainer
# password. The password is only required if you wish to make changes to the database.
ripe = RIPE::Client.new(:live, 'helloworld')

Looking up objects

# Lookup an object by providing the type of object and the primary key.
object = ripe.find(:person, 'AC23456-RIPE')

# Read attributes from the object. This will return an array of attributes because one
# attribute can have multiple values.
object['person'].name   #=> 'person'
object['person'].each do |attribute|
  attribute.value                  #=> 'Adam Cooke'
  # Some attributes link to other objects. You can access the referenced object
  # using the referenced_object method on the attribute. This will return a new
  # instance of an Object.
  attribute.referenced_object
end

# Get the link to the object
object.link             #=> 'http://rest.db.ripe.net/ripe/person/AC23456-RIPE'

# Get the primary key for an object
object.primary_key      #=> 'AC23456-RIPE'

Creating a new object

# Create your new object lcass
object = ripe.new(:person)
# Set all the attibutes you need to. You can pass an array to set multiple
# values for the same attribute.
object['person'] = 'Adam Cooke'
object['address'] = ['Unit 9 Winchester Place', 'North Street', 'United Kingdom']
object['phone'] = '+44 1202 901 222'
object['mnt-by'] = 'ATECHMEDIA-MNT'
object['source'] = 'RIPE'
begin
  # Make the request to create the object. If this doesn't raise an exception,
  # the object has been added successfully.
  object.create
  object.new?            #=> false
  object.link            # => "http://rest.db.ripe.net/..."
rescue RIPE::ValidationError => exception
  exception.errors.each do |error|
    error.text           #=> Text about the error
    error.severity       #=> The severity of the error
    error.attribute      #=> Details of the attribute that the error relates to (if applicable)
  end
end

Updating an existing object

# Find the object you wish to update
object = ripe.find(:person, 'AC23456-RIPE')
# Update the attribute you wish to change
object['phone'] = '+441234123123'
# Make the request to update the object. As with create, you should keep an eye out
# for RIPE::ValidationError exceptions and handle them appropriately.
object.update

Deleting an object

# Find the object you wish to update
object = ripe.find(:person, 'AC23456-RIPE')
# Delete the object. This will return true if successful or an exception will be
# raised. As with creations and deletions, you may receive a ValidationError if
# an object cannot be deleted.
object.delete
``

ripe-db's People

Contributors

adamcooke avatar lewiseason 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.