diff --git a/.gitignore b/.gitignore index 80f3713..5de0504 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ Gemfile.lock pkg .bundle +*.gem + diff --git a/CHANGELOG.md b/CHANGELOG.md index f7d643e..3cad295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.0 +* Make restclient gem options available (e.g. for timeouts) +* weaken the version restrictinons in the gem file. + ## 0.4.1 * Make #db_alias available * Upgrade edn diff --git a/README.md b/README.md index 3f4d7f5..bee6b08 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,16 @@ $ irb -rdatomic/client >> datomic.events(dbname) {|r| puts "Received: #{r.inspect}" } ``` +## Additional Options + +This gem uses the [rest-client gem](https://rubygems.org/gems/rest-client/versions/1.8.0) for its +network connection. When creating a client, you can add a hash of options which will be +passed to the underlying gem. These can be used to extend timeouts etc. e.g. +```ruby +>> datomic = Datomic::Client.new 'http://localhost:9000', 'socrates', read_timeout: 600, open_timeout: 10 +``` + + ## Issues Please report them [on github](http://github.com/cldwalker/datomic-client/issues). diff --git a/datomic-client.gemspec b/datomic-client.gemspec index c2511a7..1b2c43f 100644 --- a/datomic-client.gemspec +++ b/datomic-client.gemspec @@ -18,6 +18,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'bundler' s.add_development_dependency 'rspec', '~> 2.11' s.add_development_dependency 'rake', '~> 0.9.2.2' - s.add_dependency 'rest-client', '~> 1.6.7' + # Breaking changes in rest-client 1.8.0 for us + s.add_dependency 'rest-client', '~> 1.6.7' s.add_dependency 'edn', '~> 1.0.0' end diff --git a/lib/datomic/client.rb b/lib/datomic/client.rb index 3b8fd2d..f09b227 100644 --- a/lib/datomic/client.rb +++ b/lib/datomic/client.rb @@ -9,12 +9,16 @@ class Client Response.new body, response, request end - def initialize(url, storage = nil) + # rest_options is anything acceptable sa an argument to RestClient::Request.new() + def initialize(url, storage = nil, rest_options = {}) @url = url @storage = storage + @rest_options = rest_options end def create_database(dbname) + #RestClient.post root_url('data', @storage) + "/", {"db-name" => dbname}, + # :content_type => 'application/x-www-form-urlencoded', &HANDLE_RESPONSE RestClient.post root_url('data', @storage) + "/", {"db-name" => dbname}, :content_type => 'application/x-www-form-urlencoded', &HANDLE_RESPONSE end @@ -29,10 +33,13 @@ def database_info(dbname, options = {}) # Data can be a ruby data structure or a string representing clojure data def transact(dbname, data) data = transmute_data(data) - RestClient.post(db_url(dbname) + "/", {"tx-data" => data}, + #RestClient.post(db_url(dbname) + "/", {"tx-data" => data}, + # :Accept => 'application/edn', &HANDLE_RESPONSE) + post(db_url(dbname) + "/", {"tx-data" => data}, :Accept => 'application/edn', &HANDLE_RESPONSE) end + # This endpoint hits both datoms and index-range APIs. # params take any param in addition to following options: # @@ -66,7 +73,7 @@ def query(query, args_or_dbname, params = {}) # response from event def events(dbname, &block) # can't use RestClient.get b/c of :block_response - RestClient::Request.execute(:method => :get, + execute(:method => :get, :url => root_url('events', @storage, dbname), :headers => {:accept => "text/event-stream"}, :block_response => block, &HANDLE_RESPONSE) @@ -76,13 +83,26 @@ def db_alias(dbname) {:"db/alias" => "#@storage/#{dbname}"} end - private + private + # Execute a Rest operation with extra defaults + def execute( args, &block ) + RestClient::Request.execute(@rest_options.merge(args), &block) + end def get(url, params = {}) - RestClient.get(url, :params => params, :Accept => 'application/edn', - &HANDLE_RESPONSE) + #RestClient.get(url, :params => params, :Accept => 'application/edn', + # &HANDLE_RESPONSE) + execute(:method => :get, + :url => url, + headers: {:params => params, :Accept => 'application/edn'}, + &HANDLE_RESPONSE) end + def post(url, payload, headers={}, &block ) + execute(:method => :post, :url => url, :payload => payload, :headers => headers, &block) + end + + def root_url(*parts) [@url].concat(parts).join('/') end diff --git a/lib/datomic/client/version.rb b/lib/datomic/client/version.rb index 64ce490..4afb8ad 100644 --- a/lib/datomic/client/version.rb +++ b/lib/datomic/client/version.rb @@ -1,5 +1,5 @@ module Datomic class Client - VERSION = '0.4.1' + VERSION = '0.5.0' end end