github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/api/resources/service_offerings.go (about)

     1  package resources
     2  
     3  import "github.com/cloudfoundry/cli/cf/models"
     4  
     5  type PaginatedServiceOfferingResources struct {
     6  	Resources []ServiceOfferingResource
     7  }
     8  
     9  type ServiceOfferingResource struct {
    10  	Resource
    11  	Entity ServiceOfferingEntity
    12  }
    13  
    14  type ServiceOfferingEntity struct {
    15  	Label            string                `json:"label"`
    16  	Version          string                `json:"version"`
    17  	Description      string                `json:"description"`
    18  	DocumentationUrl string                `json:"documentation_url"`
    19  	Provider         string                `json:"provider"`
    20  	BrokerGuid       string                `json:"service_broker_guid"`
    21  	ServicePlans     []ServicePlanResource `json:"service_plans"`
    22  }
    23  
    24  func (resource ServiceOfferingResource) ToFields() (fields models.ServiceOfferingFields) {
    25  	fields.Label = resource.Entity.Label
    26  	fields.Version = resource.Entity.Version
    27  	fields.Provider = resource.Entity.Provider
    28  	fields.Description = resource.Entity.Description
    29  	fields.BrokerGuid = resource.Entity.BrokerGuid
    30  	fields.Guid = resource.Metadata.Guid
    31  	fields.DocumentationUrl = resource.Entity.DocumentationUrl
    32  	return
    33  }
    34  
    35  func (resource ServiceOfferingResource) ToModel() (offering models.ServiceOffering) {
    36  	offering.ServiceOfferingFields = resource.ToFields()
    37  	for _, p := range resource.Entity.ServicePlans {
    38  		servicePlan := models.ServicePlanFields{}
    39  		servicePlan.Name = p.Entity.Name
    40  		servicePlan.Guid = p.Metadata.Guid
    41  		offering.Plans = append(offering.Plans, servicePlan)
    42  	}
    43  	return offering
    44  }