Class: Crowbar::Client::Request::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/crowbar/client/request/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Base

Returns a new instance of Base.



26
27
28
# File 'lib/crowbar/client/request/base.rb', line 26

def initialize(attrs = {})
  self.attrs = Hashie::Mash.new(attrs)
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs.



24
25
26
# File 'lib/crowbar/client/request/base.rb', line 24

def attrs
  @attrs
end

#requestObject

Returns the value of attribute request.



23
24
25
# File 'lib/crowbar/client/request/base.rb', line 23

def request
  @request
end

Instance Method Details

#contentObject



34
35
36
# File 'lib/crowbar/client/request/base.rb', line 34

def content
  @content ||= {}
end

#headersObject



38
39
40
# File 'lib/crowbar/client/request/base.rb', line 38

def headers
  @headers ||= {}
end

#paramsObject



42
43
44
45
46
47
48
49
50
# File 'lib/crowbar/client/request/base.rb', line 42

def params
  headers["Content-Type"] ||= "application/json"
  headers["Accept"] ||= "application/json"

  {
    body: content.to_json,
    headers: headers
  }
end

#processObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/crowbar/client/request/base.rb', line 52

def process
  result = request.send(
    method,
    [
      "/",
      url
    ].join(""),
    params
  )

  if block_given?
    yield result
  else
    result
  end
end