Module: Putio::Client::Files

Included in:
Putio::Client
Defined in:
lib/putio/client/files.rb

Instance Method Summary collapse

Instance Method Details

#delete_files(*file_ids) ⇒ Object

Deletes given files

Returns [true]

Parameters:

  • file_ids (Array<Integer>)

    File ids separated by commas. Ex: 1,2,3,4



91
92
93
94
95
96
97
98
99
# File 'lib/putio/client/files.rb', line 91

def delete_files(*file_ids)
  resp = post '/files/delete', { file_ids: file_ids.join(',') }

  if resp.body["status"] == "OK"
    true
  else
    false
  end
end

#file(id:, options: {}) ⇒ Putio::Resource::File

Returns a file’s properties.

Parameters:

  • id (Integer)
  • options (defaults to: {})

Options Hash (options:):

  • parent_id: (Integer)

    ID of the folder you’d like to list. This defaults to the root directory (which has ID number 0).

Returns:



79
80
81
82
83
84
85
# File 'lib/putio/client/files.rb', line 79

def file(id:, options:{})
  defaults = { parent_id: 0 }
  options  = defaults.merge!(options)

  resp = get "/files/#{id}", options
  file_factory.call(resp.body["file"])
end

#list_files(options: {}) ⇒ Array<Putio::Resource::File> Also known as: files

Lists files in a folder

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options:):

  • parent_id: (Integer)

    ID of the folder you’d like to list. This defaults to the root directory (which has ID number 0).

Returns:



15
16
17
18
19
20
21
22
23
# File 'lib/putio/client/files.rb', line 15

def list_files(options:{})
  defaults = { parent_id: 0 }
  options  = defaults.merge!(options)

  resp = get '/files/list', options
  resp.body["files"].inject([]) do |memo, data|
    memo.push file_factory.call(data)
  end
end

#search(query:, options: {}) ⇒ Array<Putio::Resource::File>

Search a file

Examples:

result = client.search(query: "foo")
# => returns first page of results for "foo"

result = client.search(query: "foo", page: 2)
# => returns page 2 of results for "foo"

result = client.search(query: "foo", page:-1)
# => returns all results for "foo"

result = client.search(query: 'jazz', options: { from: 'me,jack', ext: 'mp4', time: 'today' })
# => Searches yours and jack’s files with the word jazz in its title which has the extension mp3 and created today.

result = client.search(query: 'jazz album', options: { from: 'shares', time: 'thisweek' })
# => Searches items shared with you with jazz album which are created thisweek

result = client.search(query: 'jazz', options: { type: 'iphone' })
# => Searches your files and items shared with the word jazz in its title which are converted to mp4

Parameters:

  • query (String)

    The keyword to search

  • options (Hash) (defaults to: {})

    Search Syntax params

Options Hash (options:):

  • page: (Integer)

    Defaults to 1. If -1 given, returns all results at a time.

  • from: (String)

    me, shares, jack or all

  • type: (String)

    video, audio, image, iphone or all

  • ext: (String)

    mp3, avi, jpg, mp4 or all

  • time: (String)

    today, yesterday, thisweek or all

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/putio/client/files.rb', line 55

def search(query:, options: {})
  valid_search_options = %i{ page from type ext time }
  options.select! { |o| valid_search_options.include?(o) }

  page = options.delete(:page)
  path = if page
    "/files/search/#{query}/page/#{page}"
  else
    "/files/search/#{query}"
  end

  resp = get path, options

  resp.body["files"].inject([]) do |memo, data|
    memo.push file_factory.call(data)
  end
end