mongohq-client 0.0.1 → 0.0.2
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.
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +54 -0
- data/Guardfile +10 -0
- data/README.md +45 -0
- data/Rakefile +2 -0
- data/lib/mongohq-client.rb +21 -0
- data/lib/mongohq-client/client.rb +55 -0
- data/lib/mongohq-client/collection.rb +43 -0
- data/lib/mongohq-client/commons.rb +29 -0
- data/lib/mongohq-client/database.rb +32 -0
- data/lib/mongohq-client/database_details.rb +6 -0
- data/lib/mongohq-client/document.rb +5 -0
- data/lib/mongohq-client/http.rb +23 -0
- data/lib/mongohq-client/index.rb +5 -0
- data/lib/mongohq-client/invoice.rb +5 -0
- data/lib/mongohq-client/plan.rb +5 -0
- data/mongohq-client.gemspec +22 -0
- data/spec/mongohq-client/client_spec.rb +65 -0
- data/spec/mongohq-client/collection_spec.rb +64 -0
- data/spec/mongohq-client/database_details_spec.rb +74 -0
- data/spec/mongohq-client/database_spec.rb +79 -0
- data/spec/spec_helper.rb +14 -0
- metadata +26 -2
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mongohq-client (0.0.1)
|
5
|
+
httparty
|
6
|
+
json
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.1.3)
|
12
|
+
fakeweb (1.3.0)
|
13
|
+
ffi (1.0.11)
|
14
|
+
guard (1.2.3)
|
15
|
+
listen (>= 0.4.2)
|
16
|
+
thor (>= 0.14.6)
|
17
|
+
guard-rspec (1.2.0)
|
18
|
+
guard (>= 1.1)
|
19
|
+
httparty (0.8.3)
|
20
|
+
multi_json (~> 1.0)
|
21
|
+
multi_xml
|
22
|
+
json (1.7.3)
|
23
|
+
listen (0.4.7)
|
24
|
+
rb-fchange (~> 0.0.5)
|
25
|
+
rb-fsevent (~> 0.9.1)
|
26
|
+
rb-inotify (~> 0.8.8)
|
27
|
+
multi_json (1.3.6)
|
28
|
+
multi_xml (0.5.1)
|
29
|
+
rake (0.9.2.2)
|
30
|
+
rb-fchange (0.0.5)
|
31
|
+
ffi
|
32
|
+
rb-fsevent (0.9.1)
|
33
|
+
rb-inotify (0.8.8)
|
34
|
+
ffi (>= 0.5.0)
|
35
|
+
rspec (2.11.0)
|
36
|
+
rspec-core (~> 2.11.0)
|
37
|
+
rspec-expectations (~> 2.11.0)
|
38
|
+
rspec-mocks (~> 2.11.0)
|
39
|
+
rspec-core (2.11.0)
|
40
|
+
rspec-expectations (2.11.1)
|
41
|
+
diff-lcs (~> 1.1.3)
|
42
|
+
rspec-mocks (2.11.1)
|
43
|
+
thor (0.15.4)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
ruby
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
fakeweb
|
50
|
+
guard
|
51
|
+
guard-rspec
|
52
|
+
mongohq-client!
|
53
|
+
rake
|
54
|
+
rspec
|
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Mongohq::Client
|
2
|
+
|
3
|
+
A simple MongoHQ api client for ruby
|
4
|
+
|
5
|
+
TODO: Write a gem description
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'mongohq-client'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mongohq-client
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Require mongohq-client
|
24
|
+
|
25
|
+
require 'mongohq-client'
|
26
|
+
|
27
|
+
Authenticate with you apikey
|
28
|
+
|
29
|
+
client = MongoHQClient.from_apikey("youapikey")
|
30
|
+
|
31
|
+
Retrieve all your databases
|
32
|
+
|
33
|
+
databases = client.databases
|
34
|
+
|
35
|
+
Retrive collections from database
|
36
|
+
|
37
|
+
collections = client.databases.first.collections
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require 'mongohq-client/commons'
|
5
|
+
require 'mongohq-client/http'
|
6
|
+
require 'mongohq-client/plan'
|
7
|
+
require 'mongohq-client/invoice'
|
8
|
+
require 'mongohq-client/index'
|
9
|
+
require 'mongohq-client/document'
|
10
|
+
require 'mongohq-client/collection'
|
11
|
+
require 'mongohq-client/database_details'
|
12
|
+
require 'mongohq-client/database'
|
13
|
+
require 'mongohq-client/client'
|
14
|
+
|
15
|
+
module MongoHQClient
|
16
|
+
|
17
|
+
def self.from_apikey(apikey)
|
18
|
+
Client.new apikey
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module MongoHQClient
|
2
|
+
|
3
|
+
class Client
|
4
|
+
include HTTP
|
5
|
+
|
6
|
+
attr_accessor :apikey
|
7
|
+
|
8
|
+
def initialize(apikey)
|
9
|
+
@apikey = apikey
|
10
|
+
end
|
11
|
+
|
12
|
+
def databases
|
13
|
+
json = get("databases")
|
14
|
+
|
15
|
+
db_list = []
|
16
|
+
|
17
|
+
json.each do |db|
|
18
|
+
db_list << Database.new(json: db, apikey: apikey)
|
19
|
+
end
|
20
|
+
|
21
|
+
db_list
|
22
|
+
end
|
23
|
+
|
24
|
+
def invoices
|
25
|
+
json = get("invoices")
|
26
|
+
|
27
|
+
invoices = []
|
28
|
+
|
29
|
+
json.each do |invoice|
|
30
|
+
invoices << Invoice.new(json: invoice)
|
31
|
+
end
|
32
|
+
|
33
|
+
invoices
|
34
|
+
end
|
35
|
+
|
36
|
+
def invoice(id)
|
37
|
+
json = get("invoices/#{id}")
|
38
|
+
|
39
|
+
Invoice.new json: json
|
40
|
+
end
|
41
|
+
|
42
|
+
def plans
|
43
|
+
json = get("plans")
|
44
|
+
|
45
|
+
plans = []
|
46
|
+
|
47
|
+
json.each do |plan|
|
48
|
+
plans << Plan.new(json: plan)
|
49
|
+
end
|
50
|
+
|
51
|
+
plans
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module MongoHQClient
|
2
|
+
class Collection
|
3
|
+
include Commons
|
4
|
+
include HTTP
|
5
|
+
|
6
|
+
def documents
|
7
|
+
json = get("databases/#{database}/collections/#{name}/documents")
|
8
|
+
|
9
|
+
documents = []
|
10
|
+
|
11
|
+
json.each do |doc|
|
12
|
+
documents << Document.new(json:doc)
|
13
|
+
end
|
14
|
+
|
15
|
+
documents
|
16
|
+
end
|
17
|
+
|
18
|
+
def document(id)
|
19
|
+
json = get("databases/#{database}/collections/#{name}/documents/#{id}")
|
20
|
+
|
21
|
+
Document.new(json: json)
|
22
|
+
end
|
23
|
+
|
24
|
+
def indexes
|
25
|
+
json = get("databases/#{database}/collections/#{name}/indexes")
|
26
|
+
|
27
|
+
indexes = []
|
28
|
+
|
29
|
+
json.each do |index|
|
30
|
+
indexes << Index.new(json: index)
|
31
|
+
end
|
32
|
+
|
33
|
+
indexes
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
def database
|
38
|
+
raise "Invalid database" unless @params[:database]
|
39
|
+
@params[:database]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MongoHQClient
|
2
|
+
module Commons
|
3
|
+
def method_missing(method, *args)
|
4
|
+
attribute = method.to_s
|
5
|
+
if (attribute.to_s.end_with? '?')
|
6
|
+
attribute = attribute.to_s[0..-2]
|
7
|
+
end
|
8
|
+
|
9
|
+
super.method_missing(method, *args) unless json_hash.has_key? attribute
|
10
|
+
|
11
|
+
return json_hash["#{attribute}"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(params = {})
|
15
|
+
raise "Invalid json" unless params[:json].is_a? Hash
|
16
|
+
@params = params
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
def json_hash
|
21
|
+
@params[:json]
|
22
|
+
end
|
23
|
+
|
24
|
+
def apikey
|
25
|
+
@params[:apikey]
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module MongoHQClient
|
2
|
+
|
3
|
+
class Database
|
4
|
+
include Commons
|
5
|
+
include HTTP
|
6
|
+
|
7
|
+
def details
|
8
|
+
json = get("databases/#{name}")
|
9
|
+
|
10
|
+
DatabaseDetails.new json: json
|
11
|
+
end
|
12
|
+
|
13
|
+
def collections
|
14
|
+
json = get("databases/#{name}/collections")
|
15
|
+
|
16
|
+
collections = []
|
17
|
+
|
18
|
+
json.each do |col|
|
19
|
+
collections << Collection.new(json: col, apikey: apikey, database: name)
|
20
|
+
end
|
21
|
+
|
22
|
+
collections
|
23
|
+
end
|
24
|
+
|
25
|
+
def collection(col_name)
|
26
|
+
json = get("databases/#{name}/collections/#{col_name}")
|
27
|
+
|
28
|
+
Collection.new(json: json, database: name)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MongoHQClient
|
2
|
+
|
3
|
+
module HTTP
|
4
|
+
|
5
|
+
def get(uri)
|
6
|
+
puts uri
|
7
|
+
raise "Invalid apikey" unless apikey
|
8
|
+
resp = HTTParty.get("#{base_uri}/#{uri}", query: { :_apikey => apikey } )
|
9
|
+
|
10
|
+
puts resp.body
|
11
|
+
|
12
|
+
#TODO error handling
|
13
|
+
|
14
|
+
JSON.parse(resp.body)
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def base_uri
|
19
|
+
"https://api.mongohq.com"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "mongohq-client"
|
5
|
+
s.version = "0.0.2"
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = ["Rodrigo Saito"]
|
8
|
+
s.email = ["rodrigo.saito@gmail.com"]
|
9
|
+
s.summary = "A client for MongoHQ API"
|
10
|
+
|
11
|
+
s.add_dependency("httparty")
|
12
|
+
s.add_dependency("json")
|
13
|
+
|
14
|
+
s.add_development_dependency("rspec")
|
15
|
+
s.add_development_dependency("guard")
|
16
|
+
s.add_development_dependency("guard-rspec")
|
17
|
+
s.add_development_dependency("fakeweb")
|
18
|
+
|
19
|
+
s.require_path = 'lib'
|
20
|
+
s.files = `git ls-files`.split($\)
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe MongoHQClient::Client do
|
4
|
+
let(:client) { MongoHQClient.from_apikey("123456") }
|
5
|
+
|
6
|
+
describe "client creation" do
|
7
|
+
|
8
|
+
it "should return a client with apikey" do
|
9
|
+
client.apikey.should eq("123456")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#databases" do
|
14
|
+
before do
|
15
|
+
FakeWeb.register_uri :get, "https://api.mongohq.com/databases?_apikey=#{client.apikey}", body: '[{"name":"database1","hostname":"host.mongohq.com","port":27036,"shared":true,"plan":"Micro"},{"name":"database2","hostname":"host2.mongohq.com","port":10075,"shared":true,"plan":"Sandbox"},{"name":"database3","hostname":"staff.mongohq.com","port":10025,"shared":true,"plan":"Sandbox"}]'
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:databases) { client.databases }
|
19
|
+
|
20
|
+
it "should return 3 databases" do
|
21
|
+
databases.size.should eq(3)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#invoices" do
|
26
|
+
before do
|
27
|
+
FakeWeb.register_uri :get, "https://api.mongohq.com/invoices?_apikey=#{client.apikey}", body: '[{"id":12345,"amount":5.0,"balance":0.0,"bill_date":"2012-06-01","is_paid":true},{"id":12346,"amount":5.0,"balance":0.0,"bill_date":"2012-07-01","is_paid":true}]'
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:invoices) { client.invoices }
|
31
|
+
|
32
|
+
it "should return 2 invoice" do
|
33
|
+
invoices.size.should eq(2)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return amount" do
|
37
|
+
invoices.first.amount.should eq(5.0)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#invoice" do
|
42
|
+
before do
|
43
|
+
FakeWeb.register_uri :get, "https://api.mongohq.com/invoices/12345?_apikey=#{client.apikey}", body: '{"id":12345,"amount":5.0,"balance":0.0,"bill_date":"2012-06-01","is_paid":true}'
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:invoice) { client.invoice("12345")}
|
47
|
+
|
48
|
+
it "should return a paid invoice" do
|
49
|
+
invoice.is_paid?.should be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#plans" do
|
54
|
+
before do
|
55
|
+
FakeWeb.register_uri :get, "https://api.mongohq.com/plans?_apikey=#{client.apikey}", body: '[{"name":"Micro","slug":"micro","price":5,"type":"hosted"},{"name":"Replica Set: Large","slug":"rs_large","price":300,"type":"hosted"}]'
|
56
|
+
end
|
57
|
+
|
58
|
+
let(:plans) { client.plans }
|
59
|
+
|
60
|
+
it "should return plans" do
|
61
|
+
plans.size.should eq(2)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe MongoHQClient::Collection do
|
4
|
+
let(:subject) { MongoHQClient::Collection.new json: JSON.parse('{"name":"collection1","count":15,"storageSize":192512,"avgObjSize":2257.866666666667,"indexCount":1,"ok":1.0}'), apikey: "123456", database: "database1" }
|
5
|
+
|
6
|
+
describe "#name" do
|
7
|
+
it_behaves_like "attribute", :name, "collection1"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#count" do
|
11
|
+
it_behaves_like "attribute", :count, 15
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#storageSize" do
|
15
|
+
it_behaves_like "attribute", :storageSize, 192512
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#avgObjSize" do
|
19
|
+
it_behaves_like "attribute", :avgObjSize, 2257.866666666667
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#indexCount" do
|
23
|
+
it_behaves_like "attribute", :indexCount, 1
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#ok" do
|
27
|
+
it_behaves_like "attribute", :ok, 1.0
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#documents" do
|
31
|
+
before do
|
32
|
+
FakeWeb.register_uri :get, "https://api.mongohq.com/databases/database1/collections/collection1/documents?_apikey=123456", body: '[{"_id":{"$oid": "4ffde13927bce841321005ec0"},"name":"Test User","updated_at":"2012-07-11 20:25:29 UTC","created_at":"2012-07-11 20:25:29 UTC"}]'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return documents" do
|
36
|
+
subject.documents.size.should eq(1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#document" do
|
41
|
+
before do
|
42
|
+
FakeWeb.register_uri :get, "https://api.mongohq.com/databases/database1/collections/collection1/documents/4ffde13927bce841321005ec0?_apikey=123456", body: '{"_id":{"$oid": "4ffde13927bce841321005ec0"},"name":"Test User","updated_at":"2012-07-11 20:25:29 UTC","created_at":"2012-07-11 20:25:29 UTC"}'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return document by id" do
|
46
|
+
subject.document('4ffde13927bce841321005ec0').name.should eq("Test User")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#indexes" do
|
51
|
+
before do
|
52
|
+
FakeWeb.register_uri :get, "https://api.mongohq.com/databases/database1/collections/collection1/indexes?_apikey=123456", body: '[{"v":1,"key":{"_id":1},"ns":"database1.collection1","name":"_id_"}]'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return indexes" do
|
56
|
+
subject.indexes.size.should eq(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return ns" do
|
60
|
+
subject.indexes.first.ns.should eq("database1.collection1")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe MongoHQClient::DatabaseDetails do
|
4
|
+
let(:subject) { MongoHQClient::DatabaseDetails.new json: JSON.parse('{"db":"database1","collections":10,"objects":1799,"avgObjSize":353.85881045025013,"dataSize":636592,"storageSize":2314240,"numExtents":17,"indexes":9,"indexSize":147168,"fileSize":251658240,"nsSizeMB":16,"ok":1.0,"name":"database1","hostname":"host.mongohq.com","port":27036,"shared":true,"plan":"Micro"}') }
|
5
|
+
|
6
|
+
describe "#db" do
|
7
|
+
it_behaves_like "attribute", :db, "database1"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#collections" do
|
11
|
+
it_behaves_like "attribute", :collections, 10
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#objects" do
|
15
|
+
it_behaves_like "attribute", :objects, 1799
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#avgObjSize" do
|
19
|
+
it_behaves_like "attribute", :avgObjSize, 353.85881045025013
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#dataSize" do
|
23
|
+
it_behaves_like "attribute", :dataSize, 636592
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#storageSize" do
|
27
|
+
it_behaves_like "attribute", :storageSize, 2314240
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#numExtents" do
|
31
|
+
it_behaves_like "attribute", :numExtents, 17
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#indexes" do
|
35
|
+
it_behaves_like "attribute", :indexes, 9
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#indexSize" do
|
39
|
+
it_behaves_like "attribute", :indexSize, 147168
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#fileSize" do
|
43
|
+
it_behaves_like "attribute", :fileSize, 251658240
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#nsSizeMB" do
|
47
|
+
it_behaves_like "attribute", :nsSizeMB, 16
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#ok" do
|
51
|
+
it_behaves_like "attribute", :ok, 1.0
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#name" do
|
55
|
+
it_behaves_like "attribute", :name, "database1"
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#hostname" do
|
59
|
+
it_behaves_like "attribute", :hostname, "host.mongohq.com"
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#port" do
|
63
|
+
it_behaves_like "attribute", :port, 27036
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#shared" do
|
67
|
+
it_behaves_like "attribute", :shared, true
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#plan" do
|
71
|
+
it_behaves_like "attribute", :plan, "Micro"
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe MongoHQClient::Database do
|
4
|
+
|
5
|
+
let(:database) { MongoHQClient::Database.new json: JSON.parse('{"name":"database1","hostname":"host.mongohq.com","port":27036,"shared":true,"plan":"Micro"}'), apikey: "123456" }
|
6
|
+
|
7
|
+
describe "#name" do
|
8
|
+
it "should return the name of database" do
|
9
|
+
database.name.should eq("database1")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#hostname" do
|
14
|
+
it "should return hostname of database" do
|
15
|
+
database.hostname.should eq("host.mongohq.com")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#port" do
|
20
|
+
it "should return port of database" do
|
21
|
+
database.port.should eq(27036)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#shared" do
|
26
|
+
it "should return if database is shared" do
|
27
|
+
database.shared?.should be_true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#plan" do
|
32
|
+
it "should return the plan of database" do
|
33
|
+
database.plan.should eq("Micro")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should raise error where attribute is invalid" do
|
38
|
+
expect {
|
39
|
+
database.invalid
|
40
|
+
}.to raise_error(NoMethodError)
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#details" do
|
44
|
+
before do
|
45
|
+
FakeWeb.register_uri :get, "https://api.mongohq.com/databases/database1?_apikey=123456", body: '{"db":"database1","collections":10,"objects":1799,"avgObjSize":353.85881045025013,"dataSize":636592,"storageSize":2314240,"numExtents":17,"indexes":9,"indexSize":147168,"fileSize":251658240,"nsSizeMB":16,"ok":1.0,"name":"database1","hostname":"host.mongohq.com","port":27036,"shared":true,"plan":"Micro"}'
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:details) { database.details }
|
49
|
+
|
50
|
+
it "should return database details" do
|
51
|
+
details.db.should eq("database1")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#collections" do
|
56
|
+
before do
|
57
|
+
FakeWeb.register_uri :get, "https://api.mongohq.com/databases/database1/collections?_apikey=123456", body: '[{"name":"collections1","count":0,"storageSize":40960,"avgObjSize":null,"indexCount":1,"ok":1.0},{"name":"collection2","count":15,"storageSize":192512,"avgObjSize":2257.866666666667,"indexCount":1,"ok":1.0},{"name":"collections3","count":162,"storageSize":294912,"avgObjSize":1006.8395061728395,"indexCount":1,"ok":1.0},{"name":"collections4","count":36,"storageSize":8192,"avgObjSize":92.22222222222223,"indexCount":1,"ok":1.0},{"name":"collections5","count":0,"storageSize":8192,"avgObjSize":null,"indexCount":1,"ok":1.0},{"name":"collections6","count":0,"storageSize":8192,"avgObjSize":null,"indexCount":1,"ok":1.0},{"name":"collections7","count":1558,"storageSize":1740800,"avgObjSize":278.9165596919127,"indexCount":1,"ok":1.0}]'
|
58
|
+
end
|
59
|
+
|
60
|
+
let(:collections) { database.collections }
|
61
|
+
|
62
|
+
it "should return collections" do
|
63
|
+
collections.size.should eq(7)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#collection" do
|
68
|
+
before do
|
69
|
+
FakeWeb.register_uri :get, "https://api.mongohq.com/databases/database1/collections/collection1?_apikey=123456", body: '{"ns":"database1.collection1","count":1558,"size":434552,"avgObjSize":278.9165596919127,"storageSize":1740800,"numExtents":4,"nindexes":1,"lastExtentSize":1310720,"paddingFactor":1.009999999999998,"flags":1,"totalIndexSize":81760,"indexSizes":{"_id_":81760},"ok":1.0}'
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:collection) { database.collection "collection1" }
|
73
|
+
|
74
|
+
it "should return collection with details" do
|
75
|
+
collection.ns.should eq("database1.collection1")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'fakeweb'
|
5
|
+
require 'mongohq-client'
|
6
|
+
|
7
|
+
FakeWeb.allow_net_connect = false
|
8
|
+
|
9
|
+
shared_examples "attribute" do |attr, expected|
|
10
|
+
it "should return #{attr} attribute" do
|
11
|
+
subject.send(attr).should eq(expected)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongohq-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -113,7 +113,31 @@ email:
|
|
113
113
|
executables: []
|
114
114
|
extensions: []
|
115
115
|
extra_rdoc_files: []
|
116
|
-
files:
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- .rspec
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- Guardfile
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/mongohq-client.rb
|
125
|
+
- lib/mongohq-client/client.rb
|
126
|
+
- lib/mongohq-client/collection.rb
|
127
|
+
- lib/mongohq-client/commons.rb
|
128
|
+
- lib/mongohq-client/database.rb
|
129
|
+
- lib/mongohq-client/database_details.rb
|
130
|
+
- lib/mongohq-client/document.rb
|
131
|
+
- lib/mongohq-client/http.rb
|
132
|
+
- lib/mongohq-client/index.rb
|
133
|
+
- lib/mongohq-client/invoice.rb
|
134
|
+
- lib/mongohq-client/plan.rb
|
135
|
+
- mongohq-client.gemspec
|
136
|
+
- spec/mongohq-client/client_spec.rb
|
137
|
+
- spec/mongohq-client/collection_spec.rb
|
138
|
+
- spec/mongohq-client/database_details_spec.rb
|
139
|
+
- spec/mongohq-client/database_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
117
141
|
homepage:
|
118
142
|
licenses: []
|
119
143
|
post_install_message:
|