From 881393e58d46102d93e84d15a62cca9545b8592d Mon Sep 17 00:00:00 2001 From: hahwul Date: Tue, 19 Sep 2023 01:02:41 +0900 Subject: [PATCH] (#81) Add ZAP Deliver Model --- spec/unit_test/models/delivers/zap_spec.cr | 10 +++++++++ src/models/delivers/zap.cr | 26 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 spec/unit_test/models/delivers/zap_spec.cr create mode 100644 src/models/delivers/zap.cr diff --git a/spec/unit_test/models/delivers/zap_spec.cr b/spec/unit_test/models/delivers/zap_spec.cr new file mode 100644 index 00000000..3fc1c5f2 --- /dev/null +++ b/spec/unit_test/models/delivers/zap_spec.cr @@ -0,0 +1,10 @@ +require "../../../../src/models/delivers/zap.cr" +require "../../../../src/options.cr" + +describe "Initialize" do + zap = ZAP.new "http://localhost:8090" + + it "init" do + zap.nil?.should eq(false) + end +end diff --git a/src/models/delivers/zap.cr b/src/models/delivers/zap.cr new file mode 100644 index 00000000..445d02ac --- /dev/null +++ b/src/models/delivers/zap.cr @@ -0,0 +1,26 @@ +class ZAP + @endpoint : String + @apikey : String + + API_ACCESS = "/JSON/core/action/accessUrl" + + def initialize(@endpoint) + if ENV.keys.includes? "ZAP_API_KEY" + @apikey = ENV["ZAP_API_KEY"].to_s + else + @apikey = "" + end + end + + def add_url(url : String) + call(@endpoint + API_ACCESS + "?url=#{url}") + end + + def call(query : String) + if @apikey == "" + HTTP::Client.get(query) + else + HTTP::Client.get(query, headers: {"X-ZAP-API-Key" => @apikey}) + end + end +end