Skip to content

Commit

Permalink
make some members private
Browse files Browse the repository at this point in the history
  • Loading branch information
kobtea committed Jan 29, 2017
1 parent 187c69f commit a6caf03
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
44 changes: 22 additions & 22 deletions todoist/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Client struct {
Token string
SyncToken string
CacheDir string
SyncState *SyncState
syncState *SyncState
Logger *log.Logger
Filter *FilterClient
Item *ItemClient
Expand Down Expand Up @@ -67,7 +67,7 @@ func NewClient(endpoint, token, sync_token, cache_dir string, logger *log.Logger
Token: token,
SyncToken: sync_token,
CacheDir: cache_dir,
SyncState: &SyncState{},
syncState: &SyncState{},
Logger: logger,
}
c.Filter = &FilterClient{c}
Expand All @@ -80,7 +80,7 @@ func NewClient(endpoint, token, sync_token, cache_dir string, logger *log.Logger
return c, nil
}

func (c *Client) NewRequest(ctx context.Context, method, spath string, values url.Values) (*http.Request, error) {
func (c *Client) newRequest(ctx context.Context, method, spath string, values url.Values) (*http.Request, error) {
u := *c.URL
u.Path = path.Join(c.URL.Path, spath)
values.Add("token", c.Token)
Expand Down Expand Up @@ -108,8 +108,8 @@ func (c *Client) NewRequest(ctx context.Context, method, spath string, values ur
return req, nil
}

func (c *Client) NewSyncRequest(ctx context.Context, values url.Values) (*http.Request, error) {
return c.NewRequest(ctx, http.MethodPost, "sync", values)
func (c *Client) newSyncRequest(ctx context.Context, values url.Values) (*http.Request, error) {
return c.newRequest(ctx, http.MethodPost, "sync", values)
}

func decodeBody(resp *http.Response, out interface{}) error {
Expand All @@ -129,7 +129,7 @@ func (c *Client) Sync(ctx context.Context, commands []Command) error {
"resource_types": {"[\"all\"]"},
"commands": {string(b)},
}
req, err := c.NewSyncRequest(ctx, values)
req, err := c.newSyncRequest(ctx, values)
if err != nil {
return err
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func (c *Client) ResetSyncToken() {

func (c *Client) resetState() {
c.SyncToken = "*"
c.SyncState = &SyncState{}
c.syncState = &SyncState{}
}

func (c *Client) updateState(state *SyncState) {
Expand All @@ -189,17 +189,17 @@ func (c *Client) updateState(state *SyncState) {
cachedFilter := c.Filter.Resolve(filter.ID)
if cachedFilter == nil {
if !filter.IsDeleted {
c.SyncState.Filters = append(c.SyncState.Filters, filter)
c.syncState.Filters = append(c.syncState.Filters, filter)
}
} else {
if filter.IsDeleted {
var res []Filter
for _, f := range c.SyncState.Filters {
for _, f := range c.syncState.Filters {
if !f.Equal(cachedFilter) {
res = append(res, f)
}
}
c.SyncState.Filters = res
c.syncState.Filters = res
} else {
cachedFilter = &filter
}
Expand All @@ -209,17 +209,17 @@ func (c *Client) updateState(state *SyncState) {
cachedItem := c.Item.Resolve(item.ID)
if cachedItem == nil {
if !item.IsDeleted {
c.SyncState.Items = append(c.SyncState.Items, item)
c.syncState.Items = append(c.syncState.Items, item)
}
} else {
if item.IsDeleted {
var res []Item
for _, i := range c.SyncState.Items {
for _, i := range c.syncState.Items {
if !i.Equal(cachedItem) {
res = append(res, i)
}
}
c.SyncState.Items = res
c.syncState.Items = res
} else {
cachedItem = &item
}
Expand All @@ -229,17 +229,17 @@ func (c *Client) updateState(state *SyncState) {
cachedLabel := c.Label.Resolve(label.ID)
if cachedLabel == nil {
if !label.IsDeleted {
c.SyncState.Labels = append(c.SyncState.Labels, label)
c.syncState.Labels = append(c.syncState.Labels, label)
}
} else {
if label.IsDeleted {
var res []Label
for _, l := range c.SyncState.Labels {
for _, l := range c.syncState.Labels {
if !l.Equal(cachedLabel) {
res = append(res, l)
}
}
c.SyncState.Labels = res
c.syncState.Labels = res
} else {
cachedLabel = &label
}
Expand All @@ -249,31 +249,31 @@ func (c *Client) updateState(state *SyncState) {
cachedProject := c.Project.Resolve(project.ID)
if cachedProject == nil {
if !project.IsDeleted {
c.SyncState.Projects = append(c.SyncState.Projects, project)
c.syncState.Projects = append(c.syncState.Projects, project)
}
} else {
if project.IsDeleted {
var res []Project
for _, p := range c.SyncState.Projects {
for _, p := range c.syncState.Projects {
if !p.Equal(cachedProject) {
res = append(res, p)
}
}
c.SyncState.Projects = res
c.syncState.Projects = res
} else {
cachedProject = &project
}
}
}
c.SyncState = state
c.syncState = state
}

func (c *Client) readCache() error {
b, err := ioutil.ReadFile(path.Join(c.CacheDir, c.Token+".json"))
if err != nil {
return err
}
if err = json.Unmarshal(b, c.SyncState); err != nil {
if err = json.Unmarshal(b, c.syncState); err != nil {
return err
}
b, err = ioutil.ReadFile(path.Join(c.CacheDir, c.Token+".sync"))
Expand All @@ -288,7 +288,7 @@ func (c *Client) writeCache() error {
if len(c.CacheDir) == 0 {
return nil
}
b, err := json.MarshalIndent(c.SyncState, "", " ")
b, err := json.MarshalIndent(c.syncState, "", " ")
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions todoist/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (c *FilterClient) Add(filter Filter) (*Filter, error) {
return nil, errors.New("New filter requires a query")
}
filter.ID = GenerateTempID()
c.SyncState.Filters = append(c.SyncState.Filters, filter)
c.syncState.Filters = append(c.syncState.Filters, filter)
command := Command{
Type: "filter_add",
Args: filter,
Expand Down Expand Up @@ -70,7 +70,7 @@ type FilterGetResponse struct {

func (c *FilterClient) Get(ctx context.Context, id ID) (*FilterGetResponse, error) {
values := url.Values{"filter_id": {id.String()}}
req, err := c.NewRequest(ctx, http.MethodGet, "filters/get", values)
req, err := c.newRequest(ctx, http.MethodGet, "filters/get", values)
if err != nil {
return nil, err
}
Expand All @@ -87,7 +87,7 @@ func (c *FilterClient) Get(ctx context.Context, id ID) (*FilterGetResponse, erro
}

func (c *FilterClient) Resolve(id ID) *Filter {
for _, filter := range c.SyncState.Filters {
for _, filter := range c.syncState.Filters {
if filter.ID == id {
return &filter
}
Expand Down
6 changes: 3 additions & 3 deletions todoist/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *ItemClient) Add(item Item) (*Item, error) {
}
item.ID = GenerateTempID()
// append item to sync state only `add` method?
c.SyncState.Items = append(c.SyncState.Items, item)
c.syncState.Items = append(c.syncState.Items, item)
command := Command{
Type: "item_add",
Args: item,
Expand Down Expand Up @@ -149,7 +149,7 @@ type ItemGetResponse struct {

func (c *ItemClient) Get(ctx context.Context, id ID) (*ItemGetResponse, error) {
values := url.Values{"item_id": {id.String()}}
req, err := c.NewRequest(ctx, http.MethodGet, "items/get", values)
req, err := c.newRequest(ctx, http.MethodGet, "items/get", values)
if err != nil {
return nil, err
}
Expand All @@ -167,7 +167,7 @@ func (c *ItemClient) Get(ctx context.Context, id ID) (*ItemGetResponse, error) {

func (c *ItemClient) GetCompleted(ctx context.Context, projectID ID) (*[]Item, error) {
values := url.Values{"project_id": {projectID.String()}}
req, err := c.NewRequest(ctx, http.MethodGet, "items/get_completed", values)
req, err := c.newRequest(ctx, http.MethodGet, "items/get_completed", values)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions todoist/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *LabelClient) Add(label Label) (*Label, error) {
return nil, errors.New("New label requires a name")
}
label.ID = GenerateTempID()
c.SyncState.Labels = append(c.SyncState.Labels, label)
c.syncState.Labels = append(c.syncState.Labels, label)
command := Command{
Type: "label_add",
Args: label,
Expand Down Expand Up @@ -66,7 +66,7 @@ type LabelGetResponse struct {

func (c *LabelClient) Get(ctx context.Context, id ID) (*LabelGetResponse, error) {
values := url.Values{"label_id": {id.String()}}
req, err := c.NewRequest(ctx, http.MethodGet, "labels/get", values)
req, err := c.newRequest(ctx, http.MethodGet, "labels/get", values)
if err != nil {
return nil, err
}
Expand All @@ -83,7 +83,7 @@ func (c *LabelClient) Get(ctx context.Context, id ID) (*LabelGetResponse, error)
}

func (c *LabelClient) Resolve(id ID) *Label {
for _, label := range c.SyncState.Labels {
for _, label := range c.syncState.Labels {
if label.ID == id {
return &label
}
Expand Down
10 changes: 5 additions & 5 deletions todoist/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c *ProjectClient) Add(project Project) (*Project, error) {
return nil, errors.New("New project requires a name")
}
project.ID = GenerateTempID()
c.SyncState.Projects = append(c.SyncState.Projects, project)
c.syncState.Projects = append(c.syncState.Projects, project)
command := Command{
Type: "project_add",
Args: project,
Expand Down Expand Up @@ -97,7 +97,7 @@ type ProjectGetResponse struct {

func (c *ProjectClient) Get(ctx context.Context, id ID) (*ProjectGetResponse, error) {
values := url.Values{"project_id": {id.String()}}
req, err := c.NewRequest(ctx, http.MethodGet, "projects/get", values)
req, err := c.newRequest(ctx, http.MethodGet, "projects/get", values)
if err != nil {
return nil, err
}
Expand All @@ -120,7 +120,7 @@ type ProjectGetDataResponse struct {

func (c *ProjectClient) GetData(ctx context.Context, id ID) (*ProjectGetDataResponse, error) {
values := url.Values{"project_id": {id.String()}}
req, err := c.NewRequest(ctx, http.MethodGet, "projects/get_data", values)
req, err := c.newRequest(ctx, http.MethodGet, "projects/get_data", values)
if err != nil {
return nil, err
}
Expand All @@ -138,7 +138,7 @@ func (c *ProjectClient) GetData(ctx context.Context, id ID) (*ProjectGetDataResp

func (c *ProjectClient) GetArchived(ctx context.Context) (*[]Project, error) {
values := url.Values{}
req, err := c.NewRequest(ctx, http.MethodGet, "projects/get_archived", values)
req, err := c.newRequest(ctx, http.MethodGet, "projects/get_archived", values)
if err != nil {
return nil, err
}
Expand All @@ -155,7 +155,7 @@ func (c *ProjectClient) GetArchived(ctx context.Context) (*[]Project, error) {
}

func (c *ProjectClient) Resolve(id ID) *Project {
for _, project := range c.SyncState.Projects {
for _, project := range c.syncState.Projects {
if project.ID == id {
return &project
}
Expand Down

0 comments on commit a6caf03

Please sign in to comment.