Git Product home page Git Product logo

etre-client-ruby's Introduction

Build Status

Description

etre-client is a client gem for Etre.

Installation

etre-client is hosted on rubygems.org. To install it

  1. Add "etre-client" to your Gemfile
  2. Run "bundle install"

Alternatively, you can just "gem install etre-client".

Usage

Require the gem

require 'etre-client'

Create a new client

# Create a standard client.
e = Etre::Client.new(entity_type: "node", url: "http://127.0.0.1:8080")

# Create a client with advanced HTTP options. These are passed down to the rest-client within the Etre Client.
# See https://github.com/rest-client/rest-client#passing-advanced-options for more details.
options = {
  :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("path_to_ssl_cert")),
  :ssl_client_key  => OpenSSL::PKey::RSA.new(File.read("path_to_ssl_key")),
  :ssl_ca_file     => "path_to_ssl_ca",
  :verify_ssl      => OpenSSL::SSL::VERIFY_PEER,
  :cookies         => {:foo => "bar"},
}
e = Etre::Client.new(entity_type: "node", url: "http://127.0.0.1:8080", options: options)

Insert entities

entities = [{"foo" => "bar"}, {"foo" => "abc"}, {"l1" => "a", "l2" => "b"}]
e.insert(entities)
=> [{"id"=>"59f90caadd1b176f02eddcd8", "uri"=>"127.0.0.1:8080/api/v1/entity/59f90caadd1b176f02eddcd8"}, {"id"=>"59f90caadd1b176f02eddcda", "uri"=>"127.0.0.1:8080/api/v1/entity/59f90caadd1b176f02eddcda"}, {"id"=>"59f90e3fdd1b176f02eddce5", "uri"=>"127.0.0.1:8080/api/v1/entity/59f90e3fdd1b176f02eddce5"}]

Read entities

query = "foo=bar"
e.query(query)
=> [{"_id"=>"59f90caadd1b176f02eddcd8", "_rev"=>0, "_type"=>"node", "foo"=>"bar"}]

Update entities

query = "foo=bar"
patch = {"foo" => "newbar"}
e.update(query, patch)
=> [{"id"=>"59f90caadd1b176f02eddcd8", "uri"=>"127.0.0.1:8080/api/v1/entity/59f90caadd1b176f02eddcd8", "diff"=>{"_id"=>"59f90caadd1b176f02eddcd8", "_rev"=>0, "_type"=>"node", "foo"=>"bar"}}]

Update a single entity

id = "59f90caadd1b176f02eddcda"
patch = {"foo" => "slug"}
e.update_one(id, patch)
=> {"id"=>"59f90caadd1b176f02eddcda", "uri"=>"127.0.0.1:8080/api/v1/entity/59f90caadd1b176f02eddcda", "diff"=>{"_id"=>"59f90caadd1b176f02eddcda", "_rev"=>0, "_type"=>"node", "foo"=>"abc"}}

Delete entities

query = "foo=slug"
e.delete(query)
=> [{"id"=>"59f90caadd1b176f02eddcda", "uri"=>"127.0.0.1:8080/api/v1/entity/59f90caadd1b176f02eddcda", "diff"=>{"_id"=>"59f90caadd1b176f02eddcda", "_rev"=>1, "_type"=>"node", "foo"=>"slug"}}]

Delete a single entity

id = "59f90caadd1b176f02eddcd8"
e.delete_one(id)
=> {"id"=>"59f90caadd1b176f02eddcd8", "uri"=>"127.0.0.1:8080/api/v1/entity/59f90caadd1b176f02eddcd8", "diff"=>{"_id"=>"59f90caadd1b176f02eddcd8", "_rev"=>1, "_type"=>"node", "foo"=>"newbar"}}

List the labels for an entity

id = "59f90e3fdd1b176f02eddce5"
e.labels(id)
=> ["f1", "f2"]

Delete the label on an entity

id = "59f90e3fdd1b176f02eddce5"
label = "l1"
e.delete_label(id)
=> {"id"=>"59f90e3fdd1b176f02eddce5", "uri"=>"127.0.0.1:8080/api/v1/entity/59f90e3fdd1b176f02eddce5", "diff"=>{"_id"=>"59f90e3fdd1b176f02eddce5", "_rev"=>0, "_type"=>"node", "l1"=>"a", "l2"=>"b"}}

Development

Run the tests

bundle exec rake spec

Publish a new version of the gem:

  1. Bump the version in lib/etre-client/version.rb
  2. Build the gem with gem build etre-client.gemspec
  3. Publish the new gem with gem push etre-client-#{GEM_VERSION}.gem

License

Copyright (c) 2017 Square Inc. Distributed under the Apache 2.0 License. See LICENSE file for further details.

etre-client-ruby's People

Contributors

cuzelac avatar michaelfinch avatar nicolasleger 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.