|
| 1 | +package sendcloud |
| 2 | + |
| 3 | +import "encoding/json" |
| 4 | + |
| 5 | +type Product struct { |
| 6 | + Name string `json:"name"` |
| 7 | + Code string `json:"code"` |
| 8 | + Carrier string `json:"carrier"` |
| 9 | + ServicePointsCarrier string `json:"service_points_carrier"` |
| 10 | + WeightRange struct { |
| 11 | + MinWeight int `json:"min_weight"` |
| 12 | + MaxWeight int `json:"max_weight"` |
| 13 | + } `json:"weight_range"` |
| 14 | + Methods []struct { |
| 15 | + Id int `json:"id"` |
| 16 | + Name string `json:"name"` |
| 17 | + ShippingProductCode string `json:"shipping_product_code"` |
| 18 | + Properties struct { |
| 19 | + MinWeight int `json:"min_weight"` |
| 20 | + MaxWeight int `json:"max_weight"` |
| 21 | + MaxDimensions struct { |
| 22 | + Length int `json:"length"` |
| 23 | + Width int `json:"width"` |
| 24 | + Height int `json:"height"` |
| 25 | + Unit string `json:"unit"` |
| 26 | + } `json:"max_dimensions"` |
| 27 | + } `json:"properties"` |
| 28 | + LeadTimeHours struct { |
| 29 | + NL struct { |
| 30 | + NL int `json:"NL"` |
| 31 | + } `json:"NL"` |
| 32 | + } `json:"lead_time_hours"` |
| 33 | + } `json:"methods"` |
| 34 | +} |
| 35 | + |
| 36 | +type ProductListResponseContainer struct { |
| 37 | + Products []Product `json:"products"` |
| 38 | +} |
| 39 | + |
| 40 | +func (p *ProductListResponseContainer) SetResponse(body []byte) error { |
| 41 | + return json.Unmarshal(body, &p.Products) |
| 42 | +} |
| 43 | + |
| 44 | +type ProductResponseContainer struct { |
| 45 | + Product Product `json:"product"` |
| 46 | +} |
| 47 | + |
| 48 | +func (p *ProductResponseContainer) GetResponse() interface{} { |
| 49 | + return p.Product |
| 50 | +} |
| 51 | + |
| 52 | +func (p *ProductListResponseContainer) GetResponse() interface{} { |
| 53 | + var products []*Product |
| 54 | + for i := range p.Products { |
| 55 | + products = append(products, &p.Products[i]) |
| 56 | + } |
| 57 | + |
| 58 | + return products |
| 59 | +} |
0 commit comments