Class: Cloudfuji::App

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudfuji/app.rb,
lib/cloudfuji/dns.rb

Overview

Cloudfuji::App provides all of the methods to interact with the app it’s included in, and only contains class methods. Each method will check for the most recent data, so it’s possible the data may change between two separate calls.

Class Method Summary collapse

Class Method Details

.add_domain(domain) ⇒ Object

Adds a domain to the Cloudfuji webrecords for an app. The app <b>must</b> be a premium-app in order to add domains

Example Scenario

If after launching a CMS a user decides to use a custom domain, an app can allow a user to customize it directly without resorting to the Cloudfuji app control panel.



149
150
151
# File 'lib/cloudfuji/app.rb', line 149

def add_domain(domain)
  put :add_domain!, {:domain => domain}
end

.add_var(key, value) ⇒ Object

Add an environmental variable

Example Scenario

Allows your app to easily integrate into third-party services, e.g. mixpanel. A user can enter their own API key, and you can activate your mixpanel code.



78
79
80
81
82
83
# File 'lib/cloudfuji/app.rb', line 78

def add_var(key, value)
  put :add_var, {:key => key, :value => value}
  if Cloudfuji::Command.last_command_successful?
    ENV[key.upcase] = value
  end
end

.app_urlObject

:nodoc:



7
8
9
# File 'lib/cloudfuji/app.rb', line 7

def app_url #:nodoc:
  "#{Cloudfuji::Platform.host}/apps/#{Cloudfuji::Platform.name}.json"
end

.claimObject

Claims an app for the current Cloudfuji user Raises an exception if app is launched anonymously

Example Scenario

Integrate Cloudfuji app claiming behavior directly into your app to help conversion rates



60
61
62
# File 'lib/cloudfuji/app.rb', line 60

def claim
  put :claim
end

.clear_log!(name) ⇒ Object

Clear out the given log

Example Scenario

An app may keep its production log for analysis by the end-user, but the user may want to clear out the irrelevant past logs.



171
172
173
# File 'lib/cloudfuji/app.rb', line 171

def clear_log!(name)
  put :clear_log!, {:name => name}
end

.domainsObject

List all custom domains belonging to the current application

Example Scenario

A CMS may want to use this if hosting multiple sites



100
101
102
# File 'lib/cloudfuji/app.rb', line 100

def domains
  get()["app"]["domains"]
end

.get(params = {}) ⇒ Object

:nodoc:



12
13
14
# File 'lib/cloudfuji/app.rb', line 12

def get(params={}) #:nodoc:
  Cloudfuji::Command.get_command(app_url, params)
end

.logsObject

Get all of the new logs. Returns a hash of the form => “content of log X” On Cloudfuji, there are by default the following logs:

  • access - Any page hit or asset request

  • error - Any error we had serving the page/asset

  • production - Output from the rails server

  • cloudfuji - logs from the cloudfuji deploy, update, start/stop process

– TODO: Update to use the new logs controller ++



185
186
187
# File 'lib/cloudfuji/app.rb', line 185

def logs
  get({:gift => "logs"})
end

.mail_allowed?Boolean

Check if the app is allowed to send emails Apps are rate-limited according to their tier

Returns:

  • (Boolean)


192
193
194
# File 'lib/cloudfuji/app.rb', line 192

def mail_allowed?
  Cloudfuji::Command.get_command(Cloudfuji::Base.allowed_email_url)
end

.put(command, params = {}) ⇒ Object

:nodoc:



17
18
19
20
21
# File 'lib/cloudfuji/app.rb', line 17

def put(command, params={})  #:nodoc:
  params[:command] = command

  Cloudfuji::Command.put_command(app_url, params)
end

.remove_domain(domain) ⇒ Object

Removes a custom domain from the Cloudfuji webrecords. Only works if the custom domain:

  • belongs to the current user

  • points at the current app

Example Scenario

A user may decide to migrate a domain to a different app. This allows an app to remove it from its records without resorting to the Cloudfuji app control panel



162
163
164
# File 'lib/cloudfuji/app.rb', line 162

def remove_domain(domain)
  put :remove_domain!, {:domain => domain}
end

.remove_var(key) ⇒ Object

Remove an environmental variable

Example Scenario



89
90
91
92
93
94
# File 'lib/cloudfuji/app.rb', line 89

def remove_var(key)
  put :remove_var, {:key => key}
  if Cloudfuji::Command.last_command_successful?
    ENV[key.upcase] = nil
  end
end

.restartObject

Stops (if started) and then starts an app

Example Scenario

if you’ve added environmental variables to an application and need the app to restart to pick them up, use this.



51
52
53
# File 'lib/cloudfuji/app.rb', line 51

def restart # :nodoc:
  put :restart
end

.set_subdomain(subdomain) ⇒ Object

Set the cloudfuji.com subdomain of an application

Example Scenario

An app is initially launched to a randomly-generated subdomain, but may want to move to something more memorable for a given user.



131
132
133
134
135
136
137
138
139
140
# File 'lib/cloudfuji/app.rb', line 131

def set_subdomain(subdomain)
  result = put :set_subdomain!, {:subdomain => subdomain}
  if Cloudfuji::Command.last_command_successful?
    ENV["CLOUDFUJI_SUBDOMAIN"] = subdomain
    ENV["PUBLIC_URL"] = "http://#{subdomain}.#{ENV['APP_TLD']}/"
    return result
  end

  result
end

.showObject

Get all of the information related to the current app, returns a hash



25
26
27
# File 'lib/cloudfuji/app.rb', line 25

def show
  result = get
end

.ssh_keyObject

:nodoc:



197
198
199
# File 'lib/cloudfuji/app.rb', line 197

def ssh_key #:nodoc:
  get({:gift => "ssh_key"})["ssh_key"]
end

.startObject

Starts a currently stopped app

Example Scenario

You may want to use this when recieving a <tt>rake cloudfuji:message</tt> event to start up your app for an incoming message



34
35
36
# File 'lib/cloudfuji/app.rb', line 34

def start
  put :start
end

.stopObject

Stops an app.

Example Scenario

Use this if you want to put your application in ‘maintenance mode’.



42
43
44
# File 'lib/cloudfuji/app.rb', line 42

def stop
  put :stop
end

.subdomainObject

Returns the current subdomain of the app, whether that’s the default (e.g. “happy-rabbit-12”) or a custom-set subdomain (“my-example”)

Example Scenario

A CMS will use this to know which subdomain to respond to



109
110
111
# File 'lib/cloudfuji/app.rb', line 109

def subdomain
  get()["app"]["subdomain"]
end

.subdomain_available?(subdomain) ⇒ Boolean

Check if a subdomain of cloudfuji.com is currently available

Example Scenario

An application may want to change its subdomain to something user-chosen; use this before-hand to ensure it’s available

Returns:

  • (Boolean)


118
119
120
121
122
123
124
# File 'lib/cloudfuji/app.rb', line 118

def subdomain_available?(subdomain)
  begin
    return put :subdomain_available?, {:subdomain => subdomain}
  rescue RestClient::UnprocessableEntity
    return false
  end
end

.updateObject

Updates the app to the latest git checkout, using the branch the app was initially dpeloyed from

Example Scenario

Allow your users to upgrade to the latest version via a link directly in your application



69
70
71
# File 'lib/cloudfuji/app.rb', line 69

def update
  put :update
end