Class: Seiso::Connector::ConnectorV1
- Inherits:
-
Object
- Object
- Seiso::Connector::ConnectorV1
- Defined in:
- lib/seiso/connector/connector_v1.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #do_get(path) ⇒ Object
- #do_post(path, data) ⇒ Object
- #do_put(path, data) ⇒ Object
-
#initialize(http, username, password) ⇒ ConnectorV1
constructor
A new instance of ConnectorV1.
Constructor Details
#initialize(http, username, password) ⇒ ConnectorV1
Returns a new instance of ConnectorV1.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/seiso/connector/connector_v1.rb', line 12 def initialize(http, username, password) @http = http @username = username @password = password @request_headers = { "Accept" => "application/json", "Content-Type" => "application/json", "X-User-Agent" => username } end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
9 10 11 |
# File 'lib/seiso/connector/connector_v1.rb', line 9 def http @http end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/seiso/connector/connector_v1.rb', line 10 def username @username end |
Instance Method Details
#do_get(path) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/seiso/connector/connector_v1.rb', line 23 def do_get(path) request = Net::HTTP::Get.new(path, initheader = @request_headers) request.basic_auth(@username, @password) response = @http.request(request) raise(Seiso::Connector::RequestFailedError, response.body) if !response.kind_of?(Net::HTTPSuccess) JSON.parse(response.body) end |
#do_post(path, data) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/seiso/connector/connector_v1.rb', line 31 def do_post(path, data) puts "POST #{path}" request = Net::HTTP::Post.new(path, initheader = @request_headers) request.basic_auth(@username, @password) request.body = data.to_json response = @http.request(request) display_response(response) end |
#do_put(path, data) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/seiso/connector/connector_v1.rb', line 40 def do_put(path, data) puts "PUT #{path}" request = Net::HTTP::Put.new(path, initheader = @request_headers) request.basic_auth(@username, @password) request.body = data.to_json response = @http.request(request) display_response(response) end |