Skip to content

Commit

Permalink
feat(parsing): add parameters parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
vareversat committed Oct 13, 2024
1 parent d74527a commit ba5a528
Show file tree
Hide file tree
Showing 42 changed files with 437 additions and 166 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,22 @@ Here the main features this module offers (some are already available ✅ and so
- ✅ With **VTIMEZONE** components
- ✅ With **VTODO** components
- 🟧 Make use of all [properties available](https://datatracker.ietf.org/doc/html/rfc5545#section-3.2)
- ✅ All are implemented
- 🟧 Work needed for **EXRULE**, **FREEBUSY**, **RDATE**, **RRULE** and **RRULE**
- 🟧 Make use of all [types available](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3)
- ✅ All are implemented
- 🟧 Work needed for **RECUR**
- 🟧 Parse an iCalendar file
- ✅ Parsing ics files is implemented
- 🟧 Missing the struct computation
- ✅ Write in an iCalendar file

## Installation

To install gics, use the `go get` command:

```sh
go get github.com/vareversat/gics
go get github.com/vareversat/gics@latest
```

## Type representations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ type AlarmTriggerRelationshipParam interface {
}

// NewAlarmTriggerRelationshipParam create a new registries.AlarmTriggerRelationshipParam property. See [RFC-5545] ref for more info
//
// This parameter can be used in this property :
// - registries.TriggerProp
//
// - [registries.TriggerProp]
//
// [RFC-5545]: https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.14
func NewAlarmTriggerRelationshipParam(
value registries.AlarmTriggerRelationshipTypeRegistry,
Expand All @@ -21,3 +24,19 @@ func NewAlarmTriggerRelationshipParam(
Value: types.NewTextValue(string(value)),
}
}

// NewAlarmTriggerRelationshipParam create a new registries.AlarmTriggerRelationshipParam property from string value. See [RFC-5545] ref for more info
//
// This parameter can be used in this property :
//
// - [registries.TriggerProp]
//
// [RFC-5545]: https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.14
func NewAlarmTriggerRelationshipParamFromString(
value string,
) AlarmTriggerRelationshipParam {
return &textParameter{
ParamName: registries.AlarmTriggerRelationshipParam,
Value: types.NewTextValue(string(value)),
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parameters

import (
"fmt"
"net/url"

"github.com/vareversat/gics/registries"
Expand All @@ -13,16 +14,30 @@ type AlternateTextRepresentationParam interface {

// NewAlternateTextRepresentationParam create a new registries.AlternateTextRepresentationParam property. See [RFC-5545] ref for more info
// This parameter can be used in these properties :
// - registries.CommentProp
// - registries.DescriptionProp
// - registries.LocationProp
// - registries.ResourcesProp
// - registries.SummaryProp
// - registries.ContactProp
// - registries.CommentProp
// - registries.DescriptionProp
// - registries.LocationProp
// - registries.ResourcesProp
// - registries.SummaryProp
// - registries.ContactProp
//
// [RFC-5545]: https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.1
func NewAlternateTextRepresentationParam(value *url.URL) AlternateTextRepresentationParam {
return &uriParameter{
ParamName: registries.AlternateTextRepresentationParam,
Value: types.NewUriValue(value),
}
}

func NewAlternateTextRepresentationParamFromString(
value string,
) (AlternateTextRepresentationParam, error) {
urlValue, err := url.Parse(value)
if err != nil {
return nil, fmt.Errorf("%s is not a valid URL format", value)
}
return &uriParameter{
ParamName: registries.AlternateTextRepresentationParam,
Value: types.NewUriValue(urlValue),
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ func NewCalendarUserTypeParam(value registries.CalendarUserTypeRegistry) Calenda
Value: types.NewTextValue(string(value)),
}
}

func NewCalendarUserTypeParamFromString(value string) CalendarUserTypeParam {
return &textParameter{
ParamName: registries.CalendarUserTypeParam,
Value: types.NewTextValue(value),
}
}
File renamed without changes.
35 changes: 35 additions & 0 deletions parameters/delegated_from_parameter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package parameters

import (
"fmt"
"net/url"

"github.com/vareversat/gics/registries"
"github.com/vareversat/gics/types"
)

type DelegatedFromParam interface {
CalendarUserAddressTypeParameter
}

// NewDelegatedFromParam create a new registries.DelegatedFromParam property. See [RFC-5545] ref for more info
// This parameter can be used in this property :
// - registries.AttendeeProp
// [RFC-5545]: https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.4
func NewDelegatedFromParam(value *url.URL) DelegatedFromParam {
return &calendarUserAddressParameter{
ParamName: registries.DelegatedFromParam,
Value: types.NewCalendarUserAddressValue(value),
}
}

func NewDelegatedFromParamFromString(value string) (DelegatedFromParam, error) {
urlValue, err := url.Parse(value)
if err != nil {
return nil, fmt.Errorf("%s is not a valid URL format", value)
}
return &calendarUserAddressParameter{
ParamName: registries.DelegatedFromParam,
Value: types.NewCalendarUserAddressValue(urlValue),
}, nil
}
35 changes: 35 additions & 0 deletions parameters/delegated_to_parameter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package parameters

import (
"fmt"
"net/url"

"github.com/vareversat/gics/registries"
"github.com/vareversat/gics/types"
)

type DelegatedToParam interface {
CalendarUserAddressTypeParameter
}

// NewDelegatedToParam create a new registries.DelegatedToParam property. See [RFC-5545] ref for more info
// This parameter can be used in this property :
// - registries.AttendeeProp
// [RFC-5545]: https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.5
func NewDelegatedToParam(value *url.URL) DelegatedToParam {
return &calendarUserAddressParameter{
ParamName: registries.DelegatedToParam,
Value: types.NewCalendarUserAddressValue(value),
}
}

func NewDelegatedToParamFromString(value string) (DelegatedToParam, error) {
urlValue, err := url.Parse(value)
if err != nil {
return nil, fmt.Errorf("%s is not a valid URL format", value)
}
return &calendarUserAddressParameter{
ParamName: registries.DelegatedToParam,
Value: types.NewCalendarUserAddressValue(urlValue),
}, nil
}
23 changes: 0 additions & 23 deletions parameters/delegatees.go

This file was deleted.

23 changes: 0 additions & 23 deletions parameters/delegators.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parameters

import (
"fmt"
"net/url"

"github.com/vareversat/gics/registries"
Expand All @@ -22,3 +23,14 @@ func NewDirectoryEntryParam(value *url.URL) DirectoryEntryParam {
Value: types.NewUriValue(value),
}
}

func NewDirectoryEntryParamFromString(value string) (DirectoryEntryParam, error) {
urlValue, err := url.Parse(value)
if err != nil {
return nil, fmt.Errorf("%s is not a valid URL format", value)
}
return &uriParameter{
ParamName: registries.DirectoryEntryReferenceParam,
Value: types.NewUriValue(urlValue),
}, nil
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ func NewFreeBusyTimeParam(value registries.FreeBusyTimeTypeRegistry) FreeBusyTim
Value: types.NewTextValue(string(value)),
}
}

func NewFreeBusyTimeParamFromString(value string) FreeBusyTimeParam {
return &textParameter{
ParamName: registries.FreeBusyTimeTypeParam,
Value: types.NewTextValue(value),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ func NewInlineEncodingParam(value registries.EncodingTypeRegistry) InlineEncodin
Value: types.NewTextValue(string(value)),
}
}

func NewInlineEncodingParamFromString(value string) InlineEncodingParam {
return &textParameter{
ParamName: registries.EncodingParam,
Value: types.NewTextValue(value),
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions parameters/member.go → parameters/member_parameter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parameters

import (
"fmt"
"net/url"

"github.com/vareversat/gics/registries"
Expand All @@ -21,3 +22,14 @@ func NewMemberParam(value *url.URL) MemberParam {
Value: types.NewCalendarUserAddressValue(value),
}
}

func NewMemberParamFromString(value string) (MemberParam, error) {
urlValue, err := url.Parse(value)
if err != nil {
return nil, fmt.Errorf("%s is not a valid URL format", value)
}
return &calendarUserAddressParameter{
ParamName: registries.MemberParam,
Value: types.NewCalendarUserAddressValue(urlValue),
}, nil
}
12 changes: 12 additions & 0 deletions parameters/non_standard_parameter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package parameters

import (
"github.com/vareversat/gics/types"
)

func NewNonStandardParameter(parameterName string, parameterValue string) NonStandardParameter {
return &nonStandardParameter{
ParamName: parameterName,
Value: types.NewTextValue(parameterValue),
}
}
23 changes: 23 additions & 0 deletions parameters/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,26 @@ func (cP *calendarUserAddressParameter) GetParamName() registries.ParameterRegis
func (cP *calendarUserAddressParameter) GetParamValue() string {
return fmt.Sprintf("\"%s\"", cP.Value.GetValue())
}

// CalendarUserAddressTypeParameter is the interface representation of a calendar user address typed parameter
// Go representation: string
type NonStandardParameter interface {
Parameter
}

type nonStandardParameter struct {
ParamName string
Value types.TextValue
}

func (nSP *nonStandardParameter) ToICalendarParamFormat(output io.Writer) {
output.Write([]byte(fmt.Sprintf("%s=%s", nSP.ParamName, nSP.GetParamValue())))
}

func (nSP *nonStandardParameter) GetParamName() registries.ParameterRegistry {
return registries.NonStandardParam
}

func (nSP *nonStandardParameter) GetParamValue() string {
return nSP.Value.S
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ func NewParticipationRoleParam(value registries.ParticipantRoleRegistry) Partici
Value: types.NewTextValue(string(value)),
}
}

func NewParticipationRoleParamFromString(value string) ParticipationRoleParam {
return &textParameter{
ParamName: registries.RoleParam,
Value: types.NewTextValue(value),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ func NewParticipationStatusParam(
Value: types.NewTextValue(string(value)),
}
}

func NewParticipationStatusParamFromString(
value string,
) ParticipationStatusParam {
return &textParameter{
ParamName: registries.ParticipationStatusParam,
Value: types.NewTextValue(value),
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ func NewRelationshipParam(value registries.RelationshipTypeRegistry) Relationshi
Value: types.NewTextValue(string(value)),
}
}

func NewRelationshipParamFromString(value string) RelationshipParam {
return &textParameter{
ParamName: registries.RelationshipTypeParam,
Value: types.NewTextValue(value),
}
}
Loading

0 comments on commit ba5a528

Please sign in to comment.