Class: ZAP::API
- Inherits:
-
Object
- Object
- ZAP::API
- Defined in:
- lib/zap/zap.rb
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(endpoint, apikey) ⇒ API
constructor
A new instance of API.
- #post(path, data) ⇒ Object
- #put(path, data) ⇒ Object
Constructor Details
#initialize(endpoint, apikey) ⇒ API
Returns a new instance of API.
17 18 19 20 21 |
# File 'lib/zap/zap.rb', line 17 def initialize(endpoint, apikey) @url = URI.parse(endpoint) @http = Net::HTTP.new(@url.host, @url.port) @apikey = apikey end |
Instance Method Details
#delete(path) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/zap/zap.rb', line 44 def delete(path) request = build_request(Net::HTTP::Delete, path) response = send_request(request) if response.code == '200' Result.new(true, response.body) else Result.new(false, response.body) end end |
#get(path) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/zap/zap.rb', line 23 def get(path) request = build_request(Net::HTTP::Get, path) response = send_request(request) if response.code == '200' Result.new(true, response.body) else Result.new(false, response.body) end end |
#post(path, data) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/zap/zap.rb', line 33 def post(path, data) request = build_request(Net::HTTP::Post, path) request.set_form_data(data) response = send_request(request) if response.code == '200' Result.new(true, response.body) else Result.new(false, response.body) end end |
#put(path, data) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/zap/zap.rb', line 54 def put(path, data) request = build_request(Net::HTTP::Put, path) request.set_form_data(data) response = send_request(request) if response.code == '200' Result.new(true, response.body) else Result.new(false, response.body) end end |