Skip to content

Commit

Permalink
status: Add InStatus as a provider
Browse files Browse the repository at this point in the history
  • Loading branch information
FelicianoTech committed Sep 20, 2024
1 parent f121cad commit 3a29300
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions arc/statuses/instatus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package statuses

import (
"fmt"
"net/http"
)

/*
* This file defines the structs and other components needed to represent a
* status page hosted by InstatusStatus.com.
*/

type inStatusPageField struct {
Name string `json:"name"`
URL string `url:"url"`
Status string `url:"status"`
}

type inStatusResponse struct {
Page *inStatusPageField `json:"page"`
}

/*
* inStatusPage represents the way to connect to the API and retrieve a
* response.
*/
type inStatusPage struct {
name string
apiURL string
data *inStatusResponse
}

/*
* Fetch pulls in a response from the API.
*/
func (p *inStatusPage) Fetch(c *http.Client) error {

return fetchJSON(c, p.apiURL, &p.data)
}

func (p *inStatusPage) Name() string {
return p.name
}

func (p *inStatusPage) URL() string {
return p.apiURL
}

func (p *inStatusPage) Status() (string, error) {

if p.data == nil {
return "", fmt.Errorf("Data hasn't been retrieved.")
}

return p.data.Page.Status, nil
}

/*
* RegisterStatusPageIOPage creates a new provider.
*/
func RegisterInStatusPage(name, apiURL string) error {
return registerPage(&inStatusPage{name: name, apiURL: apiURL})
}

0 comments on commit 3a29300

Please sign in to comment.