Class: LieDetector::Request
- Inherits:
-
Object
- Object
- LieDetector::Request
- Defined in:
- lib/liedetector/request.rb
Instance Method Summary collapse
- #await(trafaret) ⇒ Object
- #call ⇒ Object
- #describe ⇒ Object
-
#initialize(suite) ⇒ Request
constructor
A new instance of Request.
- #store(name) ⇒ Object
Constructor Details
#initialize(suite) ⇒ Request
Returns a new instance of Request.
3 4 5 |
# File 'lib/liedetector/request.rb', line 3 def initialize(suite) @suite = suite end |
Instance Method Details
#await(trafaret) ⇒ Object
22 23 24 |
# File 'lib/liedetector/request.rb', line 22 def await(trafaret) @trafaret = T.construct(trafaret) end |
#call ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/liedetector/request.rb', line 34 def call res = @suite.session.send( get_method, @suite.build_uri(get_path, query: get_query), get_data, @suite.headers_defaults.merge(get_headers || {}) ) unless res.status == get_status raise "Bad status(#{get_status} != #{res.status}): #{res.inspect}" end check = @trafaret.call(Oj.load(res.content)) if check.is_a? Trafaret::Error raise "Unmatched data #{check.dump} #{res.content}" end @suite.store_key(@store_key, check) if @store_key end |
#describe ⇒ Object
26 27 28 |
# File 'lib/liedetector/request.rb', line 26 def describe "#{@description}\nExecute #{@method.to_s.upcase} #{get_path}\n" end |
#store(name) ⇒ Object
30 31 32 |
# File 'lib/liedetector/request.rb', line 30 def store(name) @store_key = name end |