Class: Springcm::Folder
- Defined in:
- lib/springcm-sdk/folder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy(path: nil, uid: nil) ⇒ Object
- #create_folder(name:) ⇒ Object
-
#documents(offset: 0, limit: 20) ⇒ Object
Retrieve a page of documents in this folder.
-
#folders(offset: 0, limit: 20) ⇒ Object
Retrieve a page of folders contained in this folder.
-
#parent_folder ⇒ Object
Retrieve the containing folder.
-
#update_security(group:, access:) ⇒ Object
access InheritFromParentFolder, NoAccess, View, ViewCreate, ViewEdit, ViewEditDelete, ViewEditDeleteSetAccess.
- #upload(name:, file:, type: :binary) ⇒ Object
Methods included from Mixins::Attributes
#apply_attribute_group, #attribute_group, #attribute_groups=
Methods included from Mixins::Documents
Methods included from Mixins::ParentFolder
Methods included from Mixins::AccessLevel
#access_level, #create?, #move?, #read?, #see?, #set_access?, #write?
Methods inherited from Resource
#delete, #get, #patch, #put, #reload, #reload!, #resource_name, #resource_params, #resource_uri, #uid
Methods inherited from Object
#initialize, #method_missing, #raw
Constructor Details
This class inherits a constructor from Springcm::Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Springcm::Object
Class Method Details
.resource_params ⇒ Object
19 20 21 22 23 |
# File 'lib/springcm-sdk/folder.rb', line 19 def self.resource_params { "expand" => "attributegroups,path" } end |
Instance Method Details
#copy(path: nil, uid: nil) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/springcm-sdk/folder.rb', line 159 def copy(path: nil, uid: nil) parent = @client.folder(path: path, uid: uid) body = { "DestinationFolder" => parent.raw, "FoldersToCopy" => [ raw ] } conn = @client.(url: @client.object_api_url) res = conn.post do |req| req.headers["Content-Type"] = "application/json" req.url "copytasks" req.body = body.to_json end if res.success? data = JSON.parse(res.body) CopyTask.new(data, @client) else nil end end |
#create_folder(name:) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/springcm-sdk/folder.rb', line 141 def create_folder(name:) conn = @client.(url: @client.object_api_url) res = conn.post do |req| req.headers["Content-Type"] = "application/json" req.url "folders" req.body = { "ParentFolder" => raw, "Name" => name }.to_json end if res.success? data = JSON.parse(res.body) Folder.new(data, @client) else nil end end |
#documents(offset: 0, limit: 20) ⇒ Object
Retrieve a page of documents in this folder.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/springcm-sdk/folder.rb', line 62 def documents(offset: 0, limit: 20) Helpers.validate_offset_limit!(offset, limit) uri = URI(documents_href) url = "#{uri.scheme}://#{uri.host}" conn = @client.(url: url) res = conn.get do |req| req.url uri.path req.params["offset"] = offset req.params["limit"] = limit end if res.success? data = JSON.parse(res.body) ResourceList.new(data, self, Document, @client) else nil end end |
#folders(offset: 0, limit: 20) ⇒ Object
Retrieve a page of folders contained in this folder.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/springcm-sdk/folder.rb', line 26 def folders(offset: 0, limit: 20) Helpers.validate_offset_limit!(offset, limit) conn = @client.(url: @client.object_api_url) res = conn.get do |req| req.url "#{resource_uri}/folders" req.params["offset"] = offset req.params["limit"] = limit end if res.success? data = JSON.parse(res.body) ResourceList.new(data, self, Folder, @client) else nil end end |
#parent_folder ⇒ Object
Retrieve the containing folder.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/springcm-sdk/folder.rb', line 43 def parent_folder uri = URI(parent_folder_href) url = "#{uri.scheme}://#{uri.host}" conn = @client.(url: url) res = conn.get do |req| req.url uri.path resource_params.each { |key, value| req.params[key] = value } end if res.success? data = JSON.parse(res.body) Folder.new(data, @client) else nil end end |
#update_security(group:, access:) ⇒ Object
access InheritFromParentFolder, NoAccess, View, ViewCreate, ViewEdit, ViewEditDelete, ViewEditDeleteSetAccess
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/springcm-sdk/folder.rb', line 108 def update_security(group:, access:) Helpers.validate_access!(access) if !group.is_a?(Springcm::Group) raise ArgumentError.new("Invalid group; must be a Springcm::Group") end if group.group_type != "Security" raise ArgumentError.new("Invalid group type; must be a security group") end conn = @client.(url: @client.object_api_url) res = conn.post do |req| req.headers["Content-Type"] = "application/json" req.url "changesecuritytasks" req.body = { "Status" => "", "Security" => { "Groups" => [ { "Item" => group.raw, "AccessType" => access.to_s.split('_').map(&:capitalize).join } ] }, "Folder" => raw }.to_json end if res.success? data = JSON.parse(res.body) ChangeSecurityTask.new(data, @client) else nil end end |
#upload(name:, file:, type: :binary) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/springcm-sdk/folder.rb', line 80 def upload(name:, file:, type: :binary) # TODO: DRY Document#upload_version file_types = { binary: "application/octet-stream", pdf: "application/pdf", csv: "text/csv", txt: "text/plain" } if !type.nil? && !file_types.keys.include?(type) raise ArgumentError.new("File type must be one of: nil, #{file_types.map(&:inspect).join(", ")}") end conn = @client.(url: @client.upload_api_url) res = conn.post do |req| req.headers["Content-Type"] = file_types[type] req.headers["Content-Length"] = file.size.to_s req.url "folders/#{uid}/documents?name=#{URI.escape(name)}" req.body = file end if res.success? data = JSON.parse(res.body) Document.new(data, @client) else nil end end |