Class: API

Inherits:
Object
  • Object
show all
Defined in:
lib/appfog_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ API

Returns a new instance of API.



6
7
8
9
10
# File 'lib/appfog_api.rb', line 6

def initialize(username, password)
  @username = username
  @password = password
  @@site = RestClient::Resource.new('https://api.appfog.com')
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



5
6
7
# File 'lib/appfog_api.rb', line 5

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/appfog_api.rb', line 5

def username
  @username
end

Instance Method Details

#app(app) ⇒ Object



37
38
39
# File 'lib/appfog_api.rb', line 37

def app(app)
  JSON.parse(get("/apps/#{app}"))
end

#app_crash(app) ⇒ Object



41
42
43
# File 'lib/appfog_api.rb', line 41

def app_crash(app)
  JSON.parse(get("/apps/#{app}/crashes"))
end

#app_instances(app) ⇒ Object



45
46
47
# File 'lib/appfog_api.rb', line 45

def app_instances(app)
  JSON.parse(get("/apps/#{app}/instances"))
end

#app_stats(app) ⇒ Object



49
50
51
# File 'lib/appfog_api.rb', line 49

def app_stats(app)
  JSON.parse(get("/apps/#{app}/stats"))
end

#authObject



12
13
14
15
16
17
# File 'lib/appfog_api.rb', line 12

def auth
  password = {'password'=>@password}.to_json
  request = @@site["users/#{@username}/tokens"].post password, :content_type => :json
  raw_token = JSON.parse(request)
  @token = raw_token['token']
end

#get(url) ⇒ Object



19
20
21
22
23
24
# File 'lib/appfog_api.rb', line 19

def get(url)
  if @token == nil 
    auth
  end
  @@site[url].get("Authorization"=>@token)
end

#infoObject



33
34
35
# File 'lib/appfog_api.rb', line 33

def info
  JSON.parse(get("/info"))
end

#post(url) ⇒ Object



26
27
28
29
30
31
# File 'lib/appfog_api.rb', line 26

def post(url)
  if @token == nil 
    auth
  end
  @@site[url].post("Authorization"=>@token)
end

#servicesObject



53
54
55
# File 'lib/appfog_api.rb', line 53

def services
  JSON.parse(get("/services"))
end