Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
Gemfile.lock
pkg
.bundle
*.gem

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
3 changes: 2 additions & 1 deletion datomic-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 26 additions & 6 deletions lib/datomic/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
#
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/datomic/client/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Datomic
class Client
VERSION = '0.4.1'
VERSION = '0.5.0'
end
end