stella 0.8.8.001 → 2.0.1.001
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +9 -1
- data/Gemfile +19 -0
- data/Gemfile.lock +50 -0
- data/README.md +5 -79
- data/Rakefile +10 -7
- data/Rudyfile +1 -1
- data/TODO +31 -0
- data/VERSION.yml +3 -4
- data/bin/stella +23 -81
- data/certs/README.txt +17 -0
- data/certs/cacerts.pem +1529 -0
- data/certs/gd-class2-root.crt +24 -0
- data/certs/gd_bundle.crt +76 -0
- data/certs/gd_intermediate.crt +29 -0
- data/certs/startssl-ca.pem +44 -0
- data/certs/startssl-sub.class1.server.ca.pem +36 -0
- data/certs/stella-master.crt +1738 -0
- data/lib/stella.rb +191 -123
- data/lib/stella/cli.rb +47 -67
- data/lib/stella/client.rb +424 -360
- data/lib/stella/core_ext.rb +527 -0
- data/lib/stella/engine.rb +126 -419
- data/lib/stella/report.rb +391 -0
- data/lib/stella/testplan.rb +432 -306
- data/lib/stella/utils.rb +227 -2
- data/stella.gemspec +56 -55
- data/try/00_basics_try.rb +29 -0
- data/try/01_selectable_try.rb +25 -0
- data/try/09_utils_try.rb +67 -0
- data/try/10_stella_object_try.rb +49 -0
- data/try/40_report_try.rb +133 -0
- data/try/90_class_syntax_try.rb +13 -0
- data/try/emhttp.rb +62 -0
- data/try/rubyroute.rb +70 -0
- data/try/support/file.bmp +0 -0
- data/try/support/file.gif +0 -0
- data/try/support/file.ico +0 -0
- data/try/support/file.jpeg +0 -0
- data/try/support/file.jpg +0 -0
- data/try/support/file.png +0 -0
- data/try/traceviz.rb +60 -0
- data/vendor/httpclient-2.1.5.2/httpclient/session.rb +5 -2
- metadata +81 -53
- data/examples/cookies/plan.rb +0 -49
- data/examples/csvdata/plan.rb +0 -32
- data/examples/csvdata/search_terms.csv +0 -14
- data/examples/dynamic/plan.rb +0 -60
- data/examples/essentials/logo.png +0 -0
- data/examples/essentials/plan.rb +0 -248
- data/examples/essentials/search_terms.txt +0 -19
- data/examples/exceptions/plan.rb +0 -20
- data/examples/httpauth/plan.rb +0 -33
- data/examples/timeout/plan.rb +0 -18
- data/examples/variables/plan.rb +0 -41
- data/lib/stella/client/container.rb +0 -378
- data/lib/stella/common.rb +0 -363
- data/lib/stella/data.rb +0 -59
- data/lib/stella/data/http.rb +0 -189
- data/lib/stella/engine/functional.rb +0 -156
- data/lib/stella/engine/load.rb +0 -516
- data/lib/stella/guidelines.rb +0 -18
- data/lib/stella/logger.rb +0 -150
- data/lib/stella/utils/httputil.rb +0 -266
- data/try/01_numeric_mixins_tryouts.rb +0 -40
- data/try/12_digest_tryouts.rb +0 -42
- data/try/70_module_usage.rb +0 -21
- data/try/api/10_functional.rb +0 -20
- data/try/configs/failed_requests.rb +0 -31
- data/try/configs/global_sequential.rb +0 -18
- data/try/proofs/thread_queue.rb +0 -21
data/lib/stella/common.rb
DELETED
@@ -1,363 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
|
3
|
-
$KCODE = "u" if RUBY_VERSION =~ /^1.8/
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# A hash with indifferent access and magic predicates.
|
8
|
-
#
|
9
|
-
# hash = Thor::CoreExt::HashWithIndifferentAccess.new 'foo' => 'bar', 'baz' => 'bee', 'force' => true
|
10
|
-
#
|
11
|
-
# hash[:foo] #=> 'bar'
|
12
|
-
# hash['foo'] #=> 'bar'
|
13
|
-
# hash.foo? #=> true
|
14
|
-
#
|
15
|
-
class HashWithIndifferentAccess < ::Hash #:nodoc:
|
16
|
-
|
17
|
-
def initialize(hash={})
|
18
|
-
super()
|
19
|
-
hash.each do |key, value|
|
20
|
-
self[convert_key(key)] = value
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def [](key)
|
25
|
-
super(convert_key(key))
|
26
|
-
end
|
27
|
-
|
28
|
-
def []=(key, value)
|
29
|
-
super(convert_key(key), value)
|
30
|
-
end
|
31
|
-
|
32
|
-
def delete(key)
|
33
|
-
super(convert_key(key))
|
34
|
-
end
|
35
|
-
|
36
|
-
def values_at(*indices)
|
37
|
-
indices.collect { |key| self[convert_key(key)] }
|
38
|
-
end
|
39
|
-
|
40
|
-
def merge(other)
|
41
|
-
dup.merge!(other)
|
42
|
-
end
|
43
|
-
|
44
|
-
def merge!(other)
|
45
|
-
other.each do |key, value|
|
46
|
-
self[convert_key(key)] = value
|
47
|
-
end
|
48
|
-
self
|
49
|
-
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
|
53
|
-
def convert_key(key)
|
54
|
-
key.is_a?(Symbol) ? key.to_s : key
|
55
|
-
end
|
56
|
-
|
57
|
-
# Magic predicates. For instance:
|
58
|
-
#
|
59
|
-
# options.force? # => !!options['force']
|
60
|
-
# options.shebang # => "/usr/lib/local/ruby"
|
61
|
-
# options.test_framework?(:rspec) # => options[:test_framework] == :rspec
|
62
|
-
#
|
63
|
-
def method_missing(method, *args, &block)
|
64
|
-
method = method.to_s
|
65
|
-
if method =~ /^(\w+)\?$/
|
66
|
-
if args.empty?
|
67
|
-
!!self[$1]
|
68
|
-
else
|
69
|
-
self[$1] == args.first
|
70
|
-
end
|
71
|
-
else
|
72
|
-
self[method]
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
# Assumes Time::Units and Numeric mixins are available.
|
80
|
-
|
81
|
-
class String
|
82
|
-
|
83
|
-
def drydock_stub(*args)
|
84
|
-
self
|
85
|
-
end
|
86
|
-
|
87
|
-
unless method_defined? :color
|
88
|
-
alias_method :att, :drydock_stub
|
89
|
-
alias_method :bright, :drydock_stub
|
90
|
-
alias_method :color, :drydock_stub
|
91
|
-
alias_method :colour, :drydock_stub
|
92
|
-
end
|
93
|
-
|
94
|
-
def in_seconds
|
95
|
-
# "60m" => ["60", "m"]
|
96
|
-
q,u = self.scan(/([\d\.]+)([s,m,h])?/).flatten
|
97
|
-
q &&= q.to_f and u ||= 's'
|
98
|
-
q &&= q.in_seconds(u)
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
class Symbol
|
104
|
-
|
105
|
-
def downcase
|
106
|
-
self.to_s.downcase.to_sym
|
107
|
-
end
|
108
|
-
def upcase
|
109
|
-
self.to_s.upcase.to_sym
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
class MatchData
|
115
|
-
include Gibbler::String
|
116
|
-
end
|
117
|
-
|
118
|
-
class Thread
|
119
|
-
extend Attic
|
120
|
-
attic :stats
|
121
|
-
end
|
122
|
-
|
123
|
-
# Fix for eventmachine in Ruby 1.9
|
124
|
-
class Thread
|
125
|
-
unless method_defined? :kill!
|
126
|
-
def kill!(*args) kill( *args) end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
class Time
|
132
|
-
module Units
|
133
|
-
PER_MICROSECOND = 0.000001.freeze
|
134
|
-
PER_MILLISECOND = 0.001.freeze
|
135
|
-
PER_MINUTE = 60.0.freeze
|
136
|
-
PER_HOUR = 3600.0.freeze
|
137
|
-
PER_DAY = 86400.0.freeze
|
138
|
-
|
139
|
-
def microseconds() seconds * PER_MICROSECOND end
|
140
|
-
def milliseconds() seconds * PER_MILLISECOND end
|
141
|
-
def seconds() self end
|
142
|
-
def minutes() seconds * PER_MINUTE end
|
143
|
-
def hours() seconds * PER_HOUR end
|
144
|
-
def days() seconds * PER_DAY end
|
145
|
-
def weeks() seconds * PER_DAY * 7 end
|
146
|
-
def years() seconds * PER_DAY * 365 end
|
147
|
-
|
148
|
-
def in_years() seconds / PER_DAY / 365 end
|
149
|
-
def in_weeks() seconds / PER_DAY / 7 end
|
150
|
-
def in_days() seconds / PER_DAY end
|
151
|
-
def in_hours() seconds / PER_HOUR end
|
152
|
-
def in_minutes() seconds / PER_MINUTE end
|
153
|
-
def in_milliseconds() seconds / PER_MILLISECOND end
|
154
|
-
def in_microseconds() seconds / PER_MICROSECOND end
|
155
|
-
|
156
|
-
def in_seconds(u=nil)
|
157
|
-
case u.to_s
|
158
|
-
when /\A(y)|(years?)\z/
|
159
|
-
years
|
160
|
-
when /\A(w)|(weeks?)\z/
|
161
|
-
weeks
|
162
|
-
when /\A(d)|(days?)\z/
|
163
|
-
days
|
164
|
-
when /\A(h)|(hours?)\z/
|
165
|
-
hours
|
166
|
-
when /\A(m)|(minutes?)\z/
|
167
|
-
minutes
|
168
|
-
when /\A(ms)|(milliseconds?)\z/
|
169
|
-
milliseconds
|
170
|
-
when /\A(us)|(microseconds?)|(μs)\z/
|
171
|
-
microseconds
|
172
|
-
else
|
173
|
-
self
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
## JRuby doesn't like using instance_methods.select here.
|
178
|
-
## It could be a bug or something quirky with Attic
|
179
|
-
## (although it works in 1.8 and 1.9). The error:
|
180
|
-
##
|
181
|
-
## lib/attic.rb:32:in `select': yield called out of block (LocalJumpError)
|
182
|
-
## lib/stella/mixins/numeric.rb:24
|
183
|
-
##
|
184
|
-
## Create singular methods, like hour and day.
|
185
|
-
# instance_methods.select.each do |plural|
|
186
|
-
# singular = plural.to_s.chop
|
187
|
-
# alias_method singular, plural
|
188
|
-
# end
|
189
|
-
|
190
|
-
alias_method :ms, :milliseconds
|
191
|
-
alias_method :'μs', :microseconds
|
192
|
-
alias_method :second, :seconds
|
193
|
-
alias_method :minute, :minutes
|
194
|
-
alias_method :hour, :hours
|
195
|
-
alias_method :day, :days
|
196
|
-
alias_method :week, :weeks
|
197
|
-
alias_method :year, :years
|
198
|
-
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
class Numeric
|
203
|
-
include Time::Units
|
204
|
-
# TODO: Use 1024?
|
205
|
-
def to_bytes
|
206
|
-
args = case self.abs.to_i
|
207
|
-
when 0..1000
|
208
|
-
[(self).to_s, 'B']
|
209
|
-
when (1000)..(1000**2)
|
210
|
-
[(self / 1000.to_f).to_s, 'KB']
|
211
|
-
when (1000**2)..(1000**3)
|
212
|
-
[(self / (1000**2).to_f).to_s, 'MB']
|
213
|
-
when (1000**3)..(1000**4)
|
214
|
-
[(self / (1000**3).to_f).to_s, 'GB']
|
215
|
-
when (1000**4)..(1000**6)
|
216
|
-
[(self / (1000**4).to_f).to_s, 'TB']
|
217
|
-
else
|
218
|
-
[self, 'B']
|
219
|
-
end
|
220
|
-
'%3.2f%s' % args
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
class Stella::Config < Storable
|
229
|
-
include Gibbler::Complex
|
230
|
-
|
231
|
-
field :source
|
232
|
-
field :apikey
|
233
|
-
field :secret
|
234
|
-
|
235
|
-
# Returns true when the current config matches the default config
|
236
|
-
def default?; to_hash.gibbler == DEFAULT_CONFIG_HASH; end
|
237
|
-
|
238
|
-
def self.each_path(&blk)
|
239
|
-
[PROJECT_PATH, USER_PATH].each do |path|
|
240
|
-
Stella.ld "Loading #{path}"
|
241
|
-
blk.call(path) if File.exists? path
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
def self.refresh
|
246
|
-
conf = {}
|
247
|
-
Stella::Config.each_path do |path|
|
248
|
-
tmp = YAML.load_file path
|
249
|
-
conf.merge! tmp if tmp
|
250
|
-
end
|
251
|
-
a = from_hash conf
|
252
|
-
a || new
|
253
|
-
end
|
254
|
-
|
255
|
-
def self.init
|
256
|
-
raise AlreadyInitialized, PROJECT_PATH if File.exists? PROJECT_PATH
|
257
|
-
dir = File.dirname USER_PATH
|
258
|
-
Dir.mkdir(dir, 0700) unless File.exists? dir
|
259
|
-
unless File.exists? USER_PATH
|
260
|
-
Stella.stdout.info "Creating #{USER_PATH} (Add your credentials here)"
|
261
|
-
Stella::Utils.write_to_file(USER_PATH, DEFAULT_CONFIG, 'w', 0600)
|
262
|
-
end
|
263
|
-
|
264
|
-
dir = File.dirname PROJECT_PATH
|
265
|
-
Dir.mkdir(dir, 0700) unless File.exists? dir
|
266
|
-
|
267
|
-
Stella.stdout.info "Creating #{PROJECT_PATH}"
|
268
|
-
Stella::Utils.write_to_file(PROJECT_PATH, 'target:', 'w', 0600)
|
269
|
-
end
|
270
|
-
|
271
|
-
def self.blast
|
272
|
-
if File.exists? USER_PATH
|
273
|
-
Stella.stdout.info "Blasting #{USER_PATH}"
|
274
|
-
FileUtils.rm_rf File.dirname(USER_PATH)
|
275
|
-
end
|
276
|
-
if File.exists? PROJECT_PATH
|
277
|
-
Stella.stdout.info "Blasting #{PROJECT_PATH}"
|
278
|
-
FileUtils.rm_rf File.dirname(PROJECT_PATH)
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
def self.project_dir
|
283
|
-
File.join(Dir.pwd, DIR_NAME)
|
284
|
-
end
|
285
|
-
|
286
|
-
private
|
287
|
-
|
288
|
-
def self.find_project_config
|
289
|
-
dir = Dir.pwd.split File::SEPARATOR
|
290
|
-
path = nil
|
291
|
-
while !dir.empty?
|
292
|
-
tmp = File.join(dir.join(File::SEPARATOR), DIR_NAME, 'config')
|
293
|
-
Stella.ld " -> looking for #{tmp}"
|
294
|
-
path = tmp and break if File.exists? tmp
|
295
|
-
dir.pop
|
296
|
-
end
|
297
|
-
path ||= File.join(Dir.pwd, DIR_NAME, 'config')
|
298
|
-
path
|
299
|
-
end
|
300
|
-
|
301
|
-
|
302
|
-
unless defined?(DIR_NAME)
|
303
|
-
if Stella.sysinfo.os == :windows
|
304
|
-
DIR_NAME = 'Stella'
|
305
|
-
USER_PATH = File.join(Stella.sysinfo.home, DIR_NAME, 'config.txt')
|
306
|
-
else
|
307
|
-
DIR_NAME = '.stella'
|
308
|
-
USER_PATH = File.join(Stella.sysinfo.home, DIR_NAME, 'config')
|
309
|
-
end
|
310
|
-
PROJECT_PATH = Stella::Config.find_project_config
|
311
|
-
DEFAULT_CONFIG = ""
|
312
|
-
DEFAULT_CONFIG_HASH = YAML.load(DEFAULT_CONFIG).gibbler
|
313
|
-
end
|
314
|
-
|
315
|
-
class AlreadyInitialized < Stella::Error; end
|
316
|
-
end
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
module Stella
|
321
|
-
class Hand
|
322
|
-
attr_accessor :force_stop
|
323
|
-
attr_reader :dthread
|
324
|
-
|
325
|
-
def initialize(freq=4, rest=1, &routine)
|
326
|
-
@freq, @rest, @routine = freq, rest, routine
|
327
|
-
end
|
328
|
-
|
329
|
-
def stop()
|
330
|
-
@force_stop = true
|
331
|
-
@dthread.join
|
332
|
-
@routine.call
|
333
|
-
@finally.call unless @finally.nil?
|
334
|
-
end
|
335
|
-
def stop?() @force_stop == true end
|
336
|
-
|
337
|
-
def stopped?() @stopped end
|
338
|
-
|
339
|
-
# Execute yield every FREQUENCY seconds.
|
340
|
-
def start
|
341
|
-
@dthread ||= Thread.new do
|
342
|
-
prev_ptime = Time.now
|
343
|
-
loop do
|
344
|
-
@stopped = true and break if Stella.abort? || stop?
|
345
|
-
if (Time.now - prev_ptime).to_i >= @freq
|
346
|
-
@routine.call
|
347
|
-
prev_ptime = Time.now
|
348
|
-
end
|
349
|
-
sleep @rest
|
350
|
-
end
|
351
|
-
end
|
352
|
-
@dthread.abort_on_exception = true
|
353
|
-
end
|
354
|
-
|
355
|
-
def finally(&blk)
|
356
|
-
@finally = blk
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
|
-
|
361
|
-
end
|
362
|
-
|
363
|
-
|
data/lib/stella/data.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
|
2
|
-
module Stella::Data
|
3
|
-
extend self
|
4
|
-
|
5
|
-
module Helpers
|
6
|
-
|
7
|
-
def resource(args) to_templ(:resource, *args) end
|
8
|
-
|
9
|
-
# Can include glob
|
10
|
-
#
|
11
|
-
# e.g.
|
12
|
-
# random_file('avatar*')
|
13
|
-
def random_file(*args) to_templ(:random_file, *args) end
|
14
|
-
|
15
|
-
def read_file(*args) to_templ(:read_file, *args) end
|
16
|
-
|
17
|
-
def path(*args) to_templ(:path, *args) end
|
18
|
-
|
19
|
-
def file(*args) to_templ(:file, *args) end
|
20
|
-
|
21
|
-
def random(*args)
|
22
|
-
to_templ(:random, *args)
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
# NOTE: This is global across all users
|
27
|
-
def sequential(*args)
|
28
|
-
to_templ(:sequential, *args)
|
29
|
-
end
|
30
|
-
|
31
|
-
# NOTE: This is global across all users
|
32
|
-
def rsequential(*args)
|
33
|
-
to_templ(:rsequential, *args)
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def args_to_str(*args)
|
39
|
-
args.collect! do |el|
|
40
|
-
if el.kind_of?(Enumerable) || el.kind_of?(Numeric)
|
41
|
-
el.inspect
|
42
|
-
elsif el.is_a?(Symbol)
|
43
|
-
":#{el.to_s}"
|
44
|
-
else
|
45
|
-
"'#{el.to_s}'"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
args.join(', ')
|
49
|
-
end
|
50
|
-
|
51
|
-
def to_templ(meth, *args)
|
52
|
-
"<%= #{meth}(#{args_to_str(*args)}) %>"
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
Stella::Utils.require_glob(STELLA_LIB_HOME, 'stella', 'data', '*.rb')
|
data/lib/stella/data/http.rb
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Stella::Data::HTTP
|
4
|
-
class Request < Storable
|
5
|
-
include Gibbler::Complex
|
6
|
-
include Stella::Data::Helpers
|
7
|
-
|
8
|
-
field :id => String, &gibbler_id_processor
|
9
|
-
|
10
|
-
# A hash containing blocks to be executed depending on the HTTP response status.
|
11
|
-
# The hash keys are numeric HTTP Status Codes.
|
12
|
-
#
|
13
|
-
# 200 => { ... }
|
14
|
-
# 304 => { ... }
|
15
|
-
# 500 => { ... }
|
16
|
-
#
|
17
|
-
field :response_handler => Hash, &hash_proc_processor
|
18
|
-
|
19
|
-
# Store the description in the attic so
|
20
|
-
# it's not used in the gibbler digest.
|
21
|
-
attic :description
|
22
|
-
field :description
|
23
|
-
|
24
|
-
field :header => Hash
|
25
|
-
field :uri
|
26
|
-
field :wait => Range
|
27
|
-
field :params => Hash
|
28
|
-
field :body
|
29
|
-
field :http_method
|
30
|
-
field :http_version
|
31
|
-
field :content_type
|
32
|
-
field :http_auth
|
33
|
-
field :timeout => Float
|
34
|
-
|
35
|
-
field :autofollow # boolean. Was this an auto generated follow request.
|
36
|
-
|
37
|
-
|
38
|
-
def has_body?
|
39
|
-
!@body.nil?
|
40
|
-
end
|
41
|
-
|
42
|
-
def id
|
43
|
-
Gibbler::Digest.new @id || self.digest
|
44
|
-
end
|
45
|
-
|
46
|
-
def initialize (method=nil, uri_str=nil, version="1.1", &definition)
|
47
|
-
@uri = uri_str.to_s
|
48
|
-
@http_method, @http_version = method, version
|
49
|
-
@header, @params, @response_handler = {}, {}, {}
|
50
|
-
@resources = {}
|
51
|
-
@autofollow = false
|
52
|
-
@wait = 0..0
|
53
|
-
self.description = "Request"
|
54
|
-
instance_eval &definition unless definition.nil?
|
55
|
-
end
|
56
|
-
|
57
|
-
def autofollow!
|
58
|
-
@autofollow = true
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.from_hash(hash={})
|
62
|
-
me = super(hash)
|
63
|
-
me.response_handler.keys.each do |status|
|
64
|
-
proc_str = me.response_handler[status]
|
65
|
-
me.response_handler[status] = eval "Proc.new #{proc_str}"
|
66
|
-
me.response_handler[status].source = proc_str
|
67
|
-
end
|
68
|
-
me
|
69
|
-
end
|
70
|
-
|
71
|
-
def auth(user=nil, pass=nil, domain=nil)
|
72
|
-
@http_auth ||= Stella::Testplan::Usecase::Auth.new
|
73
|
-
@http_auth.user, @http_auth.pass, @http_auth.domain = user, pass, domain
|
74
|
-
end
|
75
|
-
|
76
|
-
def timeout(*args)
|
77
|
-
@timeout = args.first unless args.empty?
|
78
|
-
@timeout
|
79
|
-
end
|
80
|
-
|
81
|
-
def desc(*args)
|
82
|
-
self.description = args.first unless args.empty?
|
83
|
-
self.description
|
84
|
-
end
|
85
|
-
|
86
|
-
def content_type(*args)
|
87
|
-
@content_type = args.first unless args.empty?
|
88
|
-
@content_type
|
89
|
-
end
|
90
|
-
|
91
|
-
def wait(*args)
|
92
|
-
args = [args].flatten.compact
|
93
|
-
@wait = args.first unless args.empty?
|
94
|
-
@wait
|
95
|
-
end
|
96
|
-
alias_method :sleep, :wait
|
97
|
-
|
98
|
-
def headers(*args)
|
99
|
-
args = [args].flatten.compact
|
100
|
-
unless args.empty?
|
101
|
-
h = Hash === args[0] ? args[0] : {args[0]=> args[1]}
|
102
|
-
@header.merge! h unless h.empty?
|
103
|
-
end
|
104
|
-
@header
|
105
|
-
end
|
106
|
-
alias_method :header, :headers
|
107
|
-
|
108
|
-
# Set a resource key value pair in the get, post block.
|
109
|
-
# These will be process later in Stella::Client
|
110
|
-
def set(*args)
|
111
|
-
args = [args].flatten.compact
|
112
|
-
unless args.empty?
|
113
|
-
h = Hash === args[0] ? args[0] : {args[0]=> args[1]}
|
114
|
-
@resources.merge! h unless h.empty?
|
115
|
-
end
|
116
|
-
@resources
|
117
|
-
end
|
118
|
-
alias_method :resources, :set
|
119
|
-
|
120
|
-
def params(*args)
|
121
|
-
args = [args].flatten.compact
|
122
|
-
unless args.empty?
|
123
|
-
h = Hash === args[0] ? args[0] : {args[0]=> args[1]}
|
124
|
-
@params.merge! h unless h.empty?
|
125
|
-
end
|
126
|
-
@params
|
127
|
-
end
|
128
|
-
alias_method :param, :params
|
129
|
-
|
130
|
-
def response(*args, &definition)
|
131
|
-
if definition.nil?
|
132
|
-
@response_handler
|
133
|
-
else
|
134
|
-
args << /.+/ if args.empty?
|
135
|
-
args.each do |status|
|
136
|
-
@response_handler[status] = definition
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
# +content+ can be literal content or a file path
|
142
|
-
def body(*args)
|
143
|
-
return @body if args.empty?
|
144
|
-
@body = args.first
|
145
|
-
end
|
146
|
-
|
147
|
-
def inspect
|
148
|
-
str = "%s %s" % [http_method, uri.to_s, http_version]
|
149
|
-
#str << $/ + headers.join($/) unless headers.empty?
|
150
|
-
#str << $/ + $/ + body.to_s if body
|
151
|
-
str
|
152
|
-
end
|
153
|
-
|
154
|
-
def to_s
|
155
|
-
str = "%s %s" % [http_method, uri.to_s, http_version]
|
156
|
-
str
|
157
|
-
end
|
158
|
-
|
159
|
-
def cookies
|
160
|
-
return [] if !header.is_a?(Hash) || header[:Cookie].empty?
|
161
|
-
header[:Cookie]
|
162
|
-
end
|
163
|
-
|
164
|
-
def freeze
|
165
|
-
return if frozen?
|
166
|
-
@params = convert_values_to_templates @params
|
167
|
-
@header = convert_values_to_templates @header
|
168
|
-
super
|
169
|
-
self
|
170
|
-
end
|
171
|
-
|
172
|
-
private
|
173
|
-
def convert_values_to_templates(hash)
|
174
|
-
updated = {}
|
175
|
-
hash.each_pair { |k,v|
|
176
|
-
next if Stella::Template === v
|
177
|
-
if Proc === v
|
178
|
-
msg = "As of Stella 0.8, Procs are no longer supported as values#{$/}"
|
179
|
-
msg << "for parameters and headers (\"#{k}\" in \"#{description}\").#{$/}"
|
180
|
-
msg << "Use string templates instead. See the examples/ directory."
|
181
|
-
raise Stella::Error, msg
|
182
|
-
end
|
183
|
-
updated[k] = Stella::Template.new( v || '')
|
184
|
-
}
|
185
|
-
updated
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|