Class: Contracts::Request

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

Instance Method Summary collapse

Constructor Details

#initialize(host, definition) ⇒ Request

Returns a new instance of Request.



3
4
5
6
# File 'lib/contracts/request.rb', line 3

def initialize(host, definition)
  @host = host
  @definition = definition
end

Instance Method Details

#absolute_uriObject



32
33
34
# File 'lib/contracts/request.rb', line 32

def absolute_uri
  @host + path
end

#executeObject



45
46
47
48
49
50
51
# File 'lib/contracts/request.rb', line 45

def execute
  response = HTTParty.send(method, @host + path, {
    httparty_params_key => normalized_params,
    :headers => headers
  })
  ResponseAdapter.new(response)
end

#full_uriObject



36
37
38
39
40
41
42
43
# File 'lib/contracts/request.rb', line 36

def full_uri
  return absolute_uri if params.empty?

  uri = Addressable::URI.new
  uri.query_values = params

  absolute_uri + '?' + uri.query
end

#headersObject



24
25
26
# File 'lib/contracts/request.rb', line 24

def headers
  @definition['headers']
end

#hostObject



8
9
10
# File 'lib/contracts/request.rb', line 8

def host
  @host
end

#methodObject



12
13
14
# File 'lib/contracts/request.rb', line 12

def method
  @definition['method'].to_s.downcase.to_sym
end

#paramsObject



28
29
30
# File 'lib/contracts/request.rb', line 28

def params
  @definition['params']
end

#pathObject



16
17
18
# File 'lib/contracts/request.rb', line 16

def path
  @definition['path']
end

#path=(value) ⇒ Object



20
21
22
# File 'lib/contracts/request.rb', line 20

def path=(value)
  @definition['path'] = value
end