Skip to content

Commit

Permalink
Merge pull request #1 from nimbusec-oss/feature/APIv2
Browse files Browse the repository at this point in the history
Feature/ap iv2
  • Loading branch information
bernhardreisenberger authored Jul 15, 2024
2 parents 9d0e7ad + 87924a4 commit 60fa09e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ type AccountService service

func (srv AccountService) Get() (Account, error) {
resp := Account{}
err := srv.client.Do(http.MethodGet, "/api/v1/account", nil, &resp)
err := srv.client.Do(http.MethodGet, "/api/v2/account", nil, &resp)
return resp, err
}
8 changes: 7 additions & 1 deletion constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const (
StatusRatingDone = "done"
StatusRatingDeclined = "declined"
StatusRatingBlocked = "blocked"
StatusRatingExpired = "expired"
)

const (
Expand All @@ -18,3 +17,10 @@ const (
StatusCScoreFailed = "failed"
StatusCScoreMissing = "missing"
)

const TYPE_CRR ProjectType = "crr"
const TYPE_DPR ProjectType = "dpr"

const SCORE_CRR ScoreType = "crr"
const SCORE_DPR ScoreType = "dpr"
const SCORE_WEBRISK ScoreType = "webrisk"
14 changes: 10 additions & 4 deletions rating.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (srv RatingService) List(filter *RatingFilter) ([]Rating, error) {
return nil, err
}
u := url.URL{
Path: "/api/v1/ratings",
Path: "/api/v2/ratings",
RawQuery: v.Encode(),
}

Expand All @@ -24,8 +24,14 @@ func (srv RatingService) List(filter *RatingFilter) ([]Rating, error) {
return resp, err
}

func (srv RatingService) Create(create []RequestRating) ([]Rating, error) {
resp := []Rating{}
err := srv.client.Do(http.MethodPost, "/api/v1/ratings", create, &resp)
func (srv RatingService) CreateCRR(create []RequestRatingCRR) (ContingentUsage, error) {
resp := ContingentUsage{}
err := srv.client.Do(http.MethodPost, "/api/v2/ratings/crr", create, &resp)
return resp, err
}

func (srv RatingService) CreateDPR(create []RequestRatingDPR) (ContingentUsage, error) {
resp := ContingentUsage{}
err := srv.client.Do(http.MethodPost, "/api/v2/ratings/dpr", create, &resp)
return resp, err
}
23 changes: 4 additions & 19 deletions supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,9 @@ import (

type SupplierService service

func (srv SupplierService) List(filter *SupplierFilter) ([]Supplier, error) {
v, err := query.Values(filter)
if err != nil {
return nil, err
}
u := url.URL{
Path: "/api/v1/suppliers",
RawQuery: v.Encode(),
}

resp := []Supplier{}
err = srv.client.Do(http.MethodGet, u.String(), nil, &resp)
return resp, err
}

func (srv SupplierService) Create(create []RequestSupplier) ([]Supplier, error) {
resp := []Supplier{}
err := srv.client.Do(http.MethodPost, "/api/v1/suppliers", create, &resp)
func (srv SupplierService) Create(create []RequestSupplier) (PostSuppliersResponse, error) {
resp := PostSuppliersResponse{}
err := srv.client.Do(http.MethodPost, "/api/v2/suppliers", create, &resp)
return resp, err
}

Expand All @@ -36,7 +21,7 @@ func (srv SupplierService) Unassign(unassign UnassignSupplier) error {
return err
}
u := url.URL{
Path: "/api/v1/suppliers/unassign",
Path: "/api/v2/suppliers/unassign",
RawQuery: v.Encode(),
}

Expand Down
99 changes: 51 additions & 48 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"time"
)

type OrderRating struct {
RequestedCategory string `json:"requestedCategory"` // mandatory
}
type ProjectType string
type ScoreType string

type RequestSupplier struct {
VAT string `json:"vat"` // mandatory
Expand All @@ -24,33 +23,10 @@ type RequestSupplier struct {
City string `json:"city,omitempty"` // optional
Country string `json:"country,omitempty"` // optional
Sector string `json:"sector,omitempty"` // optional
ExternalID string `json:"externalID,omitempty"` // Deprecated
ExternalIDs []string `json:"externalIDs,omitempty"` // optional

OrderRating *OrderRating `json:"orderRating,omitempty"` // optional
}

type Supplier struct {
VAT string `json:"vat"`
CompanyName string `json:"companyName"`
Language string `json:"language"`
Email string `json:"email"`
Websites []string `json:"websites"`

Forename string `json:"forename,omitempty"`
Surname string `json:"surname,omitempty"`
Tel string `json:"tel,omitempty"`

Street string `json:"street,omitempty"`
ZipCode string `json:"zipCode,omitempty"`
City string `json:"city,omitempty"`
Country string `json:"country,omitempty"`
Sector string `json:"sector,omitempty"`

ExternalID string `json:"externalID,omitempty"`
ID string `json:"id"`

Rating *Rating `json:"rating,omitempty"`
OrderCRR string `json:"orderCRR,omitempty"` // optional
OrderDPR bool `json:"orderDPR,omitempty"` // optional
}

type SupplierFilter struct {
Expand All @@ -63,46 +39,73 @@ type UnassignSupplier struct {
}

type Rating struct {
CompanyName string `json:"companyName,omitempty"`
SupplierID string `json:"supplierID"`
ExternalID string `json:"externalID,omitempty"` // Deprecated
ExternalIDs []string `json:"externalIDs,omitempty"`
CompanyName string `json:"companyName,omitempty"`
SupplierID string `json:"supplierID"`
ExternalIDs []string `json:"externalIDs,omitempty"`

RatingCRR *RatingCRR `json:"ratingCRR,omitempty"`
RatingDPR *RatingDPR `json:"ratingDPR,omitempty"`
WebRisk *WebRisk `json:"webrisk,omitempty"`
}

type RatingCRR struct {
AScore int `json:"aScore,omitempty"`
BScore int `json:"bScore,omitempty"`
Status string `json:"status,omitempty"`
ValidFrom *time.Time `json:"validFrom,omitempty"`
ValidUntil *time.Time `json:"validUntil,omitempty"`
AssessmentValidUntil *time.Time `json:"-"` // internal only
AssessmentValidUntil *time.Time `json:"assessmentValidUntil,omitempty"`
CyberTrustLabel string `json:"cyberTrustLabel,omitempty"`
CScore int `json:"cScore,omitempty"`
StatusCScore string `json:"statusCScore,omitempty"`
Websites []string `json:"websites,omitempty"`
}

type RatingDPR struct {
MinimumRequirementsMet bool `json:"minimumRequirementsMet,omitempty"`
Score int `json:"score,omitempty"`
Status string `json:"status,omitempty"`
ValidFrom *time.Time `json:"validFrom,omitempty"`
ValidUntil *time.Time `json:"validUntil,omitempty"`
AssessmentValidUntil *time.Time `json:"assessmentValidUntil,omitempty"`
}

type WebRisk struct {
Score int `json:"score,omitempty"`
Status string `json:"status,omitempty"`
Websites []string `json:"websites,omitempty"`
}

type RatingFilter struct {
Status []string `url:"status"`
SupplierIDs []string `url:"supplier-id"`
ExternalIDs []string `url:"external-id"`
Status []string `url:"status"`
ScoreType []ScoreType `url:"st"`
SupplierIDs []string `url:"supplier-id"`
ExternalIDs []string `url:"external-id"`
}

type RequestRating struct {
type RequestRatingCRR struct {
Category string `json:"category"`
SupplierID string `json:"supplierID,omitempty"`
ExternalID string `json:"externalID,omitempty"`
}

type RequestRatingDPR struct {
SupplierID string `json:"supplierID,omitempty"`
ExternalID string `json:"externalID,omitempty"`
}

type ContingentUsage struct {
ContingentBefore int `json:"contingentBefore"`
ContingentAfter int `json:"contingentAfter"`
OrderedSuppliers []string `json:"orderedSuppliers"`
Project ProjectType `json:"project"`
ContingentBefore int `json:"contingentBefore"`
ContingentAfter int `json:"contingentAfter"`
OrderedSuppliers []string `json:"orderedSuppliers"`
}

type PostSuppliersReturn struct {
Created int `json:"created"`
Existed int `json:"existed"`
Orders *ContingentUsage `json:"orders,omitempty"`
type PostSuppliersResponse struct {
Created int `json:"created"`
Existed int `json:"existed"`
OrdersCRR *ContingentUsage `json:"ordersCRR,omitempty"`
OrdersDPR *ContingentUsage `json:"ordersDPR,omitempty"`
}

type Account struct {
Contingent int `json:"contingent,omitempty"`
ContingentCRR int `json:"contingentCRR,omitempty"`
ContingentDPR int `json:"contingentDPR,omitempty"`
}

0 comments on commit 60fa09e

Please sign in to comment.