Sha256: 1bc8b184355b092f89b7d973193b04372ea43a1447cb530fd2863b780fdc6093
Contents?: true
Size: 935 Bytes
Versions: 6
Compression:
Stored size: 935 Bytes
Contents
# # Sequencer via HTTP API # module ActiveRecord::Turntable class Sequencer class Api < Sequencer API_ENDPOINT = "/sequences/".freeze NEXT_VALUE_ENDPOINT = "/new".freeze def initialize(options = {}) require "httpclient" @options = options @host = @options[:api_host] @port = @options[:api_port] @client = HTTPClient.new end def next_sequence_value(sequence_name) res = @client.get_content("http://#{@host}:#{@port}#{API_ENDPOINT}#{sequence_name}#{NEXT_VALUE_ENDPOINT}") new_id = res.to_i raise SequenceNotFoundError if new_id.zero? new_id end def current_sequence_value(sequence_name) res = @client.get_content("http://#{@host}:#{@port}#{API_ENDPOINT}#{sequence_name}") current_id = res.to_i raise SequenceNotFoundError if current_id.zero? current_id end end end end
Version data entries
6 entries across 6 versions & 1 rubygems