This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from michaeldcanady/task/restructure
beginning
- Loading branch information
Showing
23 changed files
with
158 additions
and
1,270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.