Class: MongoHQClient::Client

Inherits:
Object
  • Object
show all
Includes:
HTTP
Defined in:
lib/mongohq-client/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HTTP

#delete, #get, #post

Constructor Details

#initialize(apikey) ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/mongohq-client/client.rb', line 8

def initialize(apikey)
  @apikey = apikey
end

Instance Attribute Details

#apikeyObject

Returns the value of attribute apikey.



6
7
8
# File 'lib/mongohq-client/client.rb', line 6

def apikey
  @apikey
end

Instance Method Details

#create_database(db_name, plan) ⇒ Object



24
25
26
27
28
# File 'lib/mongohq-client/client.rb', line 24

def create_database(db_name, plan)
  hash =  { name: db_name, slug: plan }

  post("databases", hash)
end

#databasesObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mongohq-client/client.rb', line 12

def databases
  json = get("databases")

  db_list = []

  json.each do |db|
    db_list << Database.new(json: db, apikey: apikey)
  end

  db_list
end

#invoice(id) ⇒ Object



42
43
44
45
46
# File 'lib/mongohq-client/client.rb', line 42

def invoice(id)
  json = get("invoices/#{id}")

  Invoice.new json: json
end

#invoicesObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mongohq-client/client.rb', line 30

def invoices
  json = get("invoices")

  invoices = []

  json.each do |invoice|
    invoices << Invoice.new(json: invoice)
  end

  invoices
end

#plansObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/mongohq-client/client.rb', line 48

def plans
  json = get("plans")

  plans = []

  json.each do |plan|
    plans << Plan.new(json: plan)
  end

  plans
end