Class: Nodester::Client
- Inherits:
-
Object
- Object
- Nodester::Client
- Includes:
- HTTParty
- Defined in:
- lib/nodester/client.rb
Overview
An API wrapper for the nodester.com API
Constant Summary collapse
- PLATFORM_URI =
'http://nodester.com'
Class Method Summary collapse
-
.bad_response(response) ⇒ Object
Examines a bad response and raises an approriate exception.
Instance Method Summary collapse
- #app(appname) ⇒ Object
- #appdomains ⇒ Object
-
#apps ⇒ Object
Get a list of all apps.
-
#create_app(appname, start) ⇒ Object
Creates a new app Parameters are: appname (required).
- #create_appdomain(appname, domain) ⇒ Object
- #delete_app(appname) ⇒ Object
- #delete_appdomain(appname, domain) ⇒ Object
- #delete_env(appname, key) ⇒ Object
- #env(appname, key) ⇒ Object
- #handle_result(res) ⇒ Object
-
#initialize(u, p) ⇒ Client
constructor
A new instance of Client.
-
#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.
-
#platform_create_user(coupon, user, password, email, rsakey) ⇒ Object
Creates a new user from the coupon given.
-
#platform_delete_user ⇒ Object
Deletes the current user.
-
#platform_status ⇒ Object
Returns the nodester.com platform status :appshosted=>1599, :appsrunning=>988.
- #start_stop_app(appname, running = true) ⇒ Object
- #update_app(appname, opts = {}) ⇒ Object
- #update_env(appname, key, value) ⇒ Object
-
#update_npm(appname, action, package) ⇒ Object
curl -X POST -u “mwawrusch:mw09543089” -d “appname=myappname&action=install&package=express” api.nodester.com/npm.
-
#update_user(opts = {}) ⇒ Object
Updates the current user.
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
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) ={:body => {},:basic_auth => @auth} handle_result self.class.get("/app/#{appname}", ) end |
#appdomains ⇒ Object
187 188 189 190 |
# File 'lib/nodester/client.rb', line 187 def appdomains() ={:basic_auth => @auth} handle_result self.class.get('/appdomains', ) end |
#apps ⇒ Object
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() ={:basic_auth => @auth} handle_result self.class.get('/apps', ) 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) ={:body => {:appname=>appname,:start=>start}, :basic_auth => @auth} handle_result self.class.post('/app', ) end |
#create_appdomain(appname, domain) ⇒ Object
177 178 179 180 |
# File 'lib/nodester/client.rb', line 177 def create_appdomain(appname,domain) ={:body => {:appname => appname,:domain=>domain},:basic_auth => @auth} handle_result self.class.post('/appdomains', ) end |
#delete_app(appname) ⇒ Object
126 127 128 129 |
# File 'lib/nodester/client.rb', line 126 def delete_app(appname) ={:body => {:appname => appname}, :basic_auth => @auth} handle_result self.class.delete('/app', ) end |
#delete_appdomain(appname, domain) ⇒ Object
182 183 184 185 |
# File 'lib/nodester/client.rb', line 182 def delete_appdomain(appname,domain) ={:body => {:appname => appname,:domain=>domain},:basic_auth => @auth} handle_result self.class.delete('/appdomains', ) end |
#delete_env(appname, key) ⇒ Object
159 160 161 162 |
# File 'lib/nodester/client.rb', line 159 def delete_env(appname,key) ={:body => {:appname => appname,:key=>key},:basic_auth => @auth} handle_result self.class.delete('/env', ) end |
#env(appname, key) ⇒ Object
164 165 166 167 |
# File 'lib/nodester/client.rb', line 164 def env(appname,key) ={:body => {:appname => appname,:key=>key},:basic_auth => @auth} handle_result self.class.get('/env', ) 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) ={ :body => {:email => email}, :base_uri => PLATFORM_URI} handle_result self.class.post('/coupon', ) 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) ={ :body => {:coupon => coupon,:user =>user,:password=>password,:email=>email,:rsakey=>rsakey}, :base_uri => PLATFORM_URI} handle_result self.class.post('/user', ) end |
#platform_delete_user ⇒ Object
Deletes the current user.
87 88 89 90 |
# File 'lib/nodester/client.rb', line 87 def platform_delete_user() ={:basic_auth => @auth} handle_result self.class.delete('/user', ) end |
#platform_status ⇒ Object
Returns the nodester.com platform status :appshosted=>1599, :appsrunning=>988
65 66 67 68 |
# File 'lib/nodester/client.rb', line 65 def platform_status() = {:base_uri => PLATFORM_URI} handle_result self.class.get('/status', ) 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) ={:body=> {:appname => appname, :running=>start}, :basic_auth => @auth} handle_result self.class.put('/app', ) 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}) ={:body=> opts, :basic_auth => @auth} handle_result self.class.put('/app', ) end |
#update_env(appname, key, value) ⇒ Object
154 155 156 157 |
# File 'lib/nodester/client.rb', line 154 def update_env(appname,key,value) ={:body => {:appname => appname,:key=>key,:value=>value},:basic_auth => @auth} handle_result self.class.put('/env', ) 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) ={:body => {:appname => appname,:action => action,:package=>package},:basic_auth => @auth} handle_result self.class.post('/npm', ) end |
#update_user(opts = {}) ⇒ Object
Updates the current user.
81 82 83 84 |
# File 'lib/nodester/client.rb', line 81 def update_user(opts={}) ={:body => opts,:basic_auth => @auth} handle_result self.class.put('/user', ) end |