Class: STDDAPI::Client
Instance Method Summary collapse
- #add_embedding_to_scenario(embedding) ⇒ Object
- #add_params_to_path(path, params) ⇒ Object
- #add_step_to_scenario(step) ⇒ Object
- #create_customer(customer_name) ⇒ Object
- #create_feature(feature) ⇒ Object
- #create_module(run_id, name, kind, start) ⇒ Object
- #create_project(customer_id, project_name) ⇒ Object
- #create_run(project_id, run_name, source, revision) ⇒ Object
- #create_scenario(scenario) ⇒ Object
- #get_customer(customer_name) ⇒ Object
- #get_project(customer_id, project_name) ⇒ Object
- #get_run(project_id, name) ⇒ Object
- #http_get(path) ⇒ Object
- #http_post(path, body) ⇒ Object
-
#initialize(stdd_url, http_proxy = nil) ⇒ Client
constructor
A new instance of Client.
- #update_module_stopTime(module_id, stop_time) ⇒ Object
Constructor Details
#initialize(stdd_url, http_proxy = nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 |
# File 'lib/stdd_api.rb', line 12 def initialize(stdd_url,http_proxy=nil) @url = stdd_url ? stdd_url : 'http://www.stddtool.se' @proxy = http_proxy ? URI.parse('http://'+http_proxy) : OpenStruct.new @connection_error = nil @uri = URI.parse(@url) end |
Instance Method Details
#add_embedding_to_scenario(embedding) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/stdd_api.rb', line 195 def path = "/api/add_embedding_to_scenario" valid, response = http_post path, .to_json if(valid) success = response["success"] if(success) return true, success end else return false, response end end |
#add_params_to_path(path, params) ⇒ Object
250 251 252 253 254 255 |
# File 'lib/stdd_api.rb', line 250 def add_params_to_path (path, params) if(params) path = "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')) end return path end |
#add_step_to_scenario(step) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/stdd_api.rb', line 181 def add_step_to_scenario step path = "/api/add_step_to_scenario" valid, response = http_post path, step.to_json if(valid) success = response["success"] if(success) return true, success end else return false, response end end |
#create_customer(customer_name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stdd_api.rb', line 19 def create_customer customer_name customer = Customer.new(customer_name) path = "/api/create_customer" valid, response = http_post path, customer.to_json if(valid) customer = Customer.new(response["name"]) customer.id = response["_id"] return true, customer else return false, response end end |
#create_feature(feature) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/stdd_api.rb', line 153 def create_feature feature path = "/api/create_feature" valid, response = http_post path, feature.to_json if(valid) id = response["_id"] if(id) return true, id end else return false, response end end |
#create_module(run_id, name, kind, start) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/stdd_api.rb', line 118 def create_module run_id, name, kind, start modl = Module.new(run_id,name,kind,start) path = "/api/create_module" valid, response = http_post path, modl.to_json if(valid) modl = Module.new(response["runID"],response["name"],response["kind"],response["startTime"]) modl.id = response["_id"] stop_time = response["stopTime"] if(stop_time) modl.stop_time = stop_time end return true, modl else return false, response end end |
#create_project(customer_id, project_name) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/stdd_api.rb', line 51 def create_project customer_id, project_name project = Project.new(customer_id,project_name) path = "/api/create_project" valid, response = http_post path, project.to_json if(valid) project = Project.new(response["customerID"],response["name"]) project.id = response["_id"] return true, project else return false, response end end |
#create_run(project_id, run_name, source, revision) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/stdd_api.rb', line 82 def create_run project_id,run_name,source,revision run = Run.new(project_id,run_name,source,revision) path = "/api/create_run" valid, response = http_post path, run.to_json if(valid) run = Run.new(response["projectID"],response["name"],response["source"],response["revision"]) run.id = response["_id"] return true, run else return false, response end end |
#create_scenario(scenario) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/stdd_api.rb', line 167 def create_scenario scenario path = "/api/create_scenario" valid, response = http_post path, scenario.to_json if(valid) id = response["_id"] if(id) return true, id end else return false, response end end |
#get_customer(customer_name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/stdd_api.rb', line 34 def get_customer(customer_name) path = "/api/get_customer" path = add_params_to_path(path,{:name => customer_name}) valid, response = http_get path if(valid) customer = Customer.new(response["name"]) if response["name"] customer.id = response["_id"] if response["_id"] return true, customer else return false, response end end |
#get_project(customer_id, project_name) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/stdd_api.rb', line 65 def get_project(customer_id, project_name) path = "/api/get_project" path = add_params_to_path(path,{:customer_id => customer_id, :name => project_name}) valid, response = http_get path if(valid) project = Project.new(response["customerID"],response["name"]) project.id = response["_id"] return true, project else return false, response end end |
#get_run(project_id, name) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/stdd_api.rb', line 98 def get_run(project_id, name) path = "/api/get_run" path = add_params_to_path(path,{:project_id => project_id, :name => name}) valid, response = http_get path if(valid) run = Run.new(project_id,name) run.id = response["_id"] run.source = response["source"] if(response["revision"]) run.revision = response["revision"] end return true, run else return false, response end end |
#http_get(path) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/stdd_api.rb', line 229 def http_get path req = Net::HTTP::Get.new(path,) response = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(@uri.host, @uri.port).start {|http| http.request(req) } case response.code when /20\d/ #success else return false, response.body end parsed_response = JSON.parse(response.body) return true,parsed_response end |
#http_post(path, body) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/stdd_api.rb', line 209 def http_post path,body begin http = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(@uri.host, @uri.port) request = Net::HTTP::Post.new(path,initheader = { 'Content-Type' => 'application/json'}) request.body = body response = http.request(request) case response.code when /20\d/ #success else return false,response.body end rescue Exception => ex return false, ex end return true, JSON.parse(response.body) end |
#update_module_stopTime(module_id, stop_time) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/stdd_api.rb', line 136 def update_module_stopTime(module_id,stop_time) path = "/api/update_module_stoptime" valid, response = http_post path, {"module_id" => module_id, "stop_time" => stop_time}.to_json if(valid) modl = Module.new(response["runID"],response["name"],response["kind"],response["startTime"]) modl.id = response["_id"] stop_time = response["stopTime"] if(stop_time) modl.stop_time = stop_time end return true, modl else return false, response end end |