Skip to content

Commit

Permalink
Merge pull request #101 from hahwul/hahwul-dev
Browse files Browse the repository at this point in the history
(#81) Add ZAP Deliver Model
  • Loading branch information
hahwul authored Sep 21, 2023
2 parents 27ad9bb + 881393e commit de0b3f2
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 de0b3f2

Please sign in to comment.