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

Add /tsm.recipes #51

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ install:
go install ./...

lint:
golint github.com/russellcardullo/go-pingdom/pingdom
golint github.com/strike-team/go-pingdom/pingdom

test:
go test github.com/russellcardullo/go-pingdom/pingdom
go test github.com/strike-team/go-pingdom/pingdom

acceptance:
PINGDOM_ACCEPTANCE=1 go test github.com/russellcardullo/go-pingdom/acceptance
PINGDOM_ACCEPTANCE=1 go test github.com/strike-team/go-pingdom/acceptance

cov:
go test github.com/russellcardullo/go-pingdom/pingdom -coverprofile=coverage.out
go test github.com/strike-team/go-pingdom/pingdom -coverprofile=coverage.out
go tool cover -func=coverage.out
rm coverage.out

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# go-pingdom #

[![Build Status](https://travis-ci.org/russellcardullo/go-pingdom.svg?branch=master)](https://travis-ci.org/russellcardullo/go-pingdom) [![Go Report Card](https://goreportcard.com/badge/github.com/russellcardullo/go-pingdom/pingdom)](https://goreportcard.com/report/github.com/russellcardullo/go-pingdom/pingdom) [![GoDoc](https://godoc.org/github.com/russellcardullo/go-pingdom/pingdom?status.svg)](https://godoc.org/github.com/russellcardullo/go-pingdom/pingdom)
[![Build Status](https://travis-ci.org/strike-team/go-pingdom.svg?branch=master)](https://travis-ci.org/strike-team/go-pingdom) [![Go Report Card](https://goreportcard.com/badge/github.com/strike-team/go-pingdom/pingdom)](https://goreportcard.com/report/github.com/strike-team/go-pingdom/pingdom) [![GoDoc](https://godoc.org/github.com/strike-team/go-pingdom/pingdom?status.svg)](https://godoc.org/github.com/strike-team/go-pingdom/pingdom)

go-pingdom is a Go client library for the Pingdom API.

Expand Down Expand Up @@ -285,8 +285,8 @@ _, err := client.PublicReport.WithdrawlCheck(12345)

### UserService ###

This service manages users and their contact information which is represented by the `User` struct.
When creating or modifying users you must provide the `Username`.
This service manages users and their contact information which is represented by the `User` struct.
When creating or modifying users you must provide the `Username`.
More information from Pingdom: https://www.pingdom.com/resources/api/2.1/#ResourceUsers

Get all users and contact info:
Expand All @@ -302,7 +302,7 @@ Create a new user and contact:
user := User{
Username : "loginName",
Paused : "NO",
}
}
userId, err := client.Users.Create(user)
fmt.Println("New UserId: ", userId.Id)

Expand All @@ -324,7 +324,7 @@ contactId := 90877
user := User{
Username : "loginName",
Paused : "NO",
}
}
result, err := client.Users.Update(userId, user)
fmt.Println("result.Message)

Expand Down Expand Up @@ -357,7 +357,7 @@ fmt.Println("result.Message)

You can run acceptance tests against the actual pingdom API to test any changes:
```
PINGDOM_USER=[username] \
PINGDOM_USER=[username] \
PINGDOM_PASSWORD=[password] \
PINGDOM_API_KEY=[api key] make acceptance
```
Expand Down
2 changes: 1 addition & 1 deletion acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/russellcardullo/go-pingdom/pingdom"
"github.com/strike-team/go-pingdom/pingdom"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/russellcardullo/go-pingdom
module github.com/strike-team/go-pingdom

require (
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
16 changes: 16 additions & 0 deletions pingdom/api_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ type MaintenanceCheckResponse struct {
Tms []int `json:"tms"`
}

// TmsResponse represents the JSON response for a check from the Pingdom API.
type TmsResponse struct {
Name string `json:"name"`
Status string `json:"status"`
Kitchen string `json:"kitchen"`
Active string `json:"active"`
CreatedAt int64 `json:"created_at"`
Interval int `json:"interval"`
UseLegacyNotifications bool `json:"use_legacy_notifications,omitempty"`
Tags []CheckResponseTag `json:"tags,omitempty"`
}

// ProbeResponse represents the JSON response for probes from the Pingdom API.
type ProbeResponse struct {
ID int `json:"id"`
Expand Down Expand Up @@ -258,6 +270,10 @@ type listChecksJSONResponse struct {
Checks []CheckResponse `json:"checks"`
}

type listTmsJSONResponse struct {
Tms map[int]TmsResponse `json:"recipes"`
}

type listMaintenanceJSONResponse struct {
Maintenances []MaintenanceResponse `json:"maintenance"`
}
Expand Down
2 changes: 2 additions & 0 deletions pingdom/pingdom.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Client struct {
Maintenances *MaintenanceService
Probes *ProbeService
Teams *TeamService
Tms *TmsService
PublicReport *PublicReportService
Users *UserService
}
Expand Down Expand Up @@ -71,6 +72,7 @@ func NewClientWithConfig(config ClientConfig) (*Client, error) {
c.Maintenances = &MaintenanceService{client: c}
c.Probes = &ProbeService{client: c}
c.Teams = &TeamService{client: c}
c.Tms = &TmsService{client: c}
c.PublicReport = &PublicReportService{client: c}
c.Users = &UserService{client: c}
return c, nil
Expand Down
41 changes: 41 additions & 0 deletions pingdom/tms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package pingdom

import (
"encoding/json"
"io/ioutil"
)

// TmsService provides an interface to Pingdom transactions.
type TmsService struct {
client *Client
}

// TODO
func (cs *TmsService) List(params ...map[string]string) (map[int]TmsResponse, error) {
param := map[string]string{}
if len(params) == 1 {
param = params[0]
}
req, err := cs.client.NewRequest("GET", "/tms.recipes", param)
if err != nil {
return nil, err
}

resp, err := cs.client.client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

if err := validateResponse(resp); err != nil {
return nil, err
}

bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyString := string(bodyBytes)

p := &listTmsJSONResponse{}
err = json.Unmarshal([]byte(bodyString), &p)

return p.Tms, err
}
60 changes: 60 additions & 0 deletions pingdom/tms_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package pingdom

import (
"fmt"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

func TestTmsServiceList(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/tms.recipes", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{
"recipes": [
{
"name": "example.com",
"status": "SUCCESSFUL",
"kitchen": "eu",
"active": "YES",
"created_at": 1560949555,
"interval": 5
},
{
"name": "mydomain.com",
"status": "SUCCESSFUL",
"kitchen": "us-west",
"active": "YES",
"created_at": 1560935224,
"interval": 5
}
]
}`)
})
want := []TmsResponse{
{
Name: "example.com",
Status: "SUCCESSFUL",
Kitchen: "eu",
Active: "YES",
CreatedAt: 1560949555,
Interval: 5,
},
{
Name: "mydomain.com",
Status: "SUCCESSFUL",
Kitchen: "us-west",
Active: "YES",
CreatedAt: 1560935224,
Interval: 5,
},
}

tms, err := client.Tms.List()
assert.NoError(t, err)
assert.Equal(t, want, tms, "Tms.List() should return correct result")
}