Class: Ayadn::FileOps

Inherits:
Object
  • Object
show all
Defined in:
lib/ayadn/fileops.rb

Class Method Summary collapse

Class Method Details

.download_url(name, url) ⇒ Object



28
29
30
31
# File 'lib/ayadn/fileops.rb', line 28

def self.download_url(name, url)
  file = CNX.get_response_from(url)
  File.write(Settings.config[:paths][:downloads] + "/#{name}", file)
end

.make_paths(files_array) ⇒ Object



59
60
61
62
63
64
# File 'lib/ayadn/fileops.rb', line 59

def self.make_paths(files_array)
  files_array.map do |file|
    abort(Status.bad_path) unless File.exist?(file)
    File.absolute_path(file)
  end
end

.old_ayadn?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/ayadn/fileops.rb', line 33

def self.old_ayadn?
  Dir.exist?(Dir.home + "/ayadn/data")
end

.save_followers_list(list) ⇒ Object



18
19
20
21
# File 'lib/ayadn/fileops.rb', line 18

def self.save_followers_list(list)
  fr = get_users(list)
  File.write(Settings.config[:paths][:lists] + "/followers.json", fr.to_json)
end

.save_followings_list(list) ⇒ Object



13
14
15
16
# File 'lib/ayadn/fileops.rb', line 13

def self.save_followings_list(list)
  fg = get_users(list)
  File.write(Settings.config[:paths][:lists] + "/followings.json", fg.to_json)
end

.save_message(resp) ⇒ Object



9
10
11
# File 'lib/ayadn/fileops.rb', line 9

def self.save_message(resp)
  File.write(Settings.config[:paths][:messages] + "/#{resp['data']['id']}.json", resp['data'].to_json)
end

.save_muted_list(list) ⇒ Object



23
24
25
26
# File 'lib/ayadn/fileops.rb', line 23

def self.save_muted_list(list)
  mt = get_users(list)
  File.write(Settings.config[:paths][:lists] + "/muted.json", mt.to_json)
end

.save_post(resp) ⇒ Object



5
6
7
# File 'lib/ayadn/fileops.rb', line 5

def self.save_post(resp)
  File.write(Settings.config[:paths][:posts] + "/#{resp['data']['id']}.json", resp['data'].to_json)
end

.upload(file, token) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ayadn/fileops.rb', line 44

def self.upload(file, token)
  begin
    case File.extname(file).downcase
    when ".png"
      `curl -k -H 'Authorization: BEARER #{token}' https://api.app.net/files -F 'type=com.ayadn.files' -F "content=@#{file};type=image/png" -F 'public=true' -X POST`
    when ".gif"
      `curl -k -H 'Authorization: BEARER #{token}' https://api.app.net/files -F 'type=com.ayadn.files' -F "content=@#{file};type=image/gif" -F 'public=true' -X POST`
    else #jpg or jpeg or JPG or JPEG, automatically recognized as such
      `curl -k -H 'Authorization: BEARER #{token}' https://api.app.net/files -F 'type=com.ayadn.files' -F "content=@#{file}" -F 'public=true' -X POST`
    end
  rescue Errno::ENOENT
    abort(Status.no_curl)
  end
end

.upload_avatar(file) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/ayadn/fileops.rb', line 66

def self.upload_avatar file
  begin
    `curl -X POST -H "Authorization: Bearer #{Settings.user_token}" -F "avatar=@#{file}" #{Endpoints.new.avatar}`
  rescue Errno::ENOENT
    abort(Status.no_curl)
  end
end

.upload_cover(file) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/ayadn/fileops.rb', line 74

def self.upload_cover file
  begin
    `curl -X POST -H "Authorization: Bearer #{Settings.user_token}" -F "cover=@#{file}" #{Endpoints.new.cover}`
  rescue Errno::ENOENT
    abort(Status.no_curl)
  end
end

.upload_files(files) ⇒ Object



37
38
39
40
41
42
# File 'lib/ayadn/fileops.rb', line 37

def self.upload_files files
  files.map do |file|
    puts "\n#{file}\n\n"
    JSON.load(self.upload(file, Settings.user_token))
  end
end