Class: SharefileConnect::Data

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/sharefile_connect/data.rb

Instance Method Summary collapse

Instance Method Details

#folder_access_info(id) ⇒ Object



9
10
11
# File 'lib/sharefile_connect/data.rb', line 9

def folder_access_info(id)
  parse_get("/Items(#{id})/Info").body
end

#folder_exists?(name, parent_id = nil) ⇒ Boolean

def create_folder parent_id, name, description = ”

unless folder_exists?(name, parent_id)
  body = {
      "Name"        => name,
      "Description" => description || name
  }
  HTTParty.post(full("Items#{parent_id}/Folder?overwrite=false&passthrough=false"), { body: body.to_json, headers: authorization_header})
else
  item(folder_in_parent(name, parent_id)['Id'])
end

end

Returns:

  • (Boolean)


29
30
31
# File 'lib/sharefile_connect/data.rb', line 29

def folder_exists?(name, parent_id = nil)
  folder_in_parent(name, parent_id).any?
end

#folder_in_parent(name, parent_id) ⇒ Object



33
34
35
# File 'lib/sharefile_connect/data.rb', line 33

def folder_in_parent(name, parent_id)
  JSON.parse(root(parent_id))['Children'].select { |f| f['Name'] == name }
end

#item(id) ⇒ Object



13
14
15
# File 'lib/sharefile_connect/data.rb', line 13

def item(id)
  get("/Items(#{id})")
end

#items_by_path(paths) ⇒ Object



37
38
39
# File 'lib/sharefile_connect/data.rb', line 37

def items_by_path(paths)
  parse_get("/Items/ByPath?path=/#{paths.join('/')}/&$expand=Children&$select=Id,Name,Children/Id,Children/Name")
end

#items_by_path_id(paths) ⇒ Object



41
42
43
44
# File 'lib/sharefile_connect/data.rb', line 41

def items_by_path_id(paths)
  r = items_by_path(paths).response
  JSON.parse(r.body)['Id'] if r.kind_of?(Net::HTTPOK)
end

#root(id = nil) ⇒ Object



5
6
7
# File 'lib/sharefile_connect/data.rb', line 5

def root(id = nil)
  parse_get("/Items(#{id || 'allshared'})?$expand=Children&$select=Id,Name,Children/Id,Children/Name").body
end

#upload_file(folder_id, file_path) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sharefile_connect/data.rb', line 46

def upload_file folder_id, file_path
  path          = "/Items(#{folder_id})/Upload"
  response      = HTTParty.get(full(path), headers: authorization_header)
  upload_config = JSON.parse response.body
  multipart_form_post upload_config['ChunkUri'], file_path
  # HTTMultiParty.post(upload_config["ChunkUri"], body: { file1: File.new(file_path) } )
  # File.open(file_path) do |transfile|
  #   # HTTMultiParty.post(upload_config["ChunkUri"], query: { file1: File.read(transfile) })
  #   # HTTMultiParty.post(upload_config["ChunkUri"], query: { file1: UploadIO.new(transfile, "multipart/formdata", File.basename(file_path)) })
  #   # HTTMultiParty.post(upload_config["ChunkUri"], query: { file1: UploadIO.new(File.open(file_path), "multipart/formdata") })
  # end
end

#zone_idObject



63
64
65
# File 'lib/sharefile_connect/data.rb', line 63

def zone_id
  JSON.parse(zones.response.body)['value'].map { |x| x['Id'] if x['ZoneType'] == 'CitrixManaged' }.compact.first
end

#zonesObject



59
60
61
# File 'lib/sharefile_connect/data.rb', line 59

def zones
  get("/Zones")
end