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 CHANGED
@@ -1,3 +1,5 @@
1
1
  *.swp
2
2
 
3
3
  pkg
4
+
5
+ .idea
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongohq-client (0.0.3)
4
+ mongohq-client (0.0.4)
5
5
  httparty
6
6
  json
7
7
 
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
@@ -21,6 +21,12 @@ module MongoHQClient
21
21
  db_list
22
22
  end
23
23
 
24
+ def create_database(db_name, plan)
25
+ hash = { name: db_name, slug: plan }
26
+
27
+ post("databases", hash)
28
+ end
29
+
24
30
  def invoices
25
31
  json = get("invoices")
26
32
 
@@ -28,5 +28,9 @@ module MongoHQClient
28
28
  Collection.new(json: json, database: name)
29
29
  end
30
30
 
31
+ def remove
32
+ delete("databases/#{name}")
33
+ end
34
+
31
35
  end
32
36
  end
@@ -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: { :_apikey => apikey } )
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"
@@ -2,7 +2,7 @@ lib = File.expand_path('../lib/', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "mongohq-client"
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Rodrigo Saito"]
8
8
  s.email = ["rodrigo.saito@gmail.com"]
@@ -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.3
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-14 00:00:00.000000000 Z
12
+ date: 2012-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty