Description
etre-client is a client gem for Etre.
Installation
etre-client is hosted on rubygems.org. To install it
- Add "etre-client" to your Gemfile
- 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.
= {
: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: )
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:
- Bump the version in lib/etre-client/version.rb
- Build the gem with
gem build etre-client.gemspec
- 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.