Class: Crowbar::Client::Request::Base
- Inherits:
-
Object
- Object
- Crowbar::Client::Request::Base
- Defined in:
- lib/crowbar/client/request/base.rb
Overview
Base that provides methods shared between request implementations
Direct Known Subclasses
Crowbar::Client::Request::Backup::Create, Crowbar::Client::Request::Backup::Delete, Crowbar::Client::Request::Backup::Download, Crowbar::Client::Request::Backup::List, Crowbar::Client::Request::Backup::Restore, Crowbar::Client::Request::Backup::Upload, Crowbar::Client::Request::Barclamp::List, Crowbar::Client::Request::Batch::Export, Cluster::List, Database::Connect, Database::Create, Database::Test, HostIP::Allocate, HostIP::Deallocate, Installer::Start, Installer::Status, Interface::Disable, Interface::Enable, Node::Action, Node::Delete, Node::Group, 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::Reset, Proposal::Show, Proposal::Template, Repository::Activate, Repository::ActivateAll, Repository::Deactivate, Repository::DeactivateAll, Repository::List, Restricted::Allocate, Restricted::Ping, Restricted::Show, Restricted::Transition, Role::List, Role::Show, Server::Api, Server::Check, Services::ClearServiceRestart, Services::ListRestartFlags, Services::ListServiceRestarts, Services::SetRestartFlag, Ses::Upload, Upgrade::Admin, Upgrade::Backup, Upgrade::Cancel, Upgrade::Database, Upgrade::Mode, Upgrade::Nodes, Upgrade::Prechecks, Upgrade::Prepare, Upgrade::Repocheck, Upgrade::Services, Upgrade::Status, 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.
29 30 31 |
# File 'lib/crowbar/client/request/base.rb', line 29 def initialize(attrs = {}) self.attrs = Hashie::Mash.new(attrs) end |
Instance Attribute Details
#attrs ⇒ Object
Returns the value of attribute attrs.
27 28 29 |
# File 'lib/crowbar/client/request/base.rb', line 27 def attrs @attrs end |
#request ⇒ Object
Returns the value of attribute request.
26 27 28 |
# File 'lib/crowbar/client/request/base.rb', line 26 def request @request end |
Instance Method Details
#content ⇒ Object
37 38 39 |
# File 'lib/crowbar/client/request/base.rb', line 37 def content @content ||= {} end |
#headers ⇒ Object
41 42 43 44 45 46 |
# File 'lib/crowbar/client/request/base.rb', line 41 def headers @headers ||= { "Content-Type" => "application/json", "Accept" => "application/json" } end |
#params ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/crowbar/client/request/base.rb', line 48 def params case method when :post [ method, content ] when :put [ method, content.to_json ] else [ method ] end end |
#process ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/crowbar/client/request/base.rb', line 67 def process result = begin request.send( *params, accept: headers["Accept"], content_type: headers["Content-Type"] ) rescue => e if e.class.superclass == RestClient::RequestFailed Hashie::Mash.new( parsed_response: { error: e.response }, code: e.http_code ) else raise e end end if block_given? yield result else result end end |