Module: VikingIO::CLI::Client
- Defined in:
- lib/vikingio/cli/client.rb
Constant Summary collapse
- BASE_PATH =
"https://www.vikingio.com/api/"
- BASE_BUILD_PATH =
"http://build1.vikingio.com/"
Class Method Summary collapse
- .authenticate(email, password) ⇒ Object
- .compile_server(user_key, app_key, app_name) ⇒ Object
- .create_app(name) ⇒ Object
- .create_node(name, app_key) ⇒ Object
- .deploy(user_key, app_key) ⇒ Object
- .deploy_check(user_key, app_key) ⇒ Object
- .deploy_data(user_key, app_key, data_path) ⇒ Object
- .deploy_servers(user_key, app_key, server_path) ⇒ Object
- .get_status(user_key, app_key) ⇒ Object
- .request_build_job(user_key, app_key) ⇒ Object
- .synchronize_file(user_key, app_key, file) ⇒ Object
Class Method Details
.authenticate(email, password) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/vikingio/cli/client.rb', line 98 def self.authenticate(email, password) uri = URI.join(BASE_PATH, "auth") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(uri.request_uri) request.set_form_data({"email" => email, "password" => password}) response = http.request(request) return nil if response.code == "403" puts "Unable to reach server." and return nil if response.code == "401" json = JSON.parse(response.body) return json["key"] end |
.compile_server(user_key, app_key, app_name) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/vikingio/cli/client.rb', line 85 def self.compile_server(user_key, app_key, app_name) uri = URI.join(BASE_BUILD_PATH, "compile") http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Get.new(uri.path) req['x-vikingio-user-key'] = user_key req['x-vikingio-key'] = app_key req['x-vikingio-app-name'] = app_name resp = http.request(req) puts resp.body end |
.create_app(name) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/vikingio/cli/client.rb', line 118 def self.create_app(name) uri = URI.join(BASE_PATH, "apps") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(uri.path) req['x-vikingio-user-key'] = VikingIO::CLI.get_netrc_key req.set_form_data({"name" => name}) response = http.request(req) return nil if response.code == "403" puts "Unable to reach server." and return nil if response.code == "401" return JSON.parse(response.body) end |
.create_node(name, app_key) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/vikingio/cli/client.rb', line 135 def self.create_node(name, app_key) return nil if name == "" || name == nil uri = URI.join(BASE_PATH, "nodes") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(uri.path) req['x-vikingio-user-key'] = VikingIO::CLI.get_netrc_key req['x-vikingio-app-key'] = app_key req.set_form_data({"name" => name}) response = http.request(req) return nil if response.code == "403" puts "Unable to reach server." and return nil if response.code == "401" return JSON.parse(response.body) end |
.deploy(user_key, app_key) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vikingio/cli/client.rb', line 53 def self.deploy(user_key, app_key) uri = URI.join(BASE_BUILD_PATH, "deploy") http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Get.new(uri.path) req['x-vikingio-user-key'] = user_key req['x-vikingio-key'] = app_key req['x-vikingio-nodefile'] = VikingIO::CLI.get_node_data.to_json resp = http.request(req) return resp.body end |
.deploy_check(user_key, app_key) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vikingio/cli/client.rb', line 42 def self.deploy_check(user_key, app_key) uri = URI.join(BASE_BUILD_PATH, "deploy_check") http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Get.new(uri.path) req['x-vikingio-user-key'] = user_key req['x-vikingio-key'] = app_key req['x-vikingio-nodefile'] = VikingIO::CLI.get_node_data.to_json resp = http.request(req) return resp.body end |
.deploy_data(user_key, app_key, data_path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vikingio/cli/client.rb', line 20 def self.deploy_data(user_key, app_key, data_path) uri = URI.join(BASE_BUILD_PATH, "deploy_data") req = Net::HTTP::Post::Multipart.new uri.path, {"file" => UploadIO.new(data_path, "application/octet-stream")} req['x-vikingio-user-key'] = user_key req['x-vikingio-key'] = app_key res = Net::HTTP.start(uri.host, uri.port) do |http| http.request(req) end end |
.deploy_servers(user_key, app_key, server_path) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vikingio/cli/client.rb', line 31 def self.deploy_servers(user_key, app_key, server_path) uri = URI.join(BASE_BUILD_PATH, "deploy_servers") req = Net::HTTP::Post::Multipart.new uri.path, {"file" => UploadIO.new(server_path, "application/octet-stream")} req['x-vikingio-user-key'] = user_key req['x-vikingio-key'] = app_key res = Net::HTTP.start(uri.host, uri.port) do |http| http.request(req) end end |
.get_status(user_key, app_key) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vikingio/cli/client.rb', line 8 def self.get_status(user_key, app_key) uri = URI.join(BASE_PATH, "apps/status") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Get.new(uri.path) req['x-vikingio-user-key'] = user_key req['x-vikingio-app-key'] = app_key resp = http.request(req) return JSON.parse(resp.body) end |
.request_build_job(user_key, app_key) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/vikingio/cli/client.rb', line 64 def self.request_build_job(user_key, app_key) uri = URI.join(BASE_BUILD_PATH, "start") http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Get.new(uri.path) req['x-vikingio-user-key'] = user_key req['x-vikingio-key'] = app_key http.request(req) end |
.synchronize_file(user_key, app_key, file) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/vikingio/cli/client.rb', line 74 def self.synchronize_file(user_key, app_key, file) uri = URI.join(BASE_BUILD_PATH, "sync") req = Net::HTTP::Post::Multipart.new uri.path, {"file" => UploadIO.new(file, "application/octet-stream"), "build-rfname" => file.gsub(File.join(Dir.pwd, "VikingIO"), "")} req['x-vikingio-user-key'] = user_key req['x-vikingio-key'] = app_key res = Net::HTTP.start(uri.host, uri.port) do |http| http.request(req) end end |