Class: NodeApiClient

Inherits:
BaseApiClient show all
Defined in:
lib/dynalist/node_api_client.rb

Defined Under Namespace

Classes: Delete, Edit, Insert, Move

Constant Summary

Constants inherited from BaseApiClient

BaseApiClient::ApiErrors

Instance Method Summary collapse

Methods inherited from BaseApiClient

#check_response!, #initialize

Constructor Details

This class inherits a constructor from BaseApiClient

Instance Method Details

#check_updates(documents) ⇒ Object



13
14
15
16
17
18
# File 'lib/dynalist/node_api_client.rb', line 13

def check_updates(documents)
  document_ids = documents.map(&:id)
  response = @conn.post "#{@base}doc/check_for_updates", {token: @token, file_ids: document_ids}.to_json
  check_response!(response)
  JSON.parse(response.body, symbolize_names: true)[:versions]
end

#edit(document, queries) ⇒ Object



20
21
22
23
24
25
# File 'lib/dynalist/node_api_client.rb', line 20

def edit(document, queries)
  changes = queries.map(&:to_query)
  response = @conn.post "#{@base}doc/edit", {token: @token, file_id: document.id, changes: changes}.to_json
  check_response!(response)
  JSON.parse(response.body, symbolize_names: true)[:new_node_ids]
end

#read(document) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/dynalist/node_api_client.rb', line 5

def read(document)
  response = @conn.post "#{@base}doc/read", {token: @token, file_id: document.id}.to_json
  check_response!(response)
  JSON.parse(response.body, symbolize_names: true)[:nodes].map{ |node| node }
  nodes = JSON.parse(response.body, symbolize_names: true)[:nodes].map{ |node| Node.new(node.merge(file_id: document.id)) }
  NodeTree.add(nodes)
end