Ejemplo n.º 1
0
func (c *CalendarData) CalendarComponent() (*components.Calendar, error) {
	cal := new(components.Calendar)
	if content := strings.TrimSpace(c.Content); content == "" {
		return nil, utils.NewError(c.CalendarComponent, "no calendar data to decode", c, nil)
	} else if err := icalendar.Unmarshal(content, cal); err != nil {
		return nil, utils.NewError(c.CalendarComponent, "decoding calendar data failed", c, err)
	} else {
		return cal, nil
	}
}
Ejemplo n.º 2
0
func (s *ContactSuite) TestItentity(c *C) {

	before := NewOrganizerContact("Foo", "*****@*****.**")
	encoded, err := icalendar.Marshal(before)
	c.Assert(err, IsNil)

	after := new(OrganizerContact)
	err = icalendar.Unmarshal(encoded, after)
	c.Assert(err, IsNil)

	c.Assert(after, DeepEquals, before)

}
Ejemplo n.º 3
0
func (s *RecurrenceRuleSuite) TestIdentity(c *C) {

	encoded, err := icalendar.Marshal(s.RecurrenceRule)
	c.Assert(err, IsNil)

	after := new(RecurrenceRule)
	if err = icalendar.Unmarshal(encoded, after); err != nil {
		c.Fatal(err.Error())
	}

	c.Assert(after, DeepEquals, s.RecurrenceRule)

}
Ejemplo n.º 4
0
func (s *GeoSuite) TestIdentity(c *C) {

	before := &geoTestObj{Geo: NewGeo(10, 20)}
	encoded, err := icalendar.Marshal(before)
	c.Assert(err, IsNil)

	after := new(geoTestObj)
	if err := icalendar.Unmarshal(encoded, after); err != nil {
		c.Fatal(err.Error())
	}

	c.Assert(after, DeepEquals, before)

}
Ejemplo n.º 5
0
// decodes a CalDAV iCalendar response into the provided interface
func (r *Response) Decode(into interface{}) error {
	if body := r.Body; body == nil {
		return nil
	} else if encoded, err := ioutil.ReadAll(body); err != nil {
		return utils.NewError(r.Decode, "unable to read response body", r, err)
	} else {
		// log.Printf("IN: %+v", string(encoded))
		if err := icalendar.Unmarshal(string(encoded), into); err != nil {
			return utils.NewError(r.Decode, "unable to decode response body", r, err)
		} else {
			return nil
		}
	}
}
Ejemplo n.º 6
0
func (s *DateTimeSuite) TestItentity(c *C) {

	t := time.Now().UTC()

	before := RecurrenceDateTimes([]*DateTime{NewDateTime(t)})
	encoded, err := icalendar.Marshal(&before)
	c.Assert(err, IsNil)

	after := make(RecurrenceDateTimes, 0)
	err = icalendar.Unmarshal(encoded, &after)
	c.Assert(err, IsNil)

	c.Assert(after[0], DeepEquals, before[0])

}
Ejemplo n.º 7
0
func (s *DurationSuite) TestIdentity(c *C) {

	type test struct {
		*Duration
	}

	before := &test{Duration: NewDuration(12*time.Hour + 10*time.Minute)}
	encoded, err := icalendar.Marshal(before)
	c.Assert(err, IsNil)

	after := new(test)
	err = icalendar.Unmarshal(encoded, after)
	c.Assert(err, IsNil)

	c.Assert(after, DeepEquals, before)

}