Class: Digto::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/digto.rb

Overview

Session

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, res) ⇒ Session

Returns a new instance of Session.



35
36
37
38
39
40
41
42
43
44
# File 'lib/digto.rb', line 35

def initialize(url, res)
  @url = res.headers['Digto-URL']
  @method = res.headers['Digto-Method']
  @headers = res.headers
  @body = res.body

  @api_url = url
  @res = res
  @done = false
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



33
34
35
# File 'lib/digto.rb', line 33

def body
  @body
end

#headersObject

Returns the value of attribute headers.



33
34
35
# File 'lib/digto.rb', line 33

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



33
34
35
# File 'lib/digto.rb', line 33

def method
  @method
end

#urlObject

Returns the value of attribute url.



33
34
35
# File 'lib/digto.rb', line 33

def url
  @url
end

Instance Method Details

#response(status = 200, headers = {}, data = { body: '' }) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/digto.rb', line 46

def response(status = 200, headers = {}, data = { body: '' })
  raise 'already sent response' if @done

  @done = true

  headers['Digto-ID'] = @res.headers['Digto-ID']
  headers['Digto-Status'] = status

  res = HTTP.headers(headers).post(@api_url, data)
  Digto.check_res_err(res)

  res
end