woodwing_elvis 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ module WoodWing
2
+ class Elvis
3
+ module Rest
4
+
5
+
6
+ # https://elvis.tenderapp.com/kb/api/rest-checkout
7
+ def checkout(options={})
8
+ url = base_url + "checkout"
9
+ response = get_response(url, options)
10
+ end # checkout
11
+
12
+
13
+ # https://elvis.tenderapp.com/kb/api/rest-undo_checkout
14
+ def undo_checkout(options={})
15
+ url = base_url + "undo_checkout"
16
+ response = get_response(url, options)
17
+ end # undo_checkout
18
+
19
+ alias :abort_checkout :undo_checkout
20
+
21
+
22
+ end # module Rest
23
+ end # class Elvis
24
+ end # module WoodWing
@@ -0,0 +1,71 @@
1
+ module WoodWing
2
+ class Elvis
3
+ module Rest
4
+
5
+
6
+ # https://elvis.tenderapp.com/kb/api/rest-create
7
+ # Upload and create an asset.
8
+ #
9
+ # This call will create a new asset in Elvis. It can be used to upload files
10
+ # into Elvis. It can also be used to create 'virtual' assets like collections.
11
+ # In that case no file has to be uploaded and Elvis will create a 0 kb
12
+ # placeholder for the virtual asset.
13
+ #
14
+ # When you want to create a new asset, certain metadata is required. The
15
+ # metadata is needed to determine where the file will be stored in Elvis.
16
+ #
17
+ # http://yourserver.com/services/create
18
+ # ?Filedata=<multipart/form-data encoded file>
19
+ # &metadata=<JSON encoded metadata>
20
+ # &<Elvis metadata field name>=<value>
21
+ # &nextUrl=<next URL>
22
+ #
23
+ # Options
24
+ #
25
+ # Filedata The file to be created in Elvis. If you do not specify a
26
+ # filename explicitly through the metadata, the filename of
27
+ # the uploaded file will be used.
28
+ # NOTE: The parameter is named "Filedata" because that is the
29
+ # standard name used by flash uploads. This makes it easy
30
+ # to use flash uploaders to upload batches of files to Elvis.
31
+ # Optional. If omitted, a 0kb placeholder file will be created.
32
+ # See the method create_collection()
33
+ #
34
+ # metadata A JSON encoded object with properties that match Elvis metadata
35
+ # field names. This metadata will be set on the asset in Elvis.
36
+ # Optional. You can also use parameters matching Elvis field names.
37
+ #
38
+ # * Any parameter matching an Elvis metadata field name will be used as
39
+ # metadata. This metadata will be set on the asset in Elvis.
40
+ # Optional. You also use the 'metadata' parameter.
41
+ #
42
+ # nextUrl When specified, the service will send a 301 redirect to this
43
+ # URL when it is completed successfully. If you place '${id}' in
44
+ # the URL, it will be replaced with the Elvis asset id of the
45
+ # created asset.
46
+ # Optional. If omitted, a simple 200 OK status code will be returned
47
+
48
+ def create(options={})
49
+
50
+ Utilities.demand_required_options!( :create, options )
51
+
52
+ # SMELL: Don't think this is required since last change to
53
+ # get_response_with_post
54
+ options.merge!( { multipart: true } )
55
+
56
+ url = base_url + "create"
57
+ response = get_response_using_post(url, options)
58
+
59
+ end # create
60
+
61
+ alias :create_file :create
62
+ alias :upload_file :create
63
+ alias :import_file :create
64
+ alias :create_asset :create
65
+ alias :upload_asset :create
66
+ alias :import_asset :create
67
+
68
+
69
+ end # module Rest
70
+ end # class Elvis
71
+ end # module WoodWing
@@ -0,0 +1,148 @@
1
+ module WoodWing
2
+ class Elvis
3
+ module Rest
4
+
5
+ =begin
6
+
7
+ Create an '.elvislink' file
8
+
9
+ http://elvis.example.com/elvislink
10
+ /yourfilename.elvislink
11
+ ?action=openAuthkey | openAssets | openContainers
12
+ | activateContainers | openSearch | openBrowse
13
+ &key=<authkey to open and link to the user>
14
+ &containerIds=<collection id's to open or activate>
15
+ &assetIds=<assets to open>
16
+ &q=<query for search>
17
+ &sort=<sort for search>
18
+ &folderPath=<folderPath to open>
19
+ &includeSubFolders=true|false
20
+
21
+ What does it do?
22
+
23
+ Produce an '*.elvislink' file that will open the desktop client and perform an action. Some actions that can be performed:
24
+
25
+ Show results sent by an email link (authkey).
26
+ Open a search.
27
+ Show a specific asset.
28
+
29
+ Available since Elvis 2.6
30
+
31
+ Parameters
32
+
33
+ action The action that should be performed when the link file is opened in
34
+ the desktop client.
35
+ See the elvisContext functions for the possible actions.
36
+ Optional. Not needed when you specify the 'key' parameter. In that case the
37
+ openAuthkey action is automatically used.
38
+
39
+ key An authkey to be opened and displayed in the desktop client. The
40
+ permissions granted by the authkey will be linked to the user when opened.
41
+ Optional. Only needed if you want to open an authkey.
42
+
43
+ other parameters For detailed descriptions of the other parameters, see the
44
+ elvisContext functions.
45
+
46
+ Return value
47
+
48
+ The service produces an XML file with the extension '.elvislink'. The file also includes the server URL so the desktop client can connect to the correct server.
49
+
50
+ Examples
51
+
52
+ openAuthkey elvislink
53
+
54
+ http://demo.elvisdam.com/elvislink
55
+ ?key=9T_WLil348lBtFk8FDTwPN
56
+
57
+ This URL generates: openAuthkey-2011_11_328-144355.elvislink
58
+
59
+ <?xml version="1.0" encoding="UTF-8"?>
60
+ <elvisLink serverUrl="http://demo.elvisdam.com">
61
+ <openAuthkey authkey="9T_WLil348lBtFk8FDTwPN"/>
62
+ </elvisLink>
63
+
64
+ openSearch elvislink
65
+
66
+ http://demo.elvisdam.com/elvislink/openBeaches.elvislink
67
+ ?action=openSearch&q=beach&sort=name
68
+
69
+ This URL generates: openBeaches.elvislink
70
+
71
+ <?xml version="1.0" encoding="UTF-8"?>
72
+ <elvisLink serverUrl="http://demo.elvisdam.com">
73
+ <openSearch q="beach" sort="name"/>
74
+ </elvisLink>
75
+
76
+ openBrowse elvislink
77
+
78
+ http://demo.elvisdam.com/elvislink/openTrailers.elvislink
79
+ ?action=openBrowse
80
+ &folderPath=/Demo Zone/Videos/Movie Trailers
81
+ &includeSubFolders=true
82
+ &sort=assetCreated
83
+
84
+ This URL generates: openTrailers.elvislink
85
+
86
+ <?xml version="1.0" encoding="UTF-8"?>
87
+ <elvisLink serverUrl="http://demo.elvisdam.com">
88
+ <openBrowse folderPath="/Demo Zone/Videos/Movie Trailers"
89
+ includeSubFolders="true" sort="assetCreated"/>
90
+ </elvisLink>
91
+
92
+ openAssets elvislink
93
+
94
+ http://demo.elvisdam.com/elvislink
95
+ ?action=openAssets
96
+ &assetIds=Bg7fObz1aVr96wy97riUad,0l2ZhcAfK779hCXqTf2E7s
97
+
98
+ This URL generates: openAssets-2011_11_328-140254.elvislink
99
+
100
+ <?xml version="1.0" encoding="UTF-8"?>
101
+ <elvisLink serverUrl="http://demo.elvisdam.com">
102
+ <openAssets assetIds="Bg7fObz1aVr96wy97riUad,0l2ZhcAfK779hCXqTf2E7s"/>
103
+ </elvisLink>
104
+
105
+ openContainers elvislink
106
+
107
+ http://demo.elvisdam.com/elvislink/openCollections.elvislink
108
+ ?action=openContainers
109
+ &containerIds=0JkPrbQc40g8RQIC1NI6uo,6BN2FRaCqyLA5DjJJdB9h4
110
+ &sort=name
111
+
112
+ This URL generates: openCollections.elvislink
113
+
114
+ <?xml version="1.0" encoding="UTF-8"?>
115
+ <elvisLink serverUrl="http://demo.elvisdam.com">
116
+ <openContainers
117
+ containerIds="0JkPrbQc40g8RQIC1NI6uo,6BN2FRaCqyLA5DjJJdB9h4"
118
+ sort="name"/>
119
+ </elvisLink>
120
+
121
+ activateContainers elvislink
122
+
123
+ http://demo.elvisdam.com/elvislink
124
+ ?action=activateContainers
125
+ &containerIds=0JkPrbQc40g8RQIC1NI6uo,6BN2FRaCqyLA5DjJJdB9h4
126
+
127
+ This URL generates: activateContainers-2011_11_328-142851.elvislink
128
+
129
+ <?xml version="1.0" encoding="UTF-8"?>
130
+ <elvisLink serverUrl="http://demo.elvisdam.com">
131
+ <activateContainers
132
+ containerIds="0JkPrbQc40g8RQIC1NI6uo,6BN2FRaCqyLA5DjJJdB9h4"/>
133
+ </elvisLink>
134
+
135
+ =end
136
+
137
+ def create_elvislink(options)
138
+
139
+ Utilities.demand_required_options!( :elvislink, options )
140
+
141
+ url = base_url + "elvislink"
142
+ response = get_response_using_get(url, options)
143
+
144
+ end # def create_elvislink(options)
145
+
146
+ end # module Rest
147
+ end # class Elvis
148
+ end # module WoodWing
@@ -0,0 +1,27 @@
1
+ module WoodWing
2
+ class Elvis
3
+ module Rest
4
+
5
+
6
+ # https://elvis.tenderapp.com/kb/api/rest-create_folder
7
+ def create_folder(options={})
8
+ Utilities.demand_required_options!( :create_folder, options )
9
+ url = base_url + "createFolder"
10
+ response = get_response(url, options)
11
+ end # create_folder
12
+
13
+
14
+ # https://elvis.tenderapp.com/kb/api/rest-remove
15
+ def remove_folder(options={})
16
+ Utilities.demand_required_options!( :remove_folder, options )
17
+ url = base_url + "remove"
18
+ response = get_response(url, options)
19
+ end # remove_folder
20
+
21
+ alias :delete_folder :remove_folder
22
+
23
+
24
+
25
+ end # module Rest
26
+ end # class Elvis
27
+ end # module WoodWing
@@ -0,0 +1,257 @@
1
+ module WoodWing
2
+ class Elvis
3
+ module Rest
4
+
5
+ # TODO: Extend session management to support multiple sessions.
6
+
7
+ class AlreadyLoggedIn < StandardError; end
8
+
9
+
10
+ # A successful log in will result in a cookie
11
+ def logged_in?
12
+ not @cookies.empty?
13
+ end
14
+
15
+
16
+
17
+ =begin
18
+ # https://elvis.tenderapp.com/kb/api/rest-login
19
+
20
+ http://yourserver.com/services/login
21
+ ?cred=<base64 credentials>
22
+ &username=<username>
23
+ &password=<password>
24
+ &nextUrl=<URL for next page>
25
+ &failUrl=<URL for fail page>
26
+ &locale=<language_COUNTRY_variant>
27
+ &timezoneOffset=<timecode>
28
+ &clientType=api_...
29
+ &returnProfile=true
30
+
31
+ What does it do?
32
+
33
+ Authenticates your browser session.
34
+
35
+ All other REST calls require an authenticated session, otherwise they will respond with a "401 Unauthorized" status.
36
+
37
+ The login service can be used in two flavors:
38
+
39
+ Handle an AJAX login request
40
+
41
+ Use this if you want maximum control on the client side over what happens. It returns a JSON response with details about the result of your authenticate request. This mechanism is also used by the auto login function of the Elvis JavaScript library.
42
+
43
+ Handle form based login
44
+
45
+ Forwards to a 'success' or 'failure' URL after the authentication attempt. Use this to build a simple login page, see the following sample at GitHub. You can also tell the JavaScript library to use your login page whenever authentication is required.
46
+
47
+ Parameters
48
+
49
+ cred Base 64 encoded credentials.
50
+ cred=<base64Encode( username + ":" + password )>
51
+ Base64 encoding is not secure. Use https to make login secure.
52
+ Optional. Either cred or username and password must be specified.
53
+
54
+ username The username to be used to login. This should match a valid
55
+ username from the LDAP or ActiveDirectory server or from the
56
+ internal Elvis users. Sometimes an LDAP configuration supports
57
+ various usernames for one user.
58
+ Optional. Either cred or username and password must be specified.
59
+
60
+ password The password for the user. Since this is passed to the server as
61
+ plain text, use https to make login secure.
62
+ Optional. Either cred or username and password must be specified.
63
+
64
+ nextUrl When specified, the service will send a 301 redirect to this URL
65
+ after a successful login.
66
+ Optional. When not specified, a JSON response with login details
67
+ will be returned.
68
+
69
+ failUrl When specified, the service will send a 301 redirect to this URL
70
+ if login fails.
71
+ Optional. When not specified, a JSON response with login failure
72
+ details will be returned.
73
+
74
+ locale The locale to be used for this user to format locale sensitive
75
+ information like dates and numbers.
76
+ A locale has one of the following formats:
77
+ <language code>
78
+ <language code>_<country code>
79
+ The language argument is a valid ISO Language Code. These codes are
80
+ the lower-case, two-letter codes as defined by ISO-639. The country
81
+ argument is a valid ISO Country Code. These codes are the upper-case,
82
+ two-letter codes as defined by ISO-3166.
83
+ Examples:
84
+ locale=de
85
+ locale=fr
86
+ locale=nl_BE
87
+ Optional. When not specified, the locale configured on the server
88
+ will be used.
89
+
90
+ timezoneOffset The timezone for this user, used to format dates. Must be
91
+ specified as base timezone offset in milliseconds to GMT. For example:
92
+ America/Los_Angeles
93
+ Base GMT offset: -8:00
94
+ = -28800000 milliseconds
95
+ timezoneOffset=-28800000
96
+ Europe/Paris,
97
+ Base GMT offset: +1:00
98
+ = 3600000 milliseconds
99
+ timezoneOffset=3600000
100
+ Optional. When not specified, the timezone configured on the
101
+ server will be used. If specified, the locale MUST also be
102
+ specified, otherwise the timezoneOffset is ignored.
103
+
104
+ clientType Custom client type that will be displayed in the usage history of
105
+ the asset. Used to track which interface was used to perform the
106
+ operation. The client type must be prefixed with "api_", for example:
107
+ "api_MyPublicWebsite".
108
+ Optional. When not specified, operations will be tracked without a
109
+ client type.
110
+ Available since Elvis 3.0
111
+
112
+ returnProfile Specify 'true' to return profile with login response.
113
+ Optional. When not specified, profile details are not returned.
114
+ Available since Elvis 2.6. In older versions, profile information
115
+ was always returned.
116
+
117
+
118
+ Return value
119
+ ------------
120
+
121
+ When nextUrl and failUrl are set, the service will respond with a 302 redirect.
122
+ This will change the URL of the browser and navigate to the 'next' URL.
123
+
124
+ When nextUrl and failUrl are not set, the service returns a JSON response with
125
+ the following information:
126
+
127
+ loginSuccess true | false
128
+ Indicates if login was successful.
129
+
130
+ sessionId The session ID.
131
+ Useful if you are doing cross-domain calls to an Elvis Server,
132
+ since session cookies are not accepted when received through a
133
+ cross-domain AJAX call. You will have to store the sessionId
134
+ yourself and add ;jsessionid=<received id> to the URL of each
135
+ subsequent call made to the Elvis Server. When you use the
136
+ JavaScript library to perform the login, this will be done for
137
+ you automatically.
138
+ Available since Elvis 2.6
139
+
140
+ serverVersion The version of the server. This can be used to check if the Elvis
141
+ Server you are connecting to meets your minimum server version
142
+ requirements.
143
+ Available since Elvis 2.6
144
+
145
+ loginFaultMessage A message indicating why login failed.
146
+ Only returned when loginSuccess is false.
147
+
148
+ userProfile An object with details about the user.
149
+ Only returned when loginSuccess is true and the returnProfile
150
+ parameter is set to true.
151
+
152
+ =end
153
+
154
+ # FIXME: Need to change Elvis to https otherwise anyone who snoops
155
+ # the wire will find cred and be able to have complete access once
156
+ # the white listed IP scheme has been dropped.
157
+
158
+ def login(options={})
159
+
160
+ raise AlreadyLoggedIn unless @cookies.empty?
161
+
162
+ unless options.include?(:cred)
163
+ options = {
164
+ username: ENV['ELVIS_USER'],
165
+ password: ENV['ELVIS_PASS']
166
+ }.merge(options)
167
+ options[:cred] = UrlSafeBase64.encode64("#{options[:username]}:#{options[:password]}")
168
+ end
169
+
170
+ options.delete(:username)
171
+ options.delete(:password)
172
+
173
+ options[:clientType] = 'api_Ruby'
174
+ options[:returnProfile] = 'true'
175
+
176
+ url = base_url + "login"
177
+ response = get_response(url, options)
178
+
179
+ return response
180
+
181
+ end # login
182
+
183
+ alias :logon :login
184
+ alias :signin :login
185
+
186
+ =begin
187
+ # https://elvis.tenderapp.com/kb/api/rest-logout
188
+
189
+ http://yourserver.com/services/logout
190
+
191
+ Terminates your browser session. Use this to end a session using an AJAX call.
192
+
193
+ Available since Elvis 2.6.
194
+
195
+ Parameters
196
+
197
+ This service has no parameters
198
+
199
+ Return value
200
+ ------------
201
+
202
+ logoutSuccess == 'true' Indicates that logout was successful.
203
+
204
+ Note: Logging out through AJAX won't work if you are doing cross-domain calls, since session cookies are not accepted when received through a cross-domain AJAX call. Use "logout and redirect" instead, see below.
205
+
206
+ Logout and redirect
207
+
208
+ http://yourserver.com/logout
209
+ ?logoutSuccessUrl=<url>
210
+
211
+ Redirects to a 'success' URL after terminating the session. The URL can be a relative or absolute URL and can even redirect to a different server.
212
+
213
+ When no logoutSuccessUrl is specified, the user will be redirected to the configured landing page (by default this is the client install page).
214
+
215
+ Examples
216
+
217
+ AJAX logout with success
218
+
219
+ The following shows the response of a successful logout.
220
+
221
+ http://demo.elvisdam.com/services/logout
222
+
223
+ {
224
+ "logoutSuccess" : true
225
+ }
226
+
227
+ Redirect logout
228
+
229
+ Ends the session and redirects to www.elvisdam.com.
230
+ logout
231
+
232
+ http://demo.elvisdam.com/logout
233
+ ?logoutSuccessUrl=http%3A%2F%2Fwww.elvisdam.com
234
+
235
+
236
+ =end
237
+
238
+
239
+ def logout(options={})
240
+
241
+ url = base_url + "logout"
242
+ response = get_response(url, options)
243
+
244
+ @cookies = {} if response[:logoutSuccess]
245
+
246
+ return response
247
+
248
+ end # logout
249
+
250
+ alias :signout :logout
251
+ alias :signoff :logout
252
+ alias :logoff :logout
253
+
254
+
255
+ end # module Rest
256
+ end # class Elvis
257
+ end # module WoodWing