From 3053714678479f3ffb2b1d963c34290b88e6dbba Mon Sep 17 00:00:00 2001 From: Tyler Date: Thu, 3 Oct 2019 20:50:58 -0400 Subject: [PATCH] Add readme, badge, resolve issue with test --- README.md | 7 +++++++ default_test.go | 2 +- linkinfo.go | 13 ++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5a49c42 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +LinkInfo +-------- + +[![Build Status](https://drone.meow.tf/api/badges/tyler/linkinfo/status.svg)](https://drone.meow.tf/tyler/linkinfo) + +An API/Library to get link information (Title, Description, etc) + diff --git a/default_test.go b/default_test.go index 8c72091..e2e7420 100644 --- a/default_test.go +++ b/default_test.go @@ -16,7 +16,7 @@ func Test_detectContentType(t *testing.T) { contentType = contentType[:idx] } - if contentType != ContentTypeHtml { + if contentType != contentTypeHtml { t.Fatal("Unexpected content type:", contentType) } } diff --git a/linkinfo.go b/linkinfo.go index ef8f007..fa4268f 100644 --- a/linkinfo.go +++ b/linkinfo.go @@ -10,6 +10,11 @@ type linkHandler struct { handler func(link string) (*LinkInfo, error) } +type LinkInfoApi struct { + client *http.Client + ImgurId string +} + type LinkInfo struct { Title string `json:"title"` Description string `json:"description"` @@ -20,14 +25,16 @@ type LinkInfo struct { } var ( - Client = http.DefaultClient - linkHandlers = []*linkHandler{ {hosts: []string{"youtube.com", "youtu.be"}, handler: youtubeLinkHandler}, } ) -func Retrieve(link string) (*LinkInfo, error) { +func New() *LinkInfoApi { + return &LinkInfoApi{} +} + +func (i *LinkInfoApi) Retrieve(link string) (*LinkInfo, error) { u, err := url.Parse(link) if err != nil {