datomic-client 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,8 @@
1
+ ## 0.3.0
2
+ * Update to work for 0.8.3520 - makes breaking changes for previous APIs
3
+ * Remove monitor method
4
+ * Add Response#args
5
+
1
6
  ## 0.2.0
2
7
  * Added EDN support
3
8
  * 2 pending specs fixed
data/README.md CHANGED
@@ -45,7 +45,6 @@ $ irb -rdatomic/client
45
45
  >> datomic.datoms(dbname, 'aevt')
46
46
  >> datomic.range(dbname, :a => "db/ident")
47
47
  >> datomic.entity(dbname, 1)
48
- >> datomic.monitor(dbname)
49
48
  >> datomic.events(dbname) {|r| puts "Received: #{r.inspect}" }
50
49
  ```
51
50
 
@@ -60,11 +59,6 @@ Please report them [on github](http://github.com/cldwalker/datomic-client/issues
60
59
  * @crnixon for adding edn support
61
60
  * @flyingmachine for starting this with me
62
61
 
63
- ##Todo
64
-
65
- * Allow entity endpoint to take an e param
66
- * Fix pending specs
67
-
68
62
  ## Links
69
63
 
70
64
  * [API documentation](http://docs.datomic.com/rest.html) - Actual documentation now resides on root
@@ -16,44 +16,52 @@ module Datomic
16
16
  end
17
17
 
18
18
  def create_database(dbname)
19
- RestClient.put db_url(dbname), {}, &HANDLE_RESPONSE
19
+ RestClient.post root_url('data', @storage) + "/", {"db-name" => dbname},
20
+ :content_type => 'application/x-www-form-urlencoded', &HANDLE_RESPONSE
20
21
  end
21
22
 
22
- def database_info(dbname)
23
- get db_url(dbname)
23
+ # Options:
24
+ # * :t - Specifies version/time of db. Defaults to latest version
25
+ def database_info(dbname, options = {})
26
+ version = options.fetch(:t, '-')
27
+ get db_url(dbname, version) + "/", :Accept => 'application/edn'
24
28
  end
25
29
 
26
30
  # Data can be a ruby data structure or a string representing clojure data
27
31
  def transact(dbname, data)
28
32
  data = transmute_data(data)
29
- RestClient.post(db_url(dbname), data, :content_type => 'application/x-edn', &HANDLE_RESPONSE)
33
+ RestClient.post(db_url(dbname) + "/", {"tx-data" => data},
34
+ :Accept => 'application/edn', &HANDLE_RESPONSE)
30
35
  end
31
36
 
32
- # Index only has certain valid types. See datomic's docs for details.
33
- def datoms(dbname, index, params = {})
34
- get db_url(dbname, "datoms/#{index}"), :params => params
35
- end
36
-
37
- def range(dbname, params = {})
38
- get db_url(dbname, 'range'), :params => params
37
+ # This endpoint hits both datoms and index-range APIs.
38
+ # params take any param in addition to following options:
39
+ #
40
+ # Options:
41
+ # * :t - Specifies version/time of db. Defaults to latest version
42
+ def datoms(dbname, params = {})
43
+ version = params.fetch(:t, '-')
44
+ get db_url(dbname, version, "datoms"), params
39
45
  end
40
46
 
47
+ # params take any param in addition to following options:
48
+ #
49
+ # Options:
50
+ # * :t - Specifies version/time of db. Defaults to latest version
41
51
  def entity(dbname, id, params = {})
42
- get db_url(dbname, 'entity', id), :params => params
52
+ version = params.fetch(:t, '-')
53
+ get db_url(dbname, version, 'entity'), params.merge(:e => id)
43
54
  end
44
55
 
45
56
  # Query can be a ruby data structure or a string representing clojure data
46
57
  def query(dbname, query, params = {})
47
58
  query = transmute_data(query)
48
59
  args = [{:"db/alias" => [@storage, dbname].join('/')}].to_edn
49
- get root_url("api/query"), :params => params.merge(:q => query, :args => args)
50
- end
51
-
52
- def monitor(dbname)
53
- get root_url('monitor', @storage, dbname)
60
+ get root_url("api/query"), params.merge(:q => query, :args => args)
54
61
  end
55
62
 
56
- # Given block is called with Net::HTTPOK response from event
63
+ # Streams events. For each event, given block is called with Net::HTTP
64
+ # response from event
57
65
  def events(dbname, &block)
58
66
  # can't use RestClient.get b/c of :block_response
59
67
  RestClient::Request.execute(:method => :get,
@@ -64,8 +72,9 @@ module Datomic
64
72
 
65
73
  private
66
74
 
67
- def get(*args)
68
- RestClient.get(*args, &HANDLE_RESPONSE)
75
+ def get(url, params = {})
76
+ RestClient.get(url, :params => params, :Accept => 'application/edn',
77
+ &HANDLE_RESPONSE)
69
78
  end
70
79
 
71
80
  def root_url(*parts)
@@ -73,7 +82,7 @@ module Datomic
73
82
  end
74
83
 
75
84
  def db_url(dbname, *parts)
76
- root_url 'db', @storage, dbname, *parts
85
+ root_url 'data', @storage, dbname, *parts
77
86
  end
78
87
 
79
88
  def transmute_data(data)
@@ -5,6 +5,8 @@ module Datomic
5
5
  attr_reader :body
6
6
  # Underlying Net:HTTP response
7
7
  attr_reader :net_http
8
+ # Args used to make request
9
+ attr_reader :args
8
10
 
9
11
  def initialize(body, response, request)
10
12
  @body = body
@@ -1,5 +1,5 @@
1
1
  module Datomic
2
2
  class Client
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -29,8 +29,6 @@ describe Datomic::Client do
29
29
  it "returns 200 for existing database" do
30
30
  resp = client.database_info('test-database_info')
31
31
  resp.code.should == 200
32
- resp.data.should have_key(:"basis-t")
33
- resp.data.should have_key(:"db/alias")
34
32
  end
35
33
 
36
34
  it "returns database info for existing database" do
@@ -39,8 +37,13 @@ describe Datomic::Client do
39
37
  resp.data.should have_key(:"db/alias")
40
38
  end
41
39
 
40
+ it "returns 200 for different version" do
41
+ resp = client.database_info('test-database_info', :t => 1)
42
+ resp.code.should == 200
43
+ resp.args[:url].should match(%r{/1/$})
44
+ end
45
+
42
46
  it "returns 404 for nonexistent database" do
43
- pending "docs say 404 but seeing 500"
44
47
  resp = client.database_info('zxvf')
45
48
  resp.code.should == 404
46
49
  end
@@ -51,14 +54,14 @@ describe Datomic::Client do
51
54
 
52
55
  it "returns correct response with string of data" do
53
56
  resp = client.transact('test-transact', schema)
54
- resp.code.should == 200
57
+ resp.code.should == 201
55
58
  resp.data.should be_a(Hash)
56
59
  resp.data.keys.sort.should == [:"db-after", :"db-before", :tempids, :"tx-data"]
57
60
  end
58
61
 
59
62
  it "returns correct response with array of data" do
60
63
  resp = client.transact('test-transact', [[:"db/add", 1, :"community/name", "Some Community"]])
61
- resp.code.should == 200
64
+ resp.code.should == 201
62
65
  resp.data.should be_a(Hash)
63
66
  resp.data.keys.sort.should == [:"db-after", :"db-before", :tempids, :"tx-data"]
64
67
  end
@@ -69,37 +72,33 @@ describe Datomic::Client do
69
72
 
70
73
  %w{eavt aevt avet vaet}.each do |index|
71
74
  it "returns correct response for index '#{index}'" do
72
- pending "possible bug" if index == 'vaet'
73
- resp = client.datoms('test-datoms', index)
75
+ resp = client.datoms('test-datoms', :index => index)
74
76
  resp.code.should == 200
75
77
  resp.data.should be_a(Array)
76
78
  end
77
79
  end
78
80
 
79
81
  it "returns 500 for invalid index" do
80
- resp = client.datoms('test-datoms', 'blarg')
82
+ resp = client.datoms('test-datoms', :index => 'blarg')
81
83
  resp.code.should == 500
82
84
  end
83
85
 
84
86
  it "returns correct response with limit param" do
85
- resp = client.datoms('test-datoms', "eavt", :limit => 0)
87
+ resp = client.datoms('test-datoms', :index => "eavt", :limit => 0)
86
88
  resp.code.should == 200
87
89
  resp.data.should == []
88
90
  end
89
- end
90
91
 
91
- describe "#range" do
92
- before { client.create_database('test-range') }
93
-
94
- it "returns correct response with required attribute" do
95
- resp = client.range('test-range', :a => "db/ident")
92
+ it "returns correct response for range usage" do
93
+ resp = client.datoms('test-datoms', :index => 'avet', :a => 'db/ident')
96
94
  resp.code.should == 200
97
95
  resp.data.should be_a(Array)
98
96
  end
99
97
 
100
- it "returns 400 without required attribute" do
101
- resp = client.range('test-range')
102
- resp.code.should == 400
98
+ it "returns correct response for different version" do
99
+ resp = client.datoms('test-datoms', :t => 2)
100
+ resp.code.should == 200
101
+ resp.args[:url].should match(%r{2/datoms$})
103
102
  end
104
103
  end
105
104
 
@@ -117,6 +116,12 @@ describe Datomic::Client do
117
116
  resp.code.should == 200
118
117
  resp.data.should be_a(Hash)
119
118
  end
119
+
120
+ it "returns correct response for different version" do
121
+ resp = client.entity('test-entity', 1, :t => 2)
122
+ resp.code.should == 200
123
+ resp.args[:url].should match(%r{2/entity$})
124
+ end
120
125
  end
121
126
 
122
127
  describe "#query" do
@@ -150,16 +155,6 @@ describe Datomic::Client do
150
155
 
151
156
  end
152
157
 
153
- describe "#monitor" do
154
- before { client.create_database('test-monitor') }
155
-
156
- it "returns a correct response" do
157
- resp = client.monitor('test-monitor')
158
- resp.code.should == 200
159
- resp.body.should match(/\<script\>/)
160
- end
161
- end
162
-
163
158
  describe "#events" do
164
159
  before { client.create_database('test-events') }
165
160
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datomic-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  segments:
126
126
  - 0
127
- hash: -1359618081440399035
127
+ hash: 2191169239501310737
128
128
  required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  segments:
135
135
  - 0
136
- hash: -1359618081440399035
136
+ hash: 2191169239501310737
137
137
  requirements: []
138
138
  rubyforge_project:
139
139
  rubygems_version: 1.8.24