Class: Nodester::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/nodester/client.rb

Overview

The client to access the API.

Examples:

Request a nodester.com coupon

client = Nodester::Client.new("","")
client.platform_coupon_request('[email protected]')

Convert a coupon (received per email) to an account

client = Nodester::Client.new("","")
client.platform_create_user("coupon",'arthur','dent','[email protected]','rsakey')

Get the platform status

client = Nodester::Client.new("","")
res = client.platform_status()
puts "Status #{res['status']} Apps Hosted #{res['appshosted']} Apps Running #{res['appsrunning']}"

Create an app

client = Nodester::Client.new("arthur","dent")
client.create_app 'myappname','server.js'

Constant Summary collapse

PLATFORM_URI =

The uri used to access the nodester.com platform for account management and status purposes.

'http://nodester.com'

Instance Method Summary collapse

Constructor Details

#initialize(u, p) ⇒ Client

Inititalizer for the client class.

Parameters:

  • u (String)

    the user name of your nodester.com account.

  • p (String)

    the password of your nodester.com account.



39
40
41
# File 'lib/nodester/client.rb', line 39

def initialize(u, p )
  @auth = {:username => u, :password => p}
end

Instance Method Details

#app(appname) ⇒ HTTParty::Response

Returns the properties of an app.

Parameters:

  • appname (String)

    the name of the app.

Returns:

  • (HTTParty::Response)

    A response.



175
176
177
178
# File 'lib/nodester/client.rb', line 175

def app(appname)
  options={:body => {},:basic_auth => @auth}
  handle_result self.class.get("/app/#{appname}", options)
end

#appdomainsHTTParty::Response

Returns a list of all app domains for all apps of the current user.

Returns:

  • (HTTParty::Response)

    A response.



257
258
259
260
# File 'lib/nodester/client.rb', line 257

def appdomains()
  options={:basic_auth => @auth}
  handle_result self.class.get('/appdomains', options)
end

#appsHTTParty::Response

Note:

The result contains the following entries (check nodester.com for up to date information):

  • ‘name’ : ‘testxyz1’

  • ‘port’ : 12344

  • ‘gitrepo’ : ‘[email protected]:/node/git/mwawrusch/blah.git’

  • ‘running’ : false

  • ‘pid’ : “unknown” | some pid

  • ‘gitrepo’ : ‘[email protected]:/node/git/mwawrusch/2914-2295037e88fed947a9b3b994171c5a9e.git“, ”running“=>false, ”pid“=>”unknown“}

Returns a list of all apps.

Returns:

  • (HTTParty::Response)

    A response. An array containing a list of apps, if any.



190
191
192
193
# File 'lib/nodester/client.rb', line 190

def apps()
  options={:basic_auth => @auth}
  handle_result self.class.get('/apps', options)
end

#create_app(appname, start) ⇒ HTTParty::Response

Note:

The result contains the following entries (check nodester.com for up to date information):

  • ‘status’ : “success” | “failure”

  • ‘message’ : “some text” ==> Only if failure

  • ‘port’ : 12345

  • ‘gitrepo’ : ‘[email protected]:/node/git/mwawrusch/blah.git’

  • ‘start’ : “the value of start, for example servre.js”

  • ‘running’ : true | false

  • ‘pid’ : “unknown” | some pid

Creates a new app.

Parameters:

  • appname (String)

    the name of the app.

  • start (String)

    the file that contains the node.js startup code. (server.js)

Returns:

  • (HTTParty::Response)

    A response.



138
139
140
141
# File 'lib/nodester/client.rb', line 138

def create_app(appname,start)
  options={:body => {:appname=>appname,:start=>start}, :basic_auth => @auth}
  handle_result self.class.post('/app', options)
end

#create_appdomain(appname, domain) ⇒ HTTParty::Response

Note:

Check out the notester.com site for up to date information how to set your a record to route the domain to the actual servers.

Creates a new domain entry for an app.

Parameters:

  • appname (String)

    the name of the app.

  • domain (String)

    the domain to be associated with the app.

Returns:

  • (HTTParty::Response)

    A response.



241
242
243
244
# File 'lib/nodester/client.rb', line 241

def create_appdomain(appname,domain)
  options={:body => {:appname => appname,:domain=>domain},:basic_auth => @auth}
  handle_result self.class.post('/appdomains', options)
end

#delete_app(appname) ⇒ HTTParty::Response

Deletes an app.

Parameters:

  • appname (String)

    the name of the app.

Returns:

  • (HTTParty::Response)

    A response.



167
168
169
170
# File 'lib/nodester/client.rb', line 167

def delete_app(appname)
  options={:body => {:appname => appname}, :basic_auth => @auth}
  handle_result self.class.delete('/app', options)
end

#delete_appdomain(appname, domain) ⇒ HTTParty::Response

Deletes a domain entry from an app.

Parameters:

  • appname (String)

    the name of the app.

  • domain (String)

    the domain to be disassociated from the app.

Returns:

  • (HTTParty::Response)

    A response.



250
251
252
253
# File 'lib/nodester/client.rb', line 250

def delete_appdomain(appname,domain)
  options={:body => {:appname => appname,:domain=>domain},:basic_auth => @auth}
  handle_result self.class.delete('/appdomains', options)
end

#delete_env(appname, key) ⇒ HTTParty::Response

Deletes a key from the app’s environment.

Parameters:

  • appname (String)

    the name of the app.

  • key (String)

    the key (name) of the evironment variable.

Returns:

  • (HTTParty::Response)

    A response.



210
211
212
213
# File 'lib/nodester/client.rb', line 210

