Class: Crowbar::Client::Request::Base
- Inherits:
-
Object
- Object
- Crowbar::Client::Request::Base
- Defined in:
- lib/crowbar/client/request/base.rb
Direct Known Subclasses
Crowbar::Client::Request::Barclamp::List, Crowbar::Client::Request::Batch::Build, Crowbar::Client::Request::Batch::Export, HostIP::Allocate, HostIP::Deallocate, Installer::Start, Installer::Status, Interface::Disable, Interface::Enable, Node::Action, Node::Delete, Node::List, Node::Rename, Node::Role, Node::Show, Node::Status, Node::Transition, Proposal::Commit, Proposal::Create, Proposal::Delete, Proposal::Dequeue, Proposal::Edit, Proposal::List, Proposal::Show, Proposal::Template, Repository::Activate, Repository::ActivateAll, Repository::Deactivate, Repository::DeactivateAll, Repository::List, Reset::Nodes, Reset::Proposal, Role::List, Role::Show, Server::Api, VirtualIP::Allocate, VirtualIP::Deallocate
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#request ⇒ Object
Returns the value of attribute request.
Instance Method Summary collapse
- #content ⇒ Object
- #headers ⇒ Object
-
#initialize(attrs = {}) ⇒ Base
constructor
A new instance of Base.
- #params ⇒ Object
- #process ⇒ Object
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
#attrs ⇒ Object
Returns the value of attribute attrs.
24 25 26 |
# File 'lib/crowbar/client/request/base.rb', line 24 def attrs @attrs end |
#request ⇒ Object
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
#content ⇒ Object
34 35 36 |
# File 'lib/crowbar/client/request/base.rb', line 34 def content @content ||= {} end |
#headers ⇒ Object
38 39 40 |
# File 'lib/crowbar/client/request/base.rb', line 38 def headers @headers ||= {} end |
#params ⇒ Object
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 |
#process ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/crowbar/client/request/base.rb', line 52 def process result = request.send( method, [ "/", url ].join(""), params ) case result.code when 500 raise InternalServerError, "An internal error occured" when 401 raise NotAuthorizedError, "User is not authorized" when 403 raise NotAuthorizedError, "User access is forbidden" end if block_given? yield result else result end end |