-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f121cad
commit 3a29300
Showing
1 changed file
with
63 additions
and
0 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
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}) | ||
} |