Merge pull request #11 from DmitryZagorulko/master

add methods, documentation and tests
This commit is contained in:
Alex Lushpai 2018-04-23 16:59:47 +03:00 committed by GitHub
commit 11a57e2e68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 5820 additions and 369 deletions

View File

@ -5,4 +5,5 @@ go:
- '1.10'
before_install:
- go get -v github.com/google/go-querystring/query
- go get -v github.com/h2non/gock
script: go test -v ./...

View File

@ -48,34 +48,58 @@ func main() {
fmt.Println(data.Orders[1].FirstName)
idata, status, err := c.InventoriesUpload(
[]InventoryUpload{
{
XMLID: "pTKIKAeghYzX21HTdzFCe1",
Stores: []InventoryUploadStore{
{Code: "test-store-v5", Available: 10, PurchasePrice: 1500},
{Code: "test-store-v4", Available: 20, PurchasePrice: 1530},
{Code: "test-store", Available: 30, PurchasePrice: 1510},
},
},
{
XMLID: "JQIvcrCtiSpOV3AAfMiQB3",
Stores: []InventoryUploadStore{
{Code: "test-store-v5", Available: 45, PurchasePrice: 1500},
{Code: "test-store-v4", Available: 32, PurchasePrice: 1530},
{Code: "test-store", Available: 46, PurchasePrice: 1510},
},
},
},
)
if err.RuntimeErr != nil {
fmt.Printf("%v", err.Error())
}
[]InventoryUpload{
{
XMLID: "pTKIKAeghYzX21HTdzFCe1",
Stores: []InventoryUploadStore{
{
Code: "test-store-v5",
Available: 10,
PurchasePrice: 1500,
},
{
Code: "test-store-v4",
Available: 20,
PurchasePrice: 1530,
},
{
Code: "test-store",
Available: 30,
PurchasePrice: 1510,
},
},
},
{
XMLID: "JQIvcrCtiSpOV3AAfMiQB3",
Stores: []InventoryUploadStore{
{
Code: "test-store-v5",
Available: 45,
PurchasePrice: 1500,
},
{
Code: "test-store-v4",
Available: 32,
PurchasePrice: 1530,
},
{
Code: "test-store",
Available: 46,
PurchasePrice: 1510,
},
},
},
},
)
if err.RuntimeErr != nil {
fmt.Printf("%v", err.Error())
}
if status >= http.StatusBadRequest {
fmt.Printf("%v", err.ApiError())
}
if status >= http.StatusBadRequest {
fmt.Printf("%v", err.ApiError())
}
fmt.Println(idata.processedOffersCount)
fmt.Println(idata.processedOffersCount)
}
```

View File

@ -16,14 +16,8 @@ func (f *Failure) ApiError() string {
}
// ApiErrors returns array of formatted strings that represents API errors
func (f *Failure) ApiErrors() []string {
var errors []string
for i := 0; i < len(f.ApiErrs); i++ {
errors = append(errors, fmt.Sprintf("%v", f.ApiErrs[i]))
}
return errors
func (f *Failure) ApiErrors() map[string]string {
return f.ApiErrs
}
// ErrorResponse method

View File

@ -4,5 +4,5 @@ package errs
type Error interface {
error
ApiError() string
ApiErrors() []string
ApiErrors() map[string]string
}

View File

@ -4,11 +4,11 @@ package errs
type Failure struct {
RuntimeErr error
ApiErr string
ApiErrs []string
ApiErrs map[string]string
}
// FailureResponse convert json error response into object
type FailureResponse struct {
ErrorMsg string `json:"errorMsg,omitempty"`
Errors []string `json:"errors,omitempty"`
ErrorMsg string `json:"errorMsg,omitempty"`
Errors map[string]string `json:"errors,omitempty"`
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -296,3 +296,39 @@ type ShipmentFilter struct {
DeliveryTypes []string `url:"deliveryTypes,omitempty,brackets"`
Statuses []string `url:"statuses,omitempty,brackets"`
}
// CostsFilter type
type CostsFilter struct {
MinSumm string `url:"minSumm,omitempty"`
MaxSumm string `url:"maxSumm,omitempty"`
OrderNumber string `url:"orderNumber,omitempty"`
Comment string `url:"orderNumber,omitempty"`
Ids []string `url:"ids,omitempty,brackets"`
Sites []string `url:"sites,omitempty,brackets"`
CreatedBy []string `url:"createdBy,omitempty,brackets"`
CostGroups []string `url:"costGroups,omitempty,brackets"`
CostItems []string `url:"costItems,omitempty,brackets"`
Users []string `url:"users,omitempty,brackets"`
DateFrom string `url:"dateFrom,omitempty"`
DateTo string `url:"dateTo,omitempty"`
CreatedAtFrom string `url:"createdAtFrom,omitempty"`
CreatedAtTo string `url:"createdAtTo,omitempty"`
OrderIds []string `url:"orderIds,omitempty,brackets"`
OrderExternalIds []string `url:"orderIds,omitempty,brackets"`
}
// CustomFieldsFilter type
type CustomFieldsFilter struct {
Name string `url:"name,omitempty"`
Code string `url:"code,omitempty"`
Type string `url:"type,omitempty"`
Entity string `url:"entity,omitempty"`
ViewMode string `url:"viewMode,omitempty"`
DisplayArea string `url:"displayArea,omitempty"`
}
// CustomDictionariesFilter type
type CustomDictionariesFilter struct {
Name string `url:"name,omitempty"`
Code string `url:"code,omitempty"`
}

View File

@ -88,7 +88,7 @@ type TasksRequest struct {
// NotesRequest type
type NotesRequest struct {
Filter TasksFilter `url:"filter,omitempty"`
Filter NotesFilter `url:"filter,omitempty"`
Limit int `url:"limit,omitempty"`
Page int `url:"page,omitempty"`
}
@ -142,3 +142,24 @@ type DeliveryShipmentsRequest struct {
Limit int `url:"limit,omitempty"`
Page int `url:"page,omitempty"`
}
// CostsRequest type
type CostsRequest struct {
Filter CostsFilter `url:"filter,omitempty"`
Limit int `url:"limit,omitempty"`
Page int `url:"page,omitempty"`
}
// CustomFieldsRequest type
type CustomFieldsRequest struct {
Filter CustomFieldsFilter `url:"filter,omitempty"`
Limit int `url:"limit,omitempty"`
Page int `url:"page,omitempty"`
}
// CustomeDictionariesRequest type
type CustomDictionariesRequest struct {
Filter CustomDictionariesFilter `url:"filter,omitempty"`
Limit int `url:"limit,omitempty"`
Page int `url:"page,omitempty"`
}

View File

@ -328,3 +328,61 @@ type IntegrationModuleEditResponse struct {
Success bool `json:"success"`
Info map[string]string `json:"info,omitempty,brackets"`
}
// CostsResponse type
type CostsResponse struct {
Success bool `json:"success"`
Pagination *Pagination `json:"pagination,omitempty"`
Costs []Cost `json:"costs,omitempty,brackets"`
}
// CostsUploadResponse type
type CostsUploadResponse struct {
Success bool `json:"success"`
UploadedCosts []int `json:"uploadedCosts,omitempty,brackets"`
}
// CostsDeleteResponse type
type CostsDeleteResponse struct {
Success bool `json:"success"`
Count int `json:"count,omitempty,brackets"`
NotRemovedIds []int `json:"notRemovedIds,omitempty,brackets"`
}
// CostResponse type
type CostResponse struct {
Success bool `json:"success"`
Cost *Cost `json:"cost,omitempty,brackets"`
}
// CustomFieldsResponse type
type CustomFieldsResponse struct {
Success bool `json:"success"`
Pagination *Pagination `json:"pagination,omitempty"`
CustomFields []CustomFields `json:"customFields,omitempty,brackets"`
}
// CustomDictionariesResponse type
type CustomDictionariesResponse struct {
Success bool `json:"success"`
Pagination *Pagination `json:"pagination,omitempty"`
CustomDictionaries *[]CustomDictionary `json:"customDictionaries,omitempty,brackets"`
}
// CustomDictionariesResponse type
type CustomResponse struct {
Success bool `json:"success"`
Code string `json:"code,omitempty"`
}
// CustomDictionaryResponse type
type CustomDictionaryResponse struct {
Success bool `json:"success"`
CustomDictionary *CustomDictionary `json:"CustomDictionary,omitempty,brackets"`
}
// CustomFieldResponse type
type CustomFieldResponse struct {
Success bool `json:"success"`
CustomField CustomFields `json:"customField,omitempty,brackets"`
}

View File

@ -864,3 +864,71 @@ type Action struct {
URL string `json:"url,omitempty"`
CallPoints []string `json:"callPoints,omitempty"`
}
/**
Cost related types
*/
// CostRecord type
type CostRecord struct {
Source *Source `json:"source,omitempty"`
Comment string `json:"comment,omitempty"`
DateFrom string `json:"dateFrom,omitempty"`
DateTo string `json:"dateTo,omitempty"`
Summ float32 `json:"summ,omitempty"`
CostItem string `json:"costItem,omitempty"`
UserId int `json:"userId,omitempty"`
Order *Order `json:"order,omitempty"`
Sites []string `json:"sites,omitempty,brackets"`
}
// Cost type
type Cost struct {
Source *Source `json:"source,omitempty"`
ID int `json:"id,omitempty"`
DateFrom string `json:"dateFrom,omitempty"`
DateTo string `json:"dateTo,omitempty"`
Summ float32 `json:"summ,omitempty"`
CostItem string `json:"costItem,omitempty"`
Comment string `json:"comment,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
CreatedBy string `json:"createdBy,omitempty"`
Order *Order `json:"order,omitempty"`
UserId int `json:"userId,omitempty"`
Sites []string `json:"sites,omitempty,brackets"`
}
// CustomFields type
type CustomFields struct {
Name string `json:"name,omitempty"`
Code string `json:"code,omitempty"`
Required bool `json:"required,omitempty"`
InFilter bool `json:"inFilter,omitempty"`
InList bool `json:"inList,omitempty"`
InGroupActions bool `json:"inGroupActions,omitempty"`
Type string `json:"type,omitempty"`
Entity string `json:"entity,omitempty"`
Default string `json:"default,omitempty"`
Ordering int `json:"ordering,omitempty"`
DisplayArea string `json:"displayArea,omitempty"`
ViewMode string `json:"viewMode,omitempty"`
Dictionary string `json:"dictionary,omitempty"`
}
/**
CustomeDictionaries related types
*/
// customDictionary type
type CustomDictionary struct {
Name string `json:"name,omitempty"`
Code string `json:"code,omitempty"`
Elements []Element `json:"elements,omitempty,brackets"`
}
// Dictionary Element type
type Element struct {
Name string `json:"name,omitempty"`
Code string `json:"code,omitempty"`
Ordering int `json:"ordering,omitempty"`
}