stdd_api 0.2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/objects.rb +165 -0
  3. data/lib/stdd_api.rb +258 -0
  4. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94c39aa2b325786b7f26120b520bcad03c9903ed
4
+ data.tar.gz: ec5c5d01cf37b468c16c08041ef33a38d926014a
5
+ SHA512:
6
+ metadata.gz: fe273cebb9a1f9f9cc180398c9232801976efa599f85e7e8856a999ddeab9fbe9ddc7c9a82e2d4548e6883a0dabeb7b7b38507df562ef2f0ca9383da341bf770
7
+ data.tar.gz: 7259e8cbcb895342cb8c1eebc5320e5c18354a37075998200f65f60f9c33177b91c68c938b5df38e443bebb39cc72b772b929ce3cd1a4f9160110a2099757c69
data/lib/objects.rb ADDED
@@ -0,0 +1,165 @@
1
+ module STDDAPI
2
+ module Objects
3
+ class Customer
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+ attr_accessor :name,:id
8
+ def to_s
9
+ "name: #{@name}, id: #{@id}"
10
+ end
11
+ def to_json
12
+ {'name' => @name}.to_json
13
+ end
14
+ end
15
+
16
+ class Project
17
+ def initialize(customer_id,name)
18
+ @name = name
19
+ @customer_id = customer_id
20
+ end
21
+ attr_accessor :name,:id,:customer_id
22
+ def to_s
23
+ "name: #{@name}, customer_id: #{@customer_id}, id: #{@id}"
24
+ end
25
+ def to_json
26
+ {'name' => @name,'customer_id' => customer_id}.to_json
27
+ end
28
+ end
29
+
30
+ class Run
31
+ def initialize(project_id,name,source="",revision="")
32
+ @project_id = project_id
33
+ @name = name
34
+ @source = source
35
+ @revision = revision
36
+
37
+ end
38
+ attr_accessor :name,:id,:project_id,:source,:revision
39
+ def to_s
40
+ "name: #{@name}\n"+
41
+ "id: #{@id}\n"+
42
+ "project-id: #{@project_id}\n"+
43
+ "source: #{@source}\n"+
44
+ "revision: #{@revision}\n"
45
+ end
46
+ def to_json
47
+ {
48
+ 'name' => @name,
49
+ 'project_id' => @project_id,
50
+ 'source'=> @source,
51
+ 'revision'=>@revision
52
+ }.to_json
53
+ end
54
+ end
55
+
56
+ class Module
57
+ def initialize(run_id,name,kind,start_time)
58
+ @run_id = run_id
59
+ @name = name
60
+ @kind = kind
61
+ @start_time = start_time
62
+
63
+ end
64
+ attr_accessor :name,:id,:run_id,:kind,:start_time,:stop_time
65
+ def to_s
66
+ "name: #{@name}\n"+
67
+ "id: #{@id}\n"+
68
+ "run-id: #{@run_id}\n"+
69
+ "kind: #{@kind}\n"+
70
+ "start-time: #{@start_time}\n"
71
+ end
72
+ def to_json
73
+ {
74
+ 'name' => @name,
75
+ 'run_id' => @run_id,
76
+ 'kind' => @kind,
77
+ 'start_time'=> @start_time,
78
+ 'stop_time'=>@stop_time
79
+ }.to_json
80
+ end
81
+ end
82
+
83
+ class Feature
84
+ def initialize(module_id,name,date)
85
+ @module_id = module_id
86
+ @name = name
87
+ @date = date
88
+ @tags = []
89
+ end
90
+ attr_accessor :name,:id,:module_id,:date,:description,:tags,:file
91
+ def to_s
92
+ "name: #{@name}\n"+
93
+ "id: #{@id}\n"+
94
+ "module-id: #{@module_id}\n"+
95
+ "date: #{@date}\n"+
96
+ "description: #{@description}\n"+
97
+ "tags: #{@tags}\n"+
98
+ "file: #{@file}\n"
99
+ end
100
+ def to_json
101
+ {
102
+ 'name' => @name,
103
+ 'module_id' => @module_id,
104
+ 'date'=>@date,
105
+ 'description'=>@description,
106
+ 'tags'=>@tags,
107
+ 'file'=>@file
108
+ }.to_json
109
+ end
110
+ end
111
+ class Scenario
112
+ def initialize(feature_id, name,element_type,keyword)
113
+ @feature_id = feature_id
114
+ @name = name
115
+ @element_type = element_type
116
+ @keyword = keyword
117
+ @tags = []
118
+ @steps = []
119
+ end
120
+ attr_accessor :feature_id,:keyword,:tags,:name,:element_type,:steps,:id
121
+ def to_json
122
+ {'feature_id' => @feature_id,
123
+ 'keyword' => @keyword,
124
+ 'name' => @name,
125
+ 'tags' => @tags,
126
+ 'element_type' => @element_type,
127
+ 'steps'=>@steps
128
+ }.to_json
129
+ end
130
+ end
131
+
132
+ class Step
133
+ def initialize(scenario_id,keyword, name)
134
+ @keyword=keyword
135
+ @name=name
136
+ @scenario_id = scenario_id
137
+ end
138
+ attr_accessor :keyword,:name,:status,:messages,:error_message,:duration,:scenario_id
139
+ def to_json
140
+ {
141
+ 'scenario_id'=>scenario_id,
142
+ 'keyword' => @keyword,
143
+ 'name' => @name ,
144
+ 'result' => {
145
+ 'status' =>@status,
146
+ 'error_message'=> @error_message,
147
+ 'duration'=>@duration
148
+ },
149
+ 'messages' => @messages
150
+ }.to_json
151
+ end
152
+ end
153
+ class Embedding
154
+ def initialize(scenario_id,mime_type,buf)
155
+ @scenario_id = scenario_id
156
+ @mime_type = mime_type
157
+ @buf=buf
158
+ end
159
+ attr_accessor :mime_type,:buf,:scenario_id
160
+ def to_json
161
+ {'scenario_id'=>scenario_id ,'mime_type' => @mime_type,'buf' => @buf}.to_json
162
+ end
163
+ end
164
+ end
165
+ end
data/lib/stdd_api.rb ADDED
@@ -0,0 +1,258 @@
1
+ require 'rubygems'
2
+ require 'cgi'
3
+ require 'uri'
4
+ require 'net/http'
5
+ require_relative 'objects'
6
+
7
+ module STDDAPI
8
+
9
+ class Client
10
+ include STDDAPI::Objects
11
+
12
+ def initialize(stdd_url,http_proxy=nil)
13
+ @url = stdd_url ? stdd_url : 'http://www.stddtool.se'
14
+ @proxy = http_proxy ? URI.parse('http://'+http_proxy) : OpenStruct.new
15
+ @connection_error = nil
16
+ @uri = URI.parse(@url)
17
+ end
18
+
19
+ def create_customer customer_name
20
+ customer = Customer.new(customer_name)
21
+ path = "/api/create_customer"
22
+ valid, response = http_post path, customer.to_json
23
+
24
+ if(valid)
25
+ customer = Customer.new(response["name"])
26
+ customer.id = response["_id"]
27
+ return true, customer
28
+ else
29
+ return false, response
30
+ end
31
+
32
+ end
33
+
34
+ def get_customer(customer_name)
35
+ path = "/api/get_customer"
36
+ path = add_params_to_path(path,{:name => customer_name})
37
+
38
+ valid, response = http_get path
39
+
40
+
41
+ if(valid)
42
+ customer = Customer.new(response["name"]) if response["name"]
43
+ customer.id = response["_id"] if response["_id"]
44
+ return true, customer
45
+ else
46
+ return false, response
47
+ end
48
+
49
+ end
50
+
51
+ def create_project customer_id, project_name
52
+ project = Project.new(customer_id,project_name)
53
+ path = "/api/create_project"
54
+ valid, response = http_post path, project.to_json
55
+
56
+ if(valid)
57
+ project = Project.new(response["customerID"],response["name"])
58
+ project.id = response["_id"]
59
+ return true, project
60
+ else
61
+ return false, response
62
+ end
63
+ end
64
+
65
+ def get_project(customer_id, project_name)
66
+
67
+ path = "/api/get_project"
68
+ path = add_params_to_path(path,{:customer_id => customer_id, :name => project_name})
69
+
70
+ valid, response = http_get path
71
+
72
+ if(valid)
73
+ project = Project.new(response["customerID"],response["name"])
74
+ project.id = response["_id"]
75
+ return true, project
76
+ else
77
+ return false, response
78
+ end
79
+
80
+ end
81
+
82
+ def create_run project_id,run_name,source,revision
83
+ run = Run.new(project_id,run_name,source,revision)
84
+ path = "/api/create_run"
85
+ valid, response = http_post path, run.to_json
86
+
87
+ if(valid)
88
+ run = Run.new(response["projectID"],response["name"],response["source"],response["revision"])
89
+ run.id = response["_id"]
90
+ return true, run
91
+ else
92
+ return false, response
93
+ end
94
+
95
+
96
+ end
97
+
98
+ def get_run(project_id, name)
99
+ path = "/api/get_run"
100
+ path = add_params_to_path(path,{:project_id => project_id, :name => name})
101
+
102
+ valid, response = http_get path
103
+
104
+ if(valid)
105
+ run = Run.new(project_id,name)
106
+ run.id = response["_id"]
107
+ run.source = response["source"]
108
+ if(response["revision"])
109
+ run.revision = response["revision"]
110
+ end
111
+ return true, run
112
+ else
113
+ return false, response
114
+ end
115
+
116
+ end
117
+
118
+ def create_module run_id, name, kind, start
119
+ modl = Module.new(run_id,name,kind,start)
120
+ path = "/api/create_module"
121
+ valid, response = http_post path, modl.to_json
122
+
123
+ if(valid)
124
+ modl = Module.new(response["runID"],response["name"],response["kind"],response["startTime"])
125
+ modl.id = response["_id"]
126
+ stop_time = response["stopTime"]
127
+ if(stop_time)
128
+ modl.stop_time = stop_time
129
+ end
130
+ return true, modl
131
+ else
132
+ return false, response
133
+ end
134
+ end
135
+
136
+ def update_module_stopTime(module_id,stop_time)
137
+ path = "/api/update_module_stoptime"
138
+ valid, response = http_post path, {"module_id" => module_id, "stop_time" => stop_time}.to_json
139
+
140
+ if(valid)
141
+ modl = Module.new(response["runID"],response["name"],response["kind"],response["startTime"])
142
+ modl.id = response["_id"]
143
+ stop_time = response["stopTime"]
144
+ if(stop_time)
145
+ modl.stop_time = stop_time
146
+ end
147
+ return true, modl
148
+ else
149
+ return false, response
150
+ end
151
+ end
152
+
153
+ def create_feature feature
154
+ path = "/api/create_feature"
155
+ valid, response = http_post path, feature.to_json
156
+
157
+ if(valid)
158
+ id = response["_id"]
159
+ if(id)
160
+ return true, id
161
+ end
162
+ else
163
+ return false, response
164
+ end
165
+ end
166
+
167
+ def create_scenario scenario
168
+ path = "/api/create_scenario"
169
+ valid, response = http_post path, scenario.to_json
170
+
171
+ if(valid)
172
+ id = response["_id"]
173
+ if(id)
174
+ return true, id
175
+ end
176
+ else
177
+ return false, response
178
+ end
179
+ end
180
+
181
+ def add_step_to_scenario step
182
+ path = "/api/add_step_to_scenario"
183
+ valid, response = http_post path, step.to_json
184
+
185
+ if(valid)
186
+ success = response["success"]
187
+ if(success)
188
+ return true, success
189
+ end
190
+ else
191
+ return false, response
192
+ end
193
+ end
194
+
195
+ def add_embedding_to_scenario embedding
196
+ path = "/api/add_embedding_to_scenario"
197
+ valid, response = http_post path, embedding.to_json
198
+
199
+ if(valid)
200
+ success = response["success"]
201
+ if(success)
202
+ return true, success
203
+ end
204
+ else
205
+ return false, response
206
+ end
207
+ end
208
+
209
+ def http_post path,body
210
+ begin
211
+ http = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(@uri.host, @uri.port)
212
+ request = Net::HTTP::Post.new(path,initheader = { 'Content-Type' => 'application/json'})
213
+ request.body = body
214
+ response = http.request(request)
215
+ case response.code
216
+ when /20\d/
217
+ #success
218
+ else
219
+ return false,response.body
220
+ end
221
+ rescue Exception => ex
222
+ return false, ex
223
+ end
224
+
225
+ return true, JSON.parse(response.body)
226
+
227
+ end
228
+
229
+ def http_get path
230
+ req = Net::HTTP::Get.new(path,)
231
+ response = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(@uri.host, @uri.port).start {|http|
232
+ http.request(req)
233
+ }
234
+ case response.code
235
+ when /20\d/
236
+ #success
237
+ else
238
+ return false, response.body
239
+ end
240
+
241
+ parsed_response = JSON.parse(response.body)
242
+ return true,parsed_response
243
+ end
244
+
245
+
246
+
247
+
248
+
249
+
250
+ def add_params_to_path (path, params)
251
+ if(params)
252
+ path = "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))
253
+ end
254
+ return path
255
+ end
256
+ end
257
+ end
258
+
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stdd_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anton Danielsson
8
+ - Anders Åslund
9
+ - Learningwell West
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-03-07 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: API for reporting to stddtool
16
+ email: anton.danielsson@learningwell.se
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/stdd_api.rb
22
+ - lib/objects.rb
23
+ homepage: https://github.com/LearningWellWest/ruby-stdd
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.0.3
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: API for stddtool
47
+ test_files: []