0.0
No release in over 3 years
Low commit activity in last 3 years
Client gem for interacting with Etre
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 12.2.0, ~> 12.2
~> 3.0

Runtime

>= 0
 Project Readme

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.