class SisRuby::Client
Constants
- DEFAULT_API_VERSION
Attributes
api_version[R]
auth_token[R]
base_url[R]
entity_endpoints[R]
hiera[R]
hooks[R]
hosts[R]
schemas[R]
Public Class Methods
new(url, options = {})
click to toggle source
@param url the base URL of the service (excluding ”/api/v…”) @param options (can include :version, :auth_token)
# File lib/sis_ruby/client.rb, line 15 def initialize(url, options = {}) @base_url = url @api_version = options[:api_version] || DEFAULT_API_VERSION @auth_token = options[:auth_token] @entity_endpoints = {} @hooks = create_endpoint('hooks', 'name') @schemas = create_endpoint('schemas', 'name') @hiera = create_endpoint('hiera', 'name') end
Public Instance Methods
authenticate(username, password)
click to toggle source
Authenticates the username and password. Get the token by calling client.auth_token. @return self for chaining this method after the constructor
# File lib/sis_ruby/client.rb, line 51 def authenticate(username, password) dest = "#{base_url}/api/v#{api_version}/users/auth_token" options = { userpwd: username + ':' + password, headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } } response = Typhoeus.post(dest, options) unless response.options[:response_code] == 201 raise AuthenticationError.new(response) end @auth_token = JSON.parse(response.response_body)['name'] self end
create_endpoint(endpoint_suffix, id_fieldname = :default)
click to toggle source
# File lib/sis_ruby/client.rb, line 27 def create_endpoint(endpoint_suffix, id_fieldname = :default) Endpoint.new(self, endpoint_suffix, id_fieldname) end
entities(name, id_fieldname = DEFAULT_ID_FIELDNAME)
click to toggle source
# File lib/sis_ruby/client.rb, line 32 def entities(name, id_fieldname = DEFAULT_ID_FIELDNAME) @entity_endpoints[name] ||= create_endpoint("entities/#{name}", id_fieldname) end
schema_for(collection_name)
click to toggle source
Returns the schema for the specified collection_name, or nil if it’s not found.
# File lib/sis_ruby/client.rb, line 43 def schema_for(collection_name) params = Params.new.limit(1).filter('name' => collection_name) schemas.list(params).first end
to_s()
click to toggle source
# File lib/sis_ruby/client.rb, line 67 def to_s self.class.name + ": base_url = #{@base_url}" end
tokens(username)
click to toggle source
# File lib/sis_ruby/client.rb, line 37 def tokens(username) create_endpoint("users/#{username}/tokens", 'name') end