Skip to content

Instantly share code, notes, and snippets.

@akjetma
Last active December 25, 2015 18:19
Show Gist options
  • Save akjetma/7020123 to your computer and use it in GitHub Desktop.
Save akjetma/7020123 to your computer and use it in GitHub Desktop.
little ruby wrapper for orchestrate.io API v0 beta
source 'https://rubygems.org'
gem 'rest-client'
gem 'json'
gem 'pry'
require 'json'
require 'rest-client'
class Orchestrate
@base_url = "https://#{ ORCHESTRATE_API_KEY }@api.orchestrate.io/v0"
# -----key/value-----
def self.kv_put(collection, key, value)
url = "#{ @base_url }/#{ collection }/#{ key }"
RestClient.put(url, value.to_json, :content_type => 'application/json')
end
def self.kv_get(collection, key)
url = "#{ @base_url }/#{ collection }/#{ key }"
response = RestClient.get(url, :accept => 'application/json')
return JSON.parse(response)
end
# -----search-----
def self.search(collection, field, value)
url = "#{ @base_url }/#{ collection }/?query=#{ field }:#{ value }"
response = RestClient.get(url, :accept => 'application/json')
return JSON.parse(response)
end
# -----graph-----
def self.graph_put(src_collection, src_key, relation, tgt_collection, tgt_key)
url = "#{ @base_url }/#{ src_collection }/#{ src_key }/relation/#{ relation }/#{ tgt_collection }/#{ tgt_key }"
RestClient.put(url, nil.to_json, :content_type => 'application/json')
end
def self.graph_get(collection, key, *relations)
traversal = relations.join("/")
url = "#{ @base_url }/#{ collection }/#{ key }/relations/#{ traversal }"
response = RestClient.get(url, :accept => 'application/json')
return JSON.parse(response)
end
# -----events-----
def self.event_put(collection, key, type, data, timestamp=nil)
url = "#{ @base_url }/#{ collection }/#{ key }/events/#{ type }?timestamp=#{ time_stamp }"
RestClient.put(url, value.to_json, :content_type => 'application/json')
end
def self.event_get(collection, key, type, t_start=nil, t_end=nil)
url = "#{ @base_url }/#{ collection }/#{ key }/events/#{ type }?start=#{ t_start }&end=#{ t_end }"
response = RestClient.get(url, :accept => 'application/json')
return JSON.parse(response)
end
end
ARGV.empty? ? abort("Please enter your Orchestrate API key as an argument") : ORCHESTRATE_API_KEY = ARGV.shift
require_relative 'orchestral'
require 'pry'
pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment