-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add seagull settings and preferences object.
- Loading branch information
1 parent
7d32881
commit 5abaa66
Showing
7 changed files
with
232 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package user | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
type Preferences struct { | ||
SeenShareDataBannerDate *time.Time `json:"seenShareDataBannerDate"` | ||
SeenShareDataBannerCount int `json:"seenShareDataBannerCount"` | ||
DismissedShareDataBannerTime *time.Time `json:"dismissedShareDataBannerTime"` | ||
DismissedDonateYourDataBannerTime *time.Time `json:"dismissedDonateYourDataBannerTime"` | ||
DismissedDexcomConnectBannerTime *time.Time `json:"dismissedDexcomConnectBannerTime"` | ||
DismissedUpdateTypeBannerTime *time.Time `json:"dismissedUpdateTypeBannerTime"` | ||
} | ||
|
||
func (p *Preferences) ToAttributes() map[string][]string { | ||
attributes := map[string][]string{} | ||
|
||
if p.SeenShareDataBannerDate != nil { | ||
addAttribute(attributes, "preferences.seenShareDataBannerDate", p.SeenShareDataBannerDate.Format(time.RFC3339)) | ||
} | ||
addAttribute(attributes, "preferences.seenShareDataBannerCount", fmt.Sprintf("%d", p.SeenShareDataBannerCount)) | ||
if p.DismissedShareDataBannerTime != nil { | ||
addAttribute(attributes, "preferences.dismissedShareDataBannerTime", p.DismissedShareDataBannerTime.Format(time.RFC3339)) | ||
} | ||
if p.DismissedDonateYourDataBannerTime != nil { | ||
addAttribute(attributes, "preferences.dismissedDonateYourDataBannerTime", p.DismissedDonateYourDataBannerTime.Format(time.RFC3339)) | ||
} | ||
if p.DismissedDexcomConnectBannerTime != nil { | ||
addAttribute(attributes, "preferences.dismissedDexcomConnectBannerTime", p.DismissedDexcomConnectBannerTime.Format(time.RFC3339)) | ||
} | ||
if p.DismissedUpdateTypeBannerTime != nil { | ||
addAttribute(attributes, "preferences.dismissedUpdateTypeBannerTime", p.DismissedUpdateTypeBannerTime.Format(time.RFC3339)) | ||
} | ||
return attributes | ||
} | ||
|
||
func preferencesFromAttributes(attributes map[string][]string) (prefs *Preferences, ok bool) { | ||
if !containsAnyAttributeKeys(attributes, "preferences.seenShareDataBannerDate", "preferences.seenShareDataBannerCount", "preferences.dismissedShareDataBannerTime", "preferences.dismissedDonateYourDataBannerTime", "preferences.dismissedDexcomConnectBannerTime", "preferences.dismissedUpdateTypeBannerTime") { | ||
return nil, false | ||
} | ||
|
||
prefs = &Preferences{} | ||
seenShareDataBannerDate, err := time.Parse(time.RFC3339, getAttribute(attributes, "preferences.seenShareDataBannerDate")) | ||
if err == nil { | ||
prefs.SeenShareDataBannerDate = &seenShareDataBannerDate | ||
} | ||
seenShareDataBannerCount, err := strconv.Atoi(getAttribute(attributes, "preferences.seenShareDataBannerCount")) | ||
if err == nil { | ||
prefs.SeenShareDataBannerCount = seenShareDataBannerCount | ||
} | ||
dismissedShareDataBannerTime, err := time.Parse(time.RFC3339, getAttribute(attributes, "preferences.dismissedShareDataBannerTime")) | ||
if err == nil { | ||
prefs.DismissedShareDataBannerTime = &dismissedShareDataBannerTime | ||
} | ||
dismissedDonateYourDataBannerTime, err := time.Parse(time.RFC3339, getAttribute(attributes, "preferences.dismissedDonateYourDataBannerTime")) | ||
if err == nil { | ||
prefs.DismissedDonateYourDataBannerTime = &dismissedDonateYourDataBannerTime | ||
} | ||
dismissedDexcomConnectBannerTime, err := time.Parse(time.RFC3339, getAttribute(attributes, "preferences.dismissedDexcomConnectBannerTime")) | ||
if err == nil { | ||
prefs.DismissedDexcomConnectBannerTime = &dismissedDexcomConnectBannerTime | ||
} | ||
dismissedUpdateTypeBannerTime, err := time.Parse(time.RFC3339, getAttribute(attributes, "preferences.dismissedUpdateTypeBannerTime")) | ||
if err == nil { | ||
prefs.DismissedUpdateTypeBannerTime = &dismissedUpdateTypeBannerTime | ||
} | ||
|
||
return prefs, true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package user | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
type Settings struct { | ||
SiteChangeSource string `json:"siteChangeSource"` | ||
BGTarget *settingsBGTarget `json:"bgTarget,omitempty"` | ||
Units *settingsUnits `json:"units,omitempty"` | ||
} | ||
|
||
type settingsBGTarget struct { | ||
High float64 `json:"high"` | ||
Low float64 `json:"low"` | ||
} | ||
|
||
type settingsUnits struct { | ||
BG string `json:"bg"` | ||
} | ||
|
||
func (s *Settings) ToAttributes() map[string][]string { | ||
attributes := map[string][]string{} | ||
|
||
addAttribute(attributes, "settings.siteChangeSource", s.SiteChangeSource) | ||
if s.BGTarget != nil { | ||
addAttribute(attributes, "settings.bgTarget.high", fmt.Sprintf("%.1f", s.BGTarget.High)) | ||
addAttribute(attributes, "settings.bgTarget.low", fmt.Sprintf("%.1f", s.BGTarget.Low)) | ||
} | ||
if s.Units != nil { | ||
addAttribute(attributes, "settings.units.bg", s.Units.BG) | ||
} | ||
return attributes | ||
} | ||
|
||
func settingsFromAttributes(attributes map[string][]string) (settings *Settings, ok bool) { | ||
if !containsAnyAttributeKeys(attributes, "settings.siteChangeSource", "settings.bgTarget.high", "settings.bgTarget.low", "settings.units.bg") { | ||
return nil, false | ||
} | ||
|
||
settings = &Settings{} | ||
settings.SiteChangeSource = getAttribute(attributes, "settings.siteChangeSource") | ||
if containsAnyAttributeKeys(attributes, "settings.bgTarget.high", "settings.bgTarget.low") { | ||
low, lowErr := strconv.ParseFloat(getAttribute(attributes, "settings.bgTarget.low"), 64) | ||
high, highErr := strconv.ParseFloat(getAttribute(attributes, "settings.bgTarget.high"), 64) | ||
if lowErr == nil && highErr == nil { | ||
settings.BGTarget = &settingsBGTarget{ | ||
Low: low, | ||
High: high, | ||
} | ||
} | ||
} | ||
if containsAnyAttributeKeys(attributes, "settings.units.bg") { | ||
settings.Units = &settingsUnits{ | ||
BG: getAttribute(attributes, "settings.units.bg"), | ||
} | ||
} | ||
return settings, true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters