Class: Nodester::Client

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

Overview

An API wrapper for the nodester.com 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 =
'http://nodester.com'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(u, p) ⇒ Client

Returns a new instance of Client.



29
30
31
# File 'lib/nodester/client.rb', line 29

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

Class Method Details

.bad_response(response) ⇒ Object

Examines a bad response and raises an approriate exception

Parameters:

  • response (HTTParty::Response)

Raises:

  • (StandardError)


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

def self.bad_response(response)
  if response.class == HTTParty::Response
   raise ResponseError, response
  end
  raise StandardError, "Unkown error"
end

Instance Method Details

#app(appname) ⇒ Object



131
132
133
134
# File 'lib/nodester/client.rb', line 131

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

#appdomainsObject



187
188
189
190
# File 'lib/nodester/client.rb', line 187

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

#appsObject

Get a list of all apps. Returns:

An array containing a list of apps, if any.

App object format:

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"}


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

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

#create_app(appname, start) ⇒ Object

Creates a new app Parameters are:

appname (required). The name of the app.
start (required). The file to start, for example server.js.

Returns:

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


106
107
108
109
# File 'lib/nodester/client.rb', line 106

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) ⇒ Object



177
178
179
180
# File 'lib/nodester/client.rb', line 177

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) ⇒ Object



126
127
128
129
# File 'lib/nodester/client.rb', line 126

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

#delete_appdomain(appname, domain) ⇒ Object



182
183
184
185
# File 'lib/nodester/client.rb', line 182

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) ⇒ Object



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

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) ⇒ Object



164
165
166
167
# File 'lib/nodester/client.rb', line 164

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

#handle_result(res) ⇒ Object



44
45
46
# File 'lib/nodester/client.rb', line 44

def handle_result(res)
  res.ok? ? res : bad_response(res) 
end

#platform_coupon_request(email) ⇒ Object

Creates a coupon request against nodester.com for early access Flow is as follows: You post this and receive a coupon per email. Parameters:

email (required) : "[email protected]"

Returns:

status : "success - you are now in queue to receive an invite on our next batch!"


58
59
60
61
# File 'lib/nodester/client.rb', line 58

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) ⇒ Object

Creates a new user from the coupon given.



71
72
73
74
# File 'lib/nodester/client.rb', line 71

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_userObject

Deletes the current user.



87
88
89
90
# File 'lib/nodester/client.rb', line 87

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

#platform_statusObject

Returns the nodester.com platform status :appshosted=>1599, :appsrunning=>988



65
66
67
68
# File 'lib/nodester/client.rb', line 65

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

#start_stop_app(appname, running = true) ⇒ Object



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

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

#update_app(appname, opts = {}) ⇒ Object



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

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) ⇒ Object



154
155
156
157
# File 'lib/nodester/client.rb', line 154

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) ⇒ Object

curl -X POST -u “mwawrusch:mw09543089” -d “appname=myappname&action=install&package=express” api.nodester.com/npm



171
172
173
174
# File 'lib/nodester/client.rb', line 171

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 = {}) ⇒ Object

Updates the current user.



81
82
83
84
# File 'lib/nodester/client.rb', line 81

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