Skip to content

Commit

Permalink
feat: Add producer extension create
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Jan 10, 2022
1 parent b5be7b3 commit ac9468b
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 108 deletions.
2 changes: 1 addition & 1 deletion account-api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c Client) doRequest(request *http.Request) ([]byte, error) {
return nil, fmt.Errorf("doRequest: %v", err)
}

if resp.StatusCode != 200 {
if resp.StatusCode != 200 && resp.StatusCode != 201 {
return nil, fmt.Errorf(string(data))
}

Expand Down
278 changes: 171 additions & 107 deletions account-api/producer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package account_api

import (
"bytes"
"encoding/json"
"fmt"
)
Expand Down Expand Up @@ -109,7 +110,7 @@ type producer struct {
CancelledContract interface{} `json:"cancelledContract"`
}

func (e producerEndpoint) Extensions() ([]listingExtension, error) {
func (e producerEndpoint) Extensions() ([]extension, error) {
r, err := e.c.NewAuthenticatedRequest("GET", fmt.Sprintf("%s/plugins?producerId=%d&limit=100&orderBy=name&orderSequence=asc", ApiUrl, e.GetId()), nil)
if err != nil {
return nil, err
Expand All @@ -121,23 +122,60 @@ func (e producerEndpoint) Extensions() ([]listingExtension, error) {
return nil, err
}

var extensions []listingExtension
var extensions []extension
if err := json.Unmarshal(body, &extensions); err != nil {
return nil, fmt.Errorf("list_extensions: %v", err)
}

return extensions, nil
}

type listingExtension struct {
Id int `json:"id"`
type extension struct {
Id int `json:"id"`
Producer struct {
Id int `json:"id"`
Prefix string `json:"prefix"`
Contract struct {
Id int `json:"id"`
Path string `json:"path"`
} `json:"contract"`
Name string `json:"name"`
Details []struct {
Id int `json:"id"`
Locale struct {
Id int `json:"id"`
Name string `json:"name"`
} `json:"locale"`
Description string `json:"description"`
} `json:"details"`
Website string `json:"website"`
Fixed bool `json:"fixed"`
HasCancelledContract bool `json:"hasCancelledContract"`
IconPath string `json:"iconPath"`
IconIsSet bool `json:"iconIsSet"`
ShopwareId string `json:"shopwareId"`
UserId int `json:"userId"`
CompanyId int `json:"companyId"`
CompanyName string `json:"companyName"`
SaleMail string `json:"saleMail"`
SupportMail string `json:"supportMail"`
RatingMail string `json:"ratingMail"`
SupportedLanguages []struct {
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
} `json:"supportedLanguages"`
IconUrl string `json:"iconUrl"`
CancelledContract interface{} `json:"cancelledContract"`
} `json:"producer"`
Type struct {
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
} `json:"type"`
Name string `json:"name"`
Code string `json:"code"`
ModuleKey string `json:"moduleKey"`
LifecycleStatus struct {
Id int `json:"id"`
Name string `json:"name"`
Expand All @@ -158,124 +196,150 @@ type listingExtension struct {
Name string `json:"name"`
Description string `json:"description"`
} `json:"approvalStatus"`
StandardLocale struct {
Id int `json:"id"`
Name string `json:"name"`
} `json:"standardLocale"`
License struct {
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
} `json:"license"`
Infos []struct {
Id int `json:"id"`
Locale struct {
Id int `json:"id"`
Name string `json:"name"`
} `json:"locale"`
Name string `json:"name"`
Description string `json:"description"`
InstallationManual string `json:"installationManual"`
ShortDescription string `json:"shortDescription"`
Highlights string `json:"highlights"`
Features string `json:"features"`
Tags []struct {
Id int `json:"id"`
Locale struct {
Id int `json:"id"`
Name string `json:"name"`
} `json:"locale"`
Name string `json:"name"`
Internal bool `json:"internal"`
} `json:"tags"`
Videos []interface{} `json:"videos"`
Faqs []interface{} `json:"faqs"`
Name string `json:"name"`
Description string `json:"description"`
InstallationManual string `json:"installationManual"`
ShortDescription string `json:"shortDescription"`
Highlights string `json:"highlights"`
Features string `json:"features"`
Tags []interface{} `json:"tags"`
Videos []interface{} `json:"videos"`
Faqs []interface{} `json:"faqs"`
} `json:"infos"`
Variants []struct {
Id int `json:"id"`
PriceModel struct {
Id int `json:"id"`
Type string `json:"type"`
BookingKey string `json:"bookingKey"`
BookingText string `json:"bookingText"`
} `json:"priceModel"`
Name string `json:"name"`
Description string `json:"description"`
} `json:"variants"`
PriceModels []interface{} `json:"priceModels"`
Variants []interface{} `json:"variants"`
StoreAvailabilities []struct {
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
} `json:"storeAvailabilities"`
Addons []interface{} `json:"addons"`
CreationDate string `json:"creationDate"`
Certification struct {
PluginId int `json:"pluginId"`
CreationDate string `json:"creationDate"`
BronzeResult struct {
Items []struct {
Name string `json:"name"`
Label string `json:"label"`
Actual interface{} `json:"actual"`
Expected interface{} `json:"expected"`
Fulfilled bool `json:"fulfilled"`
} `json:"items"`
Fulfilled bool `json:"fulfilled"`
} `json:"bronzeResult"`
SilverResult struct {
Items []struct {
Name string `json:"name"`
Label string `json:"label"`
Actual interface{} `json:"actual"`
Expected interface{} `json:"expected"`
Fulfilled bool `json:"fulfilled"`
} `json:"items"`
Fulfilled bool `json:"fulfilled"`
} `json:"silverResult"`
GoldResult struct {
Items []struct {
Name string `json:"name"`
Label string `json:"label"`
Actual interface{} `json:"actual"`
Expected interface{} `json:"expected"`
Fulfilled bool `json:"fulfilled"`
} `json:"items"`
Fulfilled bool `json:"fulfilled"`
} `json:"goldResult"`
Type struct {
Name string `json:"name"`
Description string `json:"description"`
} `json:"type"`
} `json:"certification"`
ProductType struct {
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
MainCategory struct {
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Parent bool `json:"parent"`
Position int `json:"position"`
Public bool `json:"public"`
Visible bool `json:"visible"`
Suggested bool `json:"suggested"`
Applicable bool `json:"applicable"`
Details []struct {
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Locale struct {
Id int `json:"id"`
Name string `json:"name"`
} `json:"locale"`
} `json:"details"`
Active bool `json:"active"`
} `json:"mainCategory"`
} `json:"productType"`
Status struct {
Categories []interface{} `json:"categories"`
Addons []interface{} `json:"addons"`
LastChange string `json:"lastChange"`
CreationDate string `json:"creationDate"`
Support bool `json:"support"`
SupportOnlyCommercial bool `json:"supportOnlyCommercial"`
IconPath string `json:"iconPath"`
IconIsSet bool `json:"iconIsSet"`
ExamplePageUrl string `json:"examplePageUrl"`
Demos []interface{} `json:"demos"`
Localizations []interface{} `json:"localizations"`
LatestBinary interface{} `json:"latestBinary"`
MigrationSupport bool `json:"migrationSupport"`
AutomaticBugfixVersionCompatibility bool `json:"automaticBugfixVersionCompatibility"`
HiddenInStore bool `json:"hiddenInStore"`
Certification interface{} `json:"certification"`
ProductType interface{} `json:"productType"`
Status struct {
Name string `json:"name"`
} `json:"status"`
MinimumMarketingSoftwareVersion interface{} `json:"minimumMarketingSoftwareVersion"`
IsSubscriptionEnabled bool `json:"isSubscriptionEnabled"`
ReleaseDate interface{} `json:"releaseDate"`
PlannedReleaseDate interface{} `json:"plannedReleaseDate"`
Successor interface{} `json:"successor"`
LastBusinessModelChangeDate interface{} `json:"lastBusinessModelChangeDate"`
IsSW5Compatible bool `json:"isSW5Compatible"`
Subprocessors interface{} `json:"subprocessors"`
PluginTestingInstanceDisabled bool `json:"pluginTestingInstanceDisabled"`
IconUrl string `json:"iconUrl"`
Pictures string `json:"pictures"`
HasPictures bool `json:"hasPictures"`
Comments string `json:"comments"`
Reviews string `json:"reviews"`
IsPremiumPlugin bool `json:"isPremiumPlugin"`
IsAdvancedFeature bool `json:"isAdvancedFeature"`
IsEnterpriseAccelerator bool `json:"isEnterpriseAccelerator"`
IsSW6EnterpriseFeature bool `json:"isSW6EnterpriseFeature"`
IsSW6ProfessionalEditionFeature bool `json:"isSW6ProfessionalEditionFeature"`
Binaries string `json:"binaries"`
Predecessor interface{} `json:"predecessor"`
Successor interface{} `json:"successor"`
IsCompatibleWithLatestShopwareVersion bool `json:"isCompatibleWithLatestShopwareVersion"`
AutomaticBugfixVersionCompatibility bool `json:"automaticBugfixVersionCompatibility"`
ReleaseDate *struct {
Date string `json:"date"`
TimezoneType int `json:"timezone_type"`
Timezone string `json:"timezone"`
} `json:"releaseDate"`
PluginTestingInstanceCreated bool `json:"pluginTestingInstanceCreated"`
PluginPreview interface{} `json:"pluginPreview"`
}

type CreateExtensionRequest struct {
Name string `json:"name,omitempty"`
Generation struct {
Name string `json:"name"`
} `json:"generation"`
ProducerId int `json:"producerId"`
}

const (
GenerationClassic = "classic"
GenerationThemes = "themes"
GenerationApps = "apps"
GenerationPlatform = "platform"
)

func (e producerEndpoint) CreateExtension(newExtension CreateExtensionRequest) (*extension, error) {
requestBody, err := json.Marshal(newExtension)

if err != nil {
return nil, err
}

// Create it
r, err := e.c.NewAuthenticatedRequest("POST", fmt.Sprintf("%s/plugins", ApiUrl), bytes.NewBuffer(requestBody))

if err != nil {
return nil, err
}

body, err := e.c.doRequest(r)

if err != nil {
return nil, err
}

var extension extension
if err := json.Unmarshal(body, &extension); err != nil {
return nil, fmt.Errorf("create_extension: %v", err)
}

extension.Name = newExtension.Name

// Patch the name
err = e.UpdateExtension(&extension)

if err != nil {
return nil, err
}

return &extension, nil
}

func (e producerEndpoint) UpdateExtension(extension *extension) error {
requestBody, err := json.Marshal(extension)

if err != nil {
return err
}

// Patch the name
r, err := e.c.NewAuthenticatedRequest("PUT", fmt.Sprintf("%s/plugins/%d", ApiUrl, extension.Id), bytes.NewBuffer(requestBody))

if err != nil {
return err
}

_, err = e.c.doRequest(r)

return err
}
Loading

0 comments on commit ac9468b

Please sign in to comment.