mongohq-client 0.0.3 → 0.0.4
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 +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -0
- data/lib/mongohq-client/client.rb +6 -0
- data/lib/mongohq-client/database.rb +4 -0
- data/lib/mongohq-client/http.rb +13 -1
- data/mongohq-client.gemspec +1 -1
- data/spec/mongohq-client/client_spec.rb +10 -0
- data/spec/mongohq-client/database_spec.rb +10 -0
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -42,6 +42,15 @@ Retrieve indexes from from collection
|
|
42
42
|
|
43
43
|
indexes = client.databases.first.collections.first.indexes
|
44
44
|
|
45
|
+
Create a new database
|
46
|
+
|
47
|
+
# Params database name, plan
|
48
|
+
client.create_database "my_db_name", "sandbox"
|
49
|
+
|
50
|
+
Delete a database
|
51
|
+
|
52
|
+
client.databases.first.remove
|
53
|
+
|
45
54
|
## Contributing
|
46
55
|
|
47
56
|
1. Fork it
|
data/lib/mongohq-client/http.rb
CHANGED
@@ -4,13 +4,25 @@ module MongoHQClient
|
|
4
4
|
|
5
5
|
def get(uri)
|
6
6
|
raise "Invalid apikey" unless apikey
|
7
|
-
resp = HTTParty.get("#{base_uri}/#{uri}", query: { :
|
7
|
+
resp = HTTParty.get("#{base_uri}/#{uri}", query: { _apikey: apikey } )
|
8
8
|
|
9
9
|
#TODO error handling
|
10
10
|
|
11
11
|
JSON.parse(resp.body)
|
12
12
|
end
|
13
13
|
|
14
|
+
def post(uri, json)
|
15
|
+
HTTParty.post "#{base_uri}/#{uri}", body: json, query: { _apikey: apikey }
|
16
|
+
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(uri)
|
21
|
+
HTTParty.delete "#{base_uri}/#{uri}", query: { _apikey: apikey }
|
22
|
+
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
14
26
|
protected
|
15
27
|
def base_uri
|
16
28
|
"https://api.mongohq.com"
|
data/mongohq-client.gemspec
CHANGED
@@ -22,6 +22,16 @@ describe MongoHQClient::Client do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
describe "#create_database" do
|
26
|
+
before do
|
27
|
+
FakeWeb.register_uri :post, "https://api.mongohq.com/databases?_apikey=#{client.apikey}", body: '{"ok":1}'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should create database" do
|
31
|
+
client.create_database "my_new_db", "sandbox"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
25
35
|
describe "#invoices" do
|
26
36
|
before do
|
27
37
|
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}]'
|
@@ -76,4 +76,14 @@ describe MongoHQClient::Database do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
+
describe "#remove" do
|
80
|
+
before do
|
81
|
+
FakeWeb.register_uri :delete, "https://api.mongohq.com/databases/database1?_apikey=123456", body: '{"ok":1}'
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should remove database" do
|
85
|
+
database.remove
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
79
89
|
end
|
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.4
|
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: 2012-07-
|
12
|
+
date: 2012-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|