Skip to content

Commit

Permalink
(#81) Add ZAP Deliver Model
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Sep 18, 2023
1 parent fadccef commit 881393e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spec/unit_test/models/delivers/zap_spec.cr
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions src/models/delivers/zap.cr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 881393e

Please sign in to comment.