Class: Nin::Integration::Todoist::Client::Sync

Inherits:
BaseClient show all
Defined in:
lib/nin/integration/todoist/client/sync.rb

Constant Summary collapse

API_URI =
"#{BASE_URI}/sync".freeze

Instance Method Summary collapse

Methods inherited from BaseClient

#initialize

Constructor Details

This class inherits a constructor from Nin::Integration::Todoist::Client::BaseClient

Instance Method Details

#read_resources(resource_types = ['all'], sync_token = '*') ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/nin/integration/todoist/client/sync.rb', line 8

def read_resources(resource_types = ['all'], sync_token = '*')
  res = HTTP.headers(accept: "application/json")
    .get("#{BASE_URI}/sync", params: { token: @token,
                                       sync_token: sync_token,
                                       resource_types: resource_types.to_json })

  data = JSON.parse(res.body.to_s)
  unless resource_types == ['all']
    data.slice(*resource_types)
  else
    data
  end
end

#write_resources(commands) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/nin/integration/todoist/client/sync.rb', line 22

def write_resources(commands)
  res = HTTP.headers(accept: "application/json")
    .get("#{BASE_URI}/sync", params: { token: @token,
                                       commands: commands })

  JSON.parse(res.body.to_s)
end