Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from michaeldcanady/task/restructure
Browse files Browse the repository at this point in the history
beginning
  • Loading branch information
michaeldcanady committed Aug 13, 2023
2 parents 74ba7b4 + 4a3d67a commit dcd6676
Show file tree
Hide file tree
Showing 23 changed files with 158 additions and 1,270 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: "^1.20"

- name: Build
run: go build -v ./...
Expand Down
8 changes: 8 additions & 0 deletions api_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gosnow

type ApiVersion int64

const (
v1 ApiVersion = 1
v2 ApiVersion = 2
)
46 changes: 46 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gosnow

import (
"encoding/json"
"net/http"
"strings"
)

type Client struct {
Credential UsernamePasswordCredential
BaseUrl string
Session http.Client
Decoder json.Decoder
Encoder json.Encoder
}

func NewClient(credential UsernamePasswordCredential, baseUrl string) *Client {

if !strings.HasSuffix(baseUrl, ".service-now.com") {
baseUrl += ".service-now.com"
}

return &Client{
Credential: credential,
BaseUrl: baseUrl,
Session: http.Client{},
}
}

func (C *Client) Now() *NowRequestBuilder {
return NewNowRequestBuilder(C.BaseUrl+"/now", C)
}

func (C *Client) Get(url string, target interface{}) error {
request, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
}
request.Header.Add("Authorization", C.Credential.GetAuthentication())
resp, err := C.Session.Do(request)
if err != nil {
return err
}

return json.NewDecoder(resp.Body).Decode(target)
}
15 changes: 15 additions & 0 deletions credential.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gosnow

import "encoding/base64"

type Credential struct {
}

func NewCredential() *Credential {
return &Credential{}
}

func (C *Credential) BasicAuth(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
}
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module github.com/michaeldcanady/gosnow/v6

go 1.19
go 1.20

require github.com/levigross/grequests v0.0.0-20190908174114-253788527a1a
require github.com/michaeldcanady/gosnow v0.0.0-20220816185538-876d7d991ad4

require (
github.com/google/go-querystring v1.0.0 // indirect
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 // indirect
github.com/levigross/grequests v0.0.0-20190908174114-253788527a1a // indirect
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
)
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASu
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/levigross/grequests v0.0.0-20190908174114-253788527a1a h1:DGFy/362j92vQRE3ThU1yqg9TuJS8YJOSbQuB7BP9cA=
github.com/levigross/grequests v0.0.0-20190908174114-253788527a1a/go.mod h1:jVntzcUU+2BtVohZBQmSHWUmh8B55LCNfPhcNCIvvIg=
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 h1:Y/KGZSOdz/2r0WJ9Mkmz6NJBusp0kiNx1Cn82lzJQ6w=
github.com/michaeldcanady/gosnow v0.0.0-20220816185538-876d7d991ad4 h1:zRzjQ1ut2beDUi3mzSXi5WJWbrD/B71ItWqwkFjSvT0=
github.com/michaeldcanady/gosnow v0.0.0-20220816185538-876d7d991ad4/go.mod h1:/CFL0C+MJWhhNdOcuyIMbF/UcmJmb+ixKPaBRNJPFSk=
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
59 changes: 0 additions & 59 deletions gosnow/Errors.go

This file was deleted.

164 changes: 0 additions & 164 deletions gosnow/Request.go

This file was deleted.

Loading

0 comments on commit dcd6676

Please sign in to comment.