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('arthur@dent.com')

Convert a coupon (received per email) to an account

client = Nodester::Client.new("","")
client.platform_create_user("coupon",'arthur','dent','arthur@dent.com','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

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.



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.



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.



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' : 'git@nodester.com:/node/git/mwawrusch/blah.git'

  • 'running' : false

  • 'pid' : "unknown" | some pid

  • 'gitrepo' : 'git@nodester.com:/node/git/mwawrusch/2914-2295037e88fed947a9b3b994171c5a9e.git", "running"=>false, "pid"=>"unknown"}

Returns a list of all apps.



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' : 'git@nodester.com:/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.



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.



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.



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.



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.



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.



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.



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.



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.



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



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.



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.

Options Hash (opts):

  • :start (String)

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



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.



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.



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.

Options Hash (opts):

  • :password (String)

    the password to update.

  • :rsakey (String)

    the rsa key to update.



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