B: Working on jsonapi things
This commit is contained in:
parent
6f1ce7dcc1
commit
6f308e5e23
|
@ -1,3 +1,6 @@
|
|||
[submodule "libs/oauth2"]
|
||||
path = libs/oauth2
|
||||
url = https://git.preston-baxter.com/Preston_PLB/oauth2.git
|
||||
[submodule "libs/jsonapi"]
|
||||
path = libs/jsonapi
|
||||
url = https://git.preston-baxter.com/Preston_PLB/jsonapi.git
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 1e07b10d47d02b07ccaa2dfc5ceec143bdd81c14
|
|
@ -0,0 +1,47 @@
|
|||
package pco
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"git.preston-baxter.com/Preston_PLB/capstone/webhook-service/vendors/pco/webhooks"
|
||||
"github.com/google/jsonapi"
|
||||
)
|
||||
|
||||
|
||||
func (api *PcoApiClient) GetSubscriptions() ([]services.Subscription, error) {
|
||||
api.Url().Path = "/webhook/v2/subscriptions"
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, api.Url().String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := api.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode > 299 || resp.StatusCode < 200 {
|
||||
return nil, fmt.Errorf("Failed to retrieve plan with status code: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
raw, err := jsonapi.UnmarshalManyPayload(resp.Body, reflect.TypeOf(webhooks.Subscription{}))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
webhooks := make([]webhooks.Subscription, len(raw))
|
||||
for index, hook := range raw {
|
||||
var ok bool
|
||||
webhooks[index], ok = hook.(reflect.TypeOf(webhooks.Subscription))
|
||||
if !ok {
|
||||
return fmt.Errorf("Failed to extract webhook payload")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return plan, nil
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package webhooks
|
||||
|
||||
import "time"
|
||||
|
||||
type Subscription struct {
|
||||
Id string `jsonapi:"primary,Subscription"`
|
||||
//attrs
|
||||
Active bool `jsonapi:"attr,active,omitempty"`
|
||||
ApplicationId string `jsonapi:"attr,application_id,omitempty"`
|
||||
AuthenticitySecret bool `jsonapi:"attr,authenticity_secret,omitempty"`
|
||||
CreatedAt time.Time `jsonapi:"attr,created_at,omitempty"`
|
||||
UpdatedAt time.Time `jsonapi:"attr,updated_at,omitempty"`
|
||||
Name string `jsonapi:"attr,name,omitempty"`
|
||||
Url string `jsonapi:"attr,url,omitempty"`
|
||||
}
|
||||
|
||||
type WebhookSubscription struct {
|
||||
Id string `jsonapi:"primary,WebhookSubscription"`
|
||||
//attrs
|
||||
Active bool `jsonapi:"attr,active,omitempty"`
|
||||
ApplicationId string `jsonapi:"attr,application_id,omitempty"`
|
||||
AuthenticitySecret bool `jsonapi:"attr,authenticity_secret,omitempty"`
|
||||
CreatedAt time.Time `jsonapi:"attr,created_at,omitempty"`
|
||||
UpdatedAt time.Time `jsonapi:"attr,updated_at,omitempty"`
|
||||
Name string `jsonapi:"attr,name,omitempty"`
|
||||
Url string `jsonapi:"attr,url,omitempty"`
|
||||
}
|
Loading…
Reference in New Issue