fauna 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,6 @@
1
- v1.1.0. Updates for Fauna 1.1. Remove schema configuration.
1
+ v1.1.1 Remove last bit of ORM-ness.
2
+
3
+ v1.1.0 Updates for Fauna 1.1. Remove schema configuration.
2
4
 
3
5
  v0.2.6 Implement set paging.
4
6
 
data/Manifest CHANGED
@@ -0,0 +1,24 @@
1
+ CHANGELOG
2
+ Gemfile
3
+ LICENSE
4
+ Manifest
5
+ README.md
6
+ Rakefile
7
+ fauna.gemspec
8
+ lib/fauna.rb
9
+ lib/fauna/cache.rb
10
+ lib/fauna/client.rb
11
+ lib/fauna/connection.rb
12
+ lib/fauna/named_resource.rb
13
+ lib/fauna/rails.rb
14
+ lib/fauna/resource.rb
15
+ lib/fauna/set.rb
16
+ lib/fauna/util.rb
17
+ lib/tasks/fauna.rake
18
+ test/class_test.rb
19
+ test/client_test.rb
20
+ test/connection_test.rb
21
+ test/database_test.rb
22
+ test/readme_test.rb
23
+ test/set_test.rb
24
+ test/test_helper.rb
data/fauna.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "fauna"
5
- s.version = "1.1.0"
5
+ s.version = "1.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Fauna, Inc."]
9
- s.date = "2013-07-31"
9
+ s.date = "2013-08-08"
10
10
  s.description = "Official Ruby client for the Fauna API."
11
11
  s.email = ""
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "lib/fauna.rb", "lib/fauna/cache.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/provided_classes.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "lib/fauna/set.rb", "lib/fauna/util.rb", "lib/tasks/fauna.rake"]
13
- s.files = ["CHANGELOG", "Gemfile", "LICENSE", "Manifest", "README.md", "Rakefile", "examples/welcome.rb", "fauna.gemspec", "lib/fauna.rb", "lib/fauna/cache.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/provided_classes.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "lib/fauna/set.rb", "lib/fauna/util.rb", "lib/tasks/fauna.rake", "test/class_test.rb", "test/client_test.rb", "test/connection_test.rb", "test/database_test.rb", "test/readme_test.rb", "test/set_test.rb", "test/test_helper.rb"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "lib/fauna.rb", "lib/fauna/cache.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/named_resource.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "lib/fauna/set.rb", "lib/fauna/util.rb", "lib/tasks/fauna.rake"]
13
+ s.files = ["CHANGELOG", "Gemfile", "LICENSE", "Manifest", "README.md", "Rakefile", "fauna.gemspec", "lib/fauna.rb", "lib/fauna/cache.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/named_resource.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "lib/fauna/set.rb", "lib/fauna/util.rb", "lib/tasks/fauna.rake", "test/class_test.rb", "test/client_test.rb", "test/connection_test.rb", "test/database_test.rb", "test/readme_test.rb", "test/set_test.rb", "test/test_helper.rb"]
14
14
  s.homepage = "http://fauna.github.com/fauna/"
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Fauna", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
data/lib/fauna.rb CHANGED
@@ -20,5 +20,5 @@ require 'fauna/connection'
20
20
  require 'fauna/cache'
21
21
  require 'fauna/client'
22
22
  require 'fauna/resource'
23
+ require 'fauna/named_resource'
23
24
  require 'fauna/set'
24
- require 'fauna/provided_classes'
@@ -33,12 +33,13 @@ module Fauna
33
33
  end
34
34
  end
35
35
 
36
- attr_reader :domain, :scheme
36
+ attr_reader :domain, :scheme, :port, :credentials
37
37
 
38
38
  def initialize(params={})
39
39
  @logger = params[:logger] || nil
40
40
  @domain = params[:domain] || "rest1.fauna.org"
41
41
  @scheme = params[:scheme] || "https"
42
+ @port = params[:port] || 80
42
43
 
43
44
  if ENV["FAUNA_DEBUG"]
44
45
  @logger = Logger.new(STDERR)
@@ -135,7 +136,7 @@ module Fauna
135
136
  end
136
137
 
137
138
  def url(ref)
138
- "#{@scheme}://#{@credentials}@#{@domain}/#{ref}"
139
+ "#{@scheme}://#{@credentials}@#{@domain}:#{@port}/#{ref}"
139
140
  end
140
141
  end
141
142
  end
@@ -0,0 +1,17 @@
1
+ module Fauna
2
+ class NamedResource < Fauna::Resource
3
+ def name
4
+ struct['name']
5
+ end
6
+
7
+ def ref
8
+ super || "#{fauna_class}/#{name}"
9
+ end
10
+
11
+ private
12
+
13
+ def post
14
+ raise Invalid, "Cannot POST to named resource."
15
+ end
16
+ end
17
+ end
@@ -2,9 +2,8 @@ module Fauna
2
2
  class Resource
3
3
  def self.resource_subclass(fauna_class)
4
4
  case fauna_class
5
- when 'databases' then Fauna::Database
6
- when 'classes' then Fauna::Class
7
- when 'keys' then Fauna::Key
5
+ when 'databases' then Fauna::NamedResource
6
+ when 'classes' then Fauna::NamedResource
8
7
  when 'resources' then Fauna::SetPage
9
8
  when 'events' then Fauna::EventsPage
10
9
  else Fauna::Resource
data/test/client_test.rb CHANGED
@@ -19,7 +19,7 @@ class ClientTest < MiniTest::Unit::TestCase
19
19
  user = Fauna::Resource.create("users", @attributes)
20
20
  Fauna::Client.context(@client_connection) do
21
21
  assert_raises(Fauna::Connection::Unauthorized) do
22
- Fauna::Client.get(user.ref)
22
+ instance = Fauna::Resource.create("classes/posts", @attributes)
23
23
  end
24
24
  end
25
25
  end
@@ -34,7 +34,7 @@ class ClientTest < MiniTest::Unit::TestCase
34
34
  @token = Fauna::Client.post("tokens", @attributes)
35
35
  end
36
36
 
37
- Fauna::Client.context(Fauna::Connection.new(:secret => @token['secret'], :domain => @server_connection.domain, :scheme => @server_connection.scheme)) do
37
+ Fauna::Client.context(Fauna::Connection.new(:secret => @token['secret'], :domain => @server_connection.domain, :scheme => @server_connection.scheme, :port => @server_connection.port)) do
38
38
  user = Fauna::Client.get(@token['user'])
39
39
  Fauna::Client.delete(user['ref'])
40
40
  end
@@ -11,7 +11,7 @@ class ConnectionTest < MiniTest::Unit::TestCase
11
11
  end
12
12
 
13
13
  def test_get_with_invalid_key
14
- connection = Fauna::Connection.new(:secret => 'bad_key', :domain => @server_connection.domain, :scheme => @server_connection.scheme)
14
+ connection = Fauna::Connection.new(:secret => 'bad_key', :domain => @server_connection.domain, :scheme => @server_connection.scheme, :port => @server_connection.port)
15
15
  assert_raises(Fauna::Connection::Unauthorized) do
16
16
  connection.get("users/instances")
17
17
  end
@@ -4,7 +4,7 @@ class DatabaseTest < MiniTest::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  super
7
- @model = Fauna::Database.new("ref" => "databases/fauna-ruby-test2")
7
+ @model = Fauna::Resource.new 'databases', :name => 'fauna-ruby-test2'
8
8
  Fauna::Client.context(@root_connection) do
9
9
  @model.save
10
10
  end
@@ -16,15 +16,6 @@ class DatabaseTest < MiniTest::Unit::TestCase
16
16
  end
17
17
  end
18
18
 
19
- def test_find
20
- assert_raises(Fauna::Connection::Unauthorized) do
21
- Fauna::Database.find(@model.ref)
22
- end
23
- Fauna::Client.context(@root_connection) do
24
- assert_equal @model, Fauna::Database.find(@model.ref)
25
- end
26
- end
27
-
28
19
  def test_self
29
20
  database = Fauna::Resource.find('databases/self')
30
21
  assert_equal "databases/fauna-ruby-test", database.ref
data/test/set_test.rb CHANGED
@@ -34,7 +34,7 @@ class SetTest < MiniTest::Unit::TestCase
34
34
  assert_equal 2, page4.refs.size
35
35
  page5 = @posts.page(:size => 2, :after => page4.after)
36
36
  assert_equal 2, page5.refs.size
37
- page6 = @posts.page(:size => 2, :after => page5.refs.first)
37
+ page6 = @posts.page(:size => 2, :after => page5.after)
38
38
  assert_equal 1, page6.refs.size
39
39
  end
40
40
 
data/test/test_helper.rb CHANGED
@@ -7,36 +7,37 @@ require "fauna"
7
7
  require "securerandom"
8
8
  require "mocha/setup"
9
9
 
10
- FAUNA_TEST_ROOTKEY = ENV["FAUNA_TEST_ROOTKEY"]
11
- FAUNA_TEST_DOMAIN = ENV["FAUNA_TEST_DOMAIN"]
12
- FAUNA_TEST_SCHEME = ENV["FAUNA_TEST_SCHEME"]
10
+ FAUNA_ROOTKEY = ENV["FAUNA_ROOTKEY"]
11
+ FAUNA_DOMAIN = ENV["FAUNA_DOMAIN"]
12
+ FAUNA_SCHEME = ENV["FAUNA_SCHEME"]
13
+ FAUNA_PORT = ENV["FAUNA_PORT"]
13
14
 
14
- if !(FAUNA_TEST_ROOTKEY && FAUNA_TEST_DOMAIN && FAUNA_TEST_SCHEME)
15
- raise "FAUNA_TEST_ROOTKEY, FAUNA_TEST_DOMAIN and FAUNA_TEST_SCHEME must be defined in your environment to run tests."
15
+ if !(FAUNA_ROOTKEY && FAUNA_DOMAIN && FAUNA_SCHEME && FAUNA_PORT)
16
+ raise "FAUNA_ROOTKEY, FAUNA_DOMAIN, FAUNA_SCHEME and FAUNA_PORT must be defined in your environment to run tests."
16
17
  end
17
18
 
18
- ROOT_CONNECTION = Fauna::Connection.new(:secret => FAUNA_TEST_ROOTKEY, :domain => FAUNA_TEST_DOMAIN, :scheme => FAUNA_TEST_SCHEME)
19
+ ROOT_CONNECTION = Fauna::Connection.new(:secret => FAUNA_ROOTKEY, :domain => FAUNA_DOMAIN, :scheme => FAUNA_SCHEME, :port => FAUNA_PORT)
19
20
 
20
21
  Fauna::Client.context(ROOT_CONNECTION) do
21
- Fauna::Database.new(:name => "fauna-ruby-test").delete rescue nil
22
- Fauna::Database.create(:name => "fauna-ruby-test")
22
+ Fauna::Resource.new('databases', :name => "fauna-ruby-test").delete rescue nil
23
+ Fauna::Resource.create 'databases', :name => "fauna-ruby-test"
23
24
 
24
- server_key = Fauna::Key.create :database => "databases/fauna-ruby-test", :role => "server"
25
- client_key = Fauna::Key.create :database => "databases/fauna-ruby-test", :role => "client"
25
+ server_key = Fauna::Resource.create 'keys', :database => "databases/fauna-ruby-test", :role => "server"
26
+ client_key = Fauna::Resource.create 'keys', :database => "databases/fauna-ruby-test", :role => "client"
26
27
 
27
- SERVER_CONNECTION = Fauna::Connection.new(:secret => server_key.secret, :domain => FAUNA_TEST_DOMAIN, :scheme => FAUNA_TEST_SCHEME)
28
- CLIENT_CONNECTION = Fauna::Connection.new(:secret => client_key.secret, :domain => FAUNA_TEST_DOMAIN, :scheme => FAUNA_TEST_SCHEME)
28
+ SERVER_CONNECTION = Fauna::Connection.new(:secret => server_key.secret, :domain => FAUNA_DOMAIN, :scheme => FAUNA_SCHEME, :port => FAUNA_PORT)
29
+ CLIENT_CONNECTION = Fauna::Connection.new(:secret => client_key.secret, :domain => FAUNA_DOMAIN, :scheme => FAUNA_SCHEME, :port => FAUNA_PORT)
29
30
  end
30
31
 
31
32
  # fixtures
32
33
 
33
34
  Fauna::Client.context(SERVER_CONNECTION) do
34
- Fauna::Class.create :name => 'pigs'
35
- Fauna::Class.create :name => 'pigkeepers'
36
- Fauna::Class.create :name => 'visions'
37
- Fauna::Class.create :name => 'message_boards'
38
- Fauna::Class.create :name => 'posts'
39
- Fauna::Class.create :name => 'comments'
35
+ Fauna::Resource.create 'classes', :name => 'pigs'
36
+ Fauna::Resource.create 'classes', :name => 'pigkeepers'
37
+ Fauna::Resource.create 'classes', :name => 'visions'
38
+ Fauna::Resource.create 'classes', :name => 'message_boards'
39
+ Fauna::Resource.create 'classes', :name => 'posts'
40
+ Fauna::Resource.create 'classes', :name => 'comments'
40
41
  end
41
42
 
42
43
  # test harness
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fauna
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-31 00:00:00.000000000 Z
12
+ date: 2013-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -103,7 +103,7 @@ extra_rdoc_files:
103
103
  - lib/fauna/cache.rb
104
104
  - lib/fauna/client.rb
105
105
  - lib/fauna/connection.rb
106
- - lib/fauna/provided_classes.rb
106
+ - lib/fauna/named_resource.rb
107
107
  - lib/fauna/rails.rb
108
108
  - lib/fauna/resource.rb
109
109
  - lib/fauna/set.rb
@@ -116,13 +116,12 @@ files:
116
116
  - Manifest
117
117
  - README.md
118
118
  - Rakefile
119
- - examples/welcome.rb
120
119
  - fauna.gemspec
121
120
  - lib/fauna.rb
122
121
  - lib/fauna/cache.rb
123
122
  - lib/fauna/client.rb
124
123
  - lib/fauna/connection.rb
125
- - lib/fauna/provided_classes.rb
124
+ - lib/fauna/named_resource.rb
126
125
  - lib/fauna/rails.rb
127
126
  - lib/fauna/resource.rb
128
127
  - lib/fauna/set.rb
data/examples/welcome.rb DELETED
@@ -1,73 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Ruby 1.9 required
3
-
4
- require "rubygems"
5
- require "pp"
6
- begin
7
- require "fauna"
8
- rescue LoadError
9
- puts "Please run: sudo gem install fauna"
10
- exit!
11
- end
12
-
13
- print "Email: "
14
- email = gets.chomp
15
-
16
- print "Password: "
17
- pass = gets.chomp
18
-
19
- puts "\nConnected to Fauna Cloud Platform."
20
-
21
- puts "\nCreating a server key:"
22
- root = Fauna::Connection.new(email: email, password: pass)
23
- key = root.post("keys", "role" => "server")['resource']['key']
24
- $fauna = Fauna::Connection.new(server_key: key)
25
- pp key
26
-
27
- puts "\nCreating classes:"
28
- class User < Fauna::User
29
- pp self
30
- end
31
-
32
- class Spell < Fauna::Class
33
- pp self
34
- end
35
-
36
- puts "\nCreating an event set."
37
- Fauna.schema do
38
- with User do
39
- event_set :spellbook
40
- end
41
-
42
- with Spell
43
- end
44
-
45
- Fauna::Client.context($fauna) do
46
- puts "\nMigrating."
47
- Fauna.migrate_schema!
48
-
49
- puts "\nCreating a user:"
50
- user = User.create!(
51
- email: "#{object_id}@example.com",
52
- password: "1234",
53
- data: {
54
- name: "Taran",
55
- profession: "Pigkeeper",
56
- location: "Caer Dallben"
57
- })
58
- pp user.struct
59
-
60
- puts "\nCreating an instance:"
61
- spell = Spell.create!(
62
- data: {
63
- pronouncement: "Draw Dyrnwyn only thou of royal blood.",
64
- title: "Protector of Dyrnwyn"
65
- })
66
- pp spell.struct
67
-
68
- puts "\nAdding the instance to the user's event set."
69
- user.spellbook.add(spell)
70
-
71
- puts "\nFetching the event set:"
72
- pp user.spellbook.page.struct
73
- end
@@ -1,39 +0,0 @@
1
- module Fauna
2
- class NamedResource < Fauna::Resource
3
- def name; struct['name'] end
4
-
5
- def ref; super || "#{fauna_class}/#{name}" end
6
-
7
- private
8
-
9
- def post
10
- raise Invalid, "Cannot POST to named resource."
11
- end
12
- end
13
-
14
- class Database < Fauna::NamedResource
15
- def self.new(*args); super('databases', *args) end
16
- end
17
-
18
- class Class < Fauna::NamedResource
19
- def self.new(*args); super('classes', *args) end
20
- end
21
-
22
- class Key < Fauna::Resource
23
- def self.new(*args); super('keys', *args) end
24
-
25
- def database
26
- struct['database'] || ref.split('/keys').first
27
- end
28
-
29
- private
30
-
31
- def post
32
- Fauna::Client.post("#{database}/keys", struct)
33
- end
34
- end
35
-
36
- class Token < Fauna::Resource
37
- def self.new(*args); super('tokens', *args) end
38
- end
39
- end