Class: FileApiClient

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

Defined Under Namespace

Classes: Edit, 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

#get_fileObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dynalist/file_api_client.rb', line 5

def get_file
  response = @conn.post "#{@base}file/list", {token: @token}.to_json
  check_response!(response)
  json = JSON.parse(response.body, symbolize_names: true)

  FileTree.instance.root_id = json[:root_file_id]
  json[:files].map do |file|
    instance = if file[:type] == 'folder'
        Folder.new(file)
      else
        Document.new(file)
      end
    FileTree.add(instance)

    instance
  end
end

#move_file(queries) ⇒ Object



23
24
25
26
27
28
# File 'lib/dynalist/file_api_client.rb', line 23

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