def delete_env(appname,key)
  options={:body => {:appname => appname,:key=>key},:basic_auth => @auth}
  handle_result self.class.delete('/env', options)
end

#env(appname, key) ⇒ HTTParty::Response

Returns the value of a key in the app’s environment.

Parameters:

  • appname (String)

    the name of the app.

  • key (String)

    the key (name) of the evironment variable.

Returns:

  • (HTTParty::Response)

    A response.



219
220
221
222
# File 'lib/nodester/client.rb', line 219

def env(appname,key)
  options={:body => {:appname => appname,:key=>key},:basic_auth => @auth}
  handle_result self.class.get('/env', options)
end

#platform_coupon_request(email) ⇒ HTTParty::Response

Note:

Flow is as follows: You post this and receive a coupon per email. The result contains the following entries (check nodester.com for up to date information):

  • ‘status’ : “success - you are now in queue to receive an invite on our next batch!” | “failure”

Creates a coupon request against nodester.com for early access.

Parameters:

  • email (String)

    the email where the coupon should be sent to.

Returns:

  • (HTTParty::Response)

    A response.



74
75
76
77
# File 'lib/nodester/client.rb', line 74

def platform_coupon_request(email)
  options={ :body => {:email => email}, :base_uri => PLATFORM_URI}
  handle_result self.class.post('/coupon', options)
end

#platform_create_user(coupon, user, password, email, rsakey) ⇒ HTTParty::Response

Creates a new user by redeeming a coupon.

Parameters:

  • coupon (String)

    the coupon received from nodester.

  • user (String)

    the user name of the new user.

  • password (String)

    the password of the new user.

  • email (String)

    the email of the new user.

  • rsakey (String)

    the rsa key of the new user.

Returns:

  • (HTTParty::Response)

    A response.

See Also:



99
100
101
102
# File 'lib/nodester/client.rb', line 99

def platform_create_user(coupon,user,password,email,rsakey)
  options={ :body => {:coupon => coupon,:user =>user,:password=>password,:email=>email,:rsakey=>rsakey}, :base_uri => PLATFORM_URI}
  handle_result self.class.post('/user', options)
end

#platform_delete_userHTTParty::Response

Deletes the current user.

Returns:

  • (HTTParty::Response)

    A response.



119
120
121
122
# File 'lib/nodester/client.rb', line 119

def platform_delete_user()
  options={:basic_auth => @auth}
  handle_result self.class.delete('/user', options)
end

#platform_statusHTTParty::Response

Note:

The result contains the following entries (check nodester.com for up to date information):

  • ‘status’ : “up”

  • ‘appshosted’ : 599

  • ‘appsrunning’ : 988

Retrieves the nodester.com platform status

Returns:

  • (HTTParty::Response)

    A response



85
86
87
88
# File 'lib/nodester/client.rb', line 85

def platform_status()
  options = {:base_uri => PLATFORM_URI}
  handle_result self.class.get('/status', options)
end

#start_stop_app(appname, running = true) ⇒ HTTParty::Response

Starts or stops an app.

Parameters:

  • appname (String)

    the name of the app.

  • running (Boolean) (defaults to: true)

    true to start the app; false to stop the app.

Returns:

  • (HTTParty::Response)

    A response.



158
159
160
161
162
# File 'lib/nodester/client.rb', line 158

def start_stop_app(appname,running = true)
  
  options={:body=> {:appname => appname, :running=>running}, :basic_auth => @auth}
  handle_result self.class.put('/app', options)
end

#update_app(appname, opts = {}) ⇒ HTTParty::Response

Updates properties of an app.

Parameters:

  • appname (String)

    the name of the app.

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :start (String)

    the startup file that contains the node.js startup code.

Returns:

  • (HTTParty::Response)

    A response.



147
148
149
150
151
152
# File 'lib/nodester/client.rb', line 147

def update_app(appname,opts = {})
  opts.merge!({:appname => appname})
  
  options={:body=> opts, :basic_auth => @auth}
  handle_result self.class.put('/app', options)
end

#update_env(appname, key, value) ⇒ HTTParty::Response

Creates or updates a value for a key in the app’s environment.

Parameters:

  • appname (String)

    the name of the app.

  • key (String)

    the key (name) of the evironment variable.

  • value (String)

    the value of the environment variable.

Returns:

  • (HTTParty::Response)

    A response.



201
202
203
204
# File 'lib/nodester/client.rb', line 201

def update_env(appname,key,value)
  options={:body => {:appname => appname,:key=>key,:value=>value},:basic_auth => @auth}
  handle_result self.class.put('/env', options)
end

#update_npm(appname, action, package) ⇒ HTTParty::Response

Manages the NPM package manager associated with an app.

Parameters:

  • appname (String)

    the name of the app.

  • action (String)

    the action to perform. Can be install|upgrade|uninstall. Check official documentation for more info.

  • package (String)

    the name of the package that should be worked with.

Returns:

  • (HTTParty::Response)

    A response.



230
231
232
233
# File 'lib/nodester/client.rb', line 230

def update_npm(appname,action,package)
  options={:body => {:appname => appname,:action => action,:package=>package},:basic_auth => @auth}
  handle_result self.class.post('/npm', options)
end

#update_user(opts = {}) ⇒ HTTParty::Response

Updates the settings for the current user.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :password (String)

    the password to update.

  • :rsakey (String)

    the rsa key to update.

Returns:

  • (HTTParty::Response)

    A response.



112
113
114
115
# File 'lib/nodester/client.rb', line 112

def update_user(opts={})
  options={:body => opts,:basic_auth => @auth}
  handle_result self.class.put('/user', options)
end