Class: AdobeShare::Client
- Inherits:
-
Object
- Object
- AdobeShare::Client
- Defined in:
- lib/adobeshare/client.rb
Overview
Client Access Class
Constant Summary collapse
Instance Attribute Summary collapse
-
#apikey ⇒ Object
User’s API Key:.
-
#name ⇒ Object
readonly
User’s name.
-
#password ⇒ Object
User’s password.
-
#secret ⇒ Object
User’s session shared secret.
-
#sessionid ⇒ Object
readonly
User’s session ID.
-
#username ⇒ Object
User’s Adobe ID.
Instance Method Summary collapse
-
#add_file(data, filename, description, nodeid = "", renditions = true) ⇒ Object
Upload and add file.
-
#add_folder(name, description, nodeid) ⇒ Object
Add new folder.
-
#delete_node(nodeid) ⇒ Object
Delete a node.
-
#get_node(nodeid = nil) ⇒ Object
Get a list of nodes (files and folders) in a user’s account.
-
#get_node_content(nodeid, rendition) ⇒ Object
Get the specified rendition of a document.
-
#get_source(nodeid) ⇒ Object
Get the source of a document.
-
#get_thumbnail(nodeid) ⇒ Object
Get the thumbnail of a document.
-
#initialize(proxy = nil) ⇒ Client
constructor
A new instance of Client.
-
#login ⇒ Object
Login to use Adobe Share service.
-
#logout ⇒ Object
Logout from the servce.
-
#move_node(nodeid, destnodeid, newname) ⇒ Object
Move a node.
-
#rename_node(nodeid, newname) ⇒ Object
Rename a node.
-
#replace_file(data, file_name, description, nodeid, renditions = true) ⇒ Object
Replace file in an already existing node.
-
#share_file(nodeid, users, message, level) ⇒ Object
Share a file.
-
#unshare_file(nodeid) ⇒ Object
Unshare a file.
-
#update_share(nodeid, users_to_add, users_to_remove, message) ⇒ Object
Update a share file.
Constructor Details
#initialize(proxy = nil) ⇒ Client
Returns a new instance of Client.
37 38 39 |
# File 'lib/adobeshare/client.rb', line 37 def initialize proxy=nil @client = HTTPClient.new(proxy, UA) end |
Instance Attribute Details
#apikey ⇒ Object
User’s API Key:
24 25 26 |
# File 'lib/adobeshare/client.rb', line 24 def apikey @apikey end |
#name ⇒ Object (readonly)
User’s name
32 33 34 |
# File 'lib/adobeshare/client.rb', line 32 def name @name end |
#password ⇒ Object
User’s password
30 31 32 |
# File 'lib/adobeshare/client.rb', line 30 def password @password end |
#secret ⇒ Object
User’s session shared secret
26 27 28 |
# File 'lib/adobeshare/client.rb', line 26 def secret @secret end |
#sessionid ⇒ Object (readonly)
User’s session ID
34 35 36 |
# File 'lib/adobeshare/client.rb', line 34 def sessionid @sessionid end |
#username ⇒ Object
User’s Adobe ID
28 29 30 |
# File 'lib/adobeshare/client.rb', line 28 def username @username end |
Instance Method Details
#add_file(data, filename, description, nodeid = "", renditions = true) ⇒ Object
Upload and add file
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/adobeshare/client.rb', line 87 def add_file(data, filename, description, nodeid="", renditions=true) uri = ENDPOINT_DC + nodeid + "/" # request xml req_xml = Element.new "request" file = req_xml.add_element "file" file.add_element "name" file.add_element "description" file.add_element "renditions" file.elements["name"].text = filename file.elements["description"].text = description file.elements["renditions"].text = renditions # FIXME # XXX Is there any good library or something ??? # to make multipart/form-data ... boundary = "mime-part-separator" + Time.new.to_i.to_s req = "--#{boundary}\r\n" req << "Content-Disposition: form-data; name=\"request\"\r\n" req << "\r\n" req << req_xml.to_s req << "\r\n" req << "--#{boundary}\r\n" req << "Content-Disposition: form-data; name=\"file\"; filename=\"#{URI.encode(filename)}\"\r\n" req << "Content-Type: application/octet-stream\r\n" req << "Content-Transfer-Encoding: binary\r\n" req << "\r\n" req << data req << "\r\n" req << "--#{boundary}--\r\n" headers = Hash.new headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}" res = http_client_request("POST", uri, req, headers) end |
#add_folder(name, description, nodeid) ⇒ Object
Add new folder
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/adobeshare/client.rb', line 140 def add_folder(name, description, nodeid) if nodeid uri = ENDPOINT_DC + nodeid + "/" else uri = ENDPOINT_DC end req = Element.new "request" folder = req.add_element "folder" folder.add_element "name" folder.add_element "description" folder.elements["name"].text = name folder.elements["description"].text = description res = http_client_request("POST", uri, req) doc = Document.new res end |
#delete_node(nodeid) ⇒ Object
Delete a node
81 82 83 84 |
# File 'lib/adobeshare/client.rb', line 81 def delete_node nodeid uri = ENDPOINT_DC + nodeid + "/" res = http_client_request("DELETE", uri) end |
#get_node(nodeid = nil) ⇒ Object
Get a list of nodes (files and folders) in a user’s account
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/adobeshare/client.rb', line 53 def get_node(nodeid=nil) if nodeid uri = ENDPOINT_DC + nodeid + "/" else uri = ENDPOINT_DC end res = http_client_request("GET", uri) node = Node.new res node.to_hash end |
#get_node_content(nodeid, rendition) ⇒ Object
Get the specified rendition of a document
75 76 77 78 |
# File 'lib/adobeshare/client.rb', line 75 def get_node_content nodeid, rendition uri = ENDPOINT_DC + nodeid + "/" + rendition + "/" res = http_client_request("GET", uri) end |
#get_source(nodeid) ⇒ Object
Get the source of a document
65 66 67 |
# File 'lib/adobeshare/client.rb', line 65 def get_source nodeid get_node_content nodeid, RENDITION_SOURCE end |
#get_thumbnail(nodeid) ⇒ Object
Get the thumbnail of a document
70 71 72 |
# File 'lib/adobeshare/client.rb', line 70 def get_thumbnail nodeid get_node_content nodeid, RENDITION_THUMBNAIL end |
#login ⇒ Object
Login to use Adobe Share service
42 43 44 45 |
# File 'lib/adobeshare/client.rb', line 42 def login authtoken = get_authtoken start_sessions authtoken end |
#logout ⇒ Object
Logout from the servce
48 49 50 |
# File 'lib/adobeshare/client.rb', line 48 def logout end_sessions end |
#move_node(nodeid, destnodeid, newname) ⇒ Object
Move a node
129 130 131 132 |
# File 'lib/adobeshare/client.rb', line 129 def move_node(nodeid, destnodeid, newname) uri = ENDPOINT_DC + nodeid + "/?destnodeid=" + destnodeid + "&newname=" + URI.encode(newname) res = http_client_request("MOVE", uri) end |
#rename_node(nodeid, newname) ⇒ Object
Rename a node
123 124 125 126 |
# File 'lib/adobeshare/client.rb', line 123 def rename_node(nodeid, newname) uri = ENDPOINT_DC + nodeid + "/?newname=" + newname res = http_client_request("MOVE", uri) end |
#replace_file(data, file_name, description, nodeid, renditions = true) ⇒ Object
Replace file in an already existing node
135 136 137 |
# File 'lib/adobeshare/client.rb', line 135 def replace_file(data, file_name, description, nodeid, renditions=true) add_file(data, file_name, description, nodeid, renditions) end |
#share_file(nodeid, users, message, level) ⇒ Object
Share a file
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/adobeshare/client.rb', line 157 def share_file(nodeid, users, , level) uri = ENDPOINT_DC + nodeid + "/share/" req = Element.new "request" share = req.add_element "share" users = [""] unless users users.each{|e| user = Element.new "user" user.text = e share.add_element user } req.add_element "message" req.add_element "level" req.elements["message"].text = req.elements["level"].text = level res = http_client_request("PUT", uri, req) doc = Document.new res end |
#unshare_file(nodeid) ⇒ Object
Unshare a file
176 177 178 |
# File 'lib/adobeshare/client.rb', line 176 def unshare_file(nodeid) share_file(nodeid, nil, nil, 0) end |
#update_share(nodeid, users_to_add, users_to_remove, message) ⇒ Object
Update a share file
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/adobeshare/client.rb', line 181 def update_share(nodeid, users_to_add, users_to_remove, ) uri = ENDPOINT_DC + nodeid + "/share/" req = Element.new "request" share = req.add_element "share" users_to_add = [""] unless users_to_add users_to_add.each{|e| user = Element.new "user" user.text = e share.add_element user } unshare = req.add_element "unshare" users_to_remove = [""] unless users_to_remove users_to_remove.each{|e| user = Element.new "user" user.text = e unshare.add_element user } req.add_element "message" req.add_element "level" req.elements["message"].text = res = http_client_request("POST", uri, req) doc = Document.new res end |