woodwing_elvis 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ea949496d1f812078942642edaec4ba77633479
4
+ data.tar.gz: 7b5be281d4ac85ad6b0c75c713847388a1758c13
5
+ SHA512:
6
+ metadata.gz: 3a4b656cbb4a5051e5a3d922922d26d320ee9e5b10366eaa4aa753ec989e08e23fc0d710d150d0640342496d9135c784fbd416292efe4f00b10e678b49ea9581
7
+ data.tar.gz: 925d473f24b19506abd07714614284dce20b4a973cd36e0100563781e0c9ce16b4430f4916eb0a783100588347b21fe0a54f8805b2bf8efee424d93264227ef3
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+
16
+ .irbrc
17
+ .rvmrc
18
+ .envrc
19
+ .ruby-version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in woodwing_elvis.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ You want it; its yours.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ woodwing_elvis
2
+ ==============
3
+
4
+ A Ruby implementation of Woodwing's Elvis API
5
+
6
+ System environment variables used:
7
+
8
+ Name Default
9
+ ----------------- -------------------------------
10
+ ELVIS_API_URL http://localhost:8080/services/
11
+ ELVIS_USER guest
12
+ ELVIS_PASS guest
13
+
14
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/woodwing.rb ADDED
@@ -0,0 +1,16 @@
1
+ ###################################################
2
+ ###
3
+ ## File: woodwing.rb
4
+ ## Desc: API definitions for WoodWing products
5
+ #
6
+
7
+ require "url_safe_base64"
8
+ require 'rest_client'
9
+ require 'multi_json'
10
+
11
+ module WoodWing
12
+ require_relative 'woodwing/version'
13
+ require_relative 'woodwing/elvis'
14
+ end # module WoodWing
15
+
16
+ WW = WoodWing unless defined?(WW)
@@ -0,0 +1,273 @@
1
+ ###################################################
2
+ ###
3
+ ## File: rest.rb
4
+ ## Desc: REST API definitions for WoodWing's Elvis
5
+ #
6
+
7
+ require_relative 'elvis/utilities'
8
+ require_relative 'elvis/rest'
9
+ require_relative 'elvis/soap'
10
+
11
+ module WoodWing
12
+
13
+ # Elvis is a Digital Asset Manager implemented in Java
14
+ class Elvis
15
+
16
+ attr_accessor :base_url
17
+ attr_accessor :cookies
18
+
19
+ # SMELL: Why is this error any more special than the others?
20
+ class ConcurrentModificationException < StandardError; end
21
+ class NotLoggedIn < StandardError; end
22
+
23
+
24
+ COMMANDS = {
25
+ # method name URL Resource Required Parameters
26
+ browse: ["browse", [:path]],
27
+ checkout: ["checkout", []],
28
+ copy: ["copy", [:source, :target]],
29
+ create: ["create", [:assetPath, :Filedata]],
30
+ create: ["create", [:Filedata]],
31
+ create_auth_key: ["create_auth_key", []],
32
+ create_collection: ["create", [:assetPath]],
33
+ create_relation: ["create_relation", []],
34
+ create_folder: ["createFolder", [:path]],
35
+ localization: ["localization", []],
36
+ log_usage_stats: ["log_usage_stats", []],
37
+ login: ["login", [:username, :password]],
38
+ logout: ["logout", []],
39
+ move: ["move", [:source, :target]],
40
+ profile: ["profile", []],
41
+ query_stats: ["queryStats", []],
42
+ remove_bulk: ["remove", [:q]],
43
+ remove_bulk_ids: ["remove", [:ids]],
44
+ remove_folder: ["remove", [:folderPath]],
45
+ remove_relation: ["remove_relation", []],
46
+ revoke_auth_keys: ["revoke_auth_keys",[]],
47
+ search: ["search", [:q]],
48
+ undo_checkout: ["undo_checkout", []],
49
+ update: ["update", [:Filedata, :id]],
50
+ update_metadata: ["update", [:id, :metadata]],
51
+ update_auth_key: ["update_auth_key", []],
52
+ update_bulk_metadata: ["updatebulk", [:q, :metadata]],
53
+ zip_download: ["zip_download", []]
54
+ }
55
+
56
+
57
+
58
+ def initialize( my_base_url=ENV['ELVIS_API_URL'],
59
+ my_cookies={})
60
+
61
+ @base_url = my_base_url
62
+ @cookies = my_cookies
63
+
64
+ @base_url += '/' unless @base_url.end_with?('/')
65
+
66
+ end
67
+
68
+
69
+ # Use RestClient.get
70
+
71
+ def get_response(url=nil,options={})
72
+
73
+ raise NotLoggedIn unless logged_in? || url.end_with?('login')
74
+
75
+ response = RestClient.get(url, { params: options, cookies: @cookies })
76
+
77
+ if $DEBUG
78
+ debug_me(){[:url, :options, :response ]}
79
+ debug_me(){[ 'response.code', 'response.cookies', 'response.body' ]}
80
+ end
81
+
82
+ @cookies = response.cookies unless response.cookies.empty?
83
+
84
+ response = MultiJson.load( response.body,
85
+ :symbolize_keys => true)
86
+
87
+ if response.include?(:errorcode)
88
+ if 401 == response[:errorcode] &&
89
+ response[:message].include?('ConcurrentModificationException')
90
+ raise ConcurrentModificationException
91
+ else
92
+ error_condition = "ERROR #{response[:errorcode]}: #{response[:message]}"
93
+ raise error_condition
94
+ end
95
+ end
96
+
97
+ return response
98
+ end
99
+
100
+
101
+ # SMELL: This is sooooo close to #get_response
102
+ # Use RestClient.post
103
+
104
+ def get_response_using_post(url=nil,options={})
105
+
106
+ raise NotLoggedIn unless logged_in? || url.end_with?('login')
107
+
108
+ response = RestClient.post( url, options, { cookies: @cookies } )
109
+
110
+ if $DEBUG
111
+ debug_me(){[:url, :options, :response ]}
112
+ debug_me(){[ 'response.code', 'response.cookies', 'response.body' ]}
113
+ end
114
+
115
+ @cookies = response.cookies unless response.cookies.empty?
116
+
117
+ response = MultiJson.load( response.body,
118
+ :symbolize_keys => true)
119
+
120
+ if response.include?(:errorcode)
121
+ if 401 == response[:errorcode] &&
122
+ response[:message].include?('ConcurrentModificationException')
123
+ raise ConcurrentModificationException
124
+ else
125
+ error_condition = "ERROR #{response[:errorcode]}: #{response[:message]}"
126
+ raise error_condition
127
+ end
128
+ end
129
+
130
+ return response
131
+
132
+ end
133
+
134
+
135
+ # https://elvis.tenderapp.com/kb/api/rest-copy
136
+ def copy(options={})
137
+ Utilities.demand_required_options!( :copy, options )
138
+ url = base_url + "copy"
139
+ response = get_response(url, options)
140
+ end # copy
141
+
142
+
143
+ # No file is uploaded. A placehold asset is created with the
144
+ # associated metadata
145
+ def create_collection(options={})
146
+ Utilities.demand_required_options!( :create_collection, options )
147
+ url = base_url + "create"
148
+ options.merge!( {assetType: 'collection'} )
149
+ response = get_response(url, options)
150
+ end # create
151
+
152
+
153
+ # https://elvis.tenderapp.com/kb/api/rest-localization
154
+ def localization(options={})
155
+ url = base_url + "localization"
156
+ response = get_response(url, options)
157
+ end # localization
158
+
159
+
160
+ # https://elvis.tenderapp.com/kb/api/rest-log_usage_stats
161
+ def log_usage_stats(options={})
162
+ url = base_url + "log_usage_stats"
163
+ response = get_response(url, options)
164
+ end # log_usage_stats
165
+
166
+
167
+ # https://elvis.tenderapp.com/kb/api/rest-move
168
+ def move(options={})
169
+ Utilities.demand_required_options!( :move, options )
170
+ url = base_url + "move"
171
+ response = get_response(url, options)
172
+ end # move
173
+
174
+ alias :rename :move
175
+
176
+
177
+ # https://elvis.tenderapp.com/kb/api/rest-profile
178
+ def profile(options={})
179
+ url = base_url + "profile"
180
+ response = get_response(url, options)
181
+ end # profile
182
+
183
+
184
+ # https://elvis.tenderapp.com/kb/api/rest-query_stats
185
+ def query_stats(options={})
186
+ url = base_url + "queryStats"
187
+ response = get_response(url, options)
188
+ end # query_stats
189
+
190
+
191
+ # https://elvis.tenderapp.com/kb/api/rest-remove
192
+ # can delete one or more using list of IDs or a search query
193
+ # pr a folderPath. The folderPath process has been abstracted
194
+ # into #remove_folder.
195
+
196
+ def remove_bulk(options={})
197
+ Utilities.demand_required_options!( :remove_bulk, options )
198
+ url = base_url + "remove"
199
+ response = get_response(url, options)
200
+ end # remove
201
+
202
+ alias :delete_bulk :remove_bulk
203
+
204
+
205
+ # https://elvis.tenderapp.com/kb/api/rest-remove
206
+ # can delete one or more using list of IDs or a search query
207
+ # pr a folderPath. The folderPath process has been abstracted
208
+ # into #remove_folder.
209
+
210
+ def remove_bulk_ids(options={})
211
+ Utilities.demand_required_options!( :remove_bulk_ids, options )
212
+ url = base_url + "remove"
213
+ response = get_response(url, options)
214
+ end # remove
215
+
216
+ alias :delete_bulk_ids :remove_bulk_ids
217
+
218
+
219
+ # https://elvis.tenderapp.com/kb/api/rest-update
220
+ # used to update assets and metadata
221
+ def update(options={})
222
+ Utilities.demand_required_options!( :update, options )
223
+ url = base_url + "update"
224
+ response = get_response(url, options)
225
+ end # update
226
+
227
+ alias :replace :update
228
+ alias :update_asset :update
229
+ alias :replace_asset :update
230
+
231
+
232
+ # https://elvis.tenderapp.com/kb/api/rest-update
233
+ # used to update metadata for a specific asset referenced by 'id'
234
+
235
+ def update_metadata(options={})
236
+ Utilities.demand_required_options!( :update, options )
237
+ options[:metadata] = options[:metadata].to_json
238
+ url = base_url + "update"
239
+ response = get_response(url, options)
240
+ end # update
241
+
242
+ alias :replace_metadata :update_metadata
243
+
244
+
245
+ # https://elvis.tenderapp.com/kb/api/rest-updatebulk
246
+ # updates metadata fields for all assets matching a specific query
247
+ def update_bulk_metadata(options={})
248
+ Utilities.demand_required_options!( :update_bulk_metadata, options )
249
+ options[:metadata] = options[:metadata].to_json
250
+ url = base_url + "updatebulk"
251
+ response = get_response(url, options)
252
+ end # update_bulk
253
+
254
+ alias :bulk_update_metadata :update_bulk_metadata
255
+ alias :bulk_replace_metadata :update_bulk_metadata
256
+ alias :replace_bulk_metadata :update_bulk_metadata
257
+
258
+
259
+ # https://elvis.tenderapp.com/kb/api/rest-zip_download
260
+ def zip_download(options={})
261
+ url = base_url + "zip_download"
262
+ response = get_response(url, options)
263
+ end # zip_download
264
+
265
+ alias :download_zip :zip_download
266
+
267
+ end # class Elvis
268
+
269
+ end # module WoodWing
270
+
271
+
272
+ WW = WoodWing unless defined?(WW)
273
+ WwElvis = WoodWing::Elvis unless defined?(WwElvis)
@@ -0,0 +1,30 @@
1
+ ###################################################
2
+ ###
3
+ ## File: rest.rb
4
+ ## Desc: REST API definitions for WoodWing's Elvis
5
+ #
6
+
7
+ module WoodWing
8
+ class Elvis
9
+
10
+ module Rest
11
+
12
+ require_relative 'rest/authorization_keys'
13
+ require_relative 'rest/browse'
14
+ require_relative 'rest/checkout'
15
+ require_relative 'rest/create'
16
+ require_relative 'rest/create_elvislink'
17
+ require_relative 'rest/login_logout'
18
+ require_relative 'rest/relations'
19
+ require_relative 'rest/search'
20
+ require_relative 'rest/stub'
21
+
22
+ end # module WoodWing::Elvis::Rest
23
+
24
+ include Rest
25
+
26
+ end # class Elvis
27
+ end # module WoodWing
28
+
29
+ WW = WoodWing unless defined?(WW)
30
+ WwElvis = WoodWing::Elvis unless defined?(WwElvis)
@@ -0,0 +1,31 @@
1
+ module WoodWing
2
+ class Elvis
3
+ module Rest
4
+
5
+
6
+ # https://elvis.tenderapp.com/kb/api/rest-createauthkey
7
+ def create_auth_key(options={})
8
+ url = base_url + "create_auth_key"
9
+ response = get_response(url, options)
10
+ end # create_auth_key
11
+
12
+
13
+ # https://elvis.tenderapp.com/kb/api/rest-update_auth_key
14
+ def update_auth_key(options={})
15
+ url = base_url + "update_auth_key"
16
+ response = get_response(url, options)
17
+ end # update_auth_key
18
+
19
+ alias :replace_auth_key :update_auth_key
20
+
21
+
22
+ # https://elvis.tenderapp.com/kb/api/rest-revokeauthkeys
23
+ def revoke_auth_keys(options={})
24
+ url = base_url + "revoke_auth_keys"
25
+ response = get_response(url, options)
26
+ end # revoke_auth_keys
27
+
28
+
29
+ end # module Rest
30
+ end # class Elvis
31
+ end # module WoodWing
@@ -0,0 +1,65 @@
1
+ module WoodWing
2
+ class Elvis
3
+ module Rest
4
+
5
+
6
+ # https://elvis.tenderapp.com/kb/api/rest-browse
7
+ #
8
+ # browse folders and show their subfolders and collections,
9
+ # similar to how folder browsing works in the Elvis desktop client.
10
+ #
11
+ # Note: Even though it is possible to return the assets in folders,
12
+ # doing so is not advised. The browse call does not limit the
13
+ # number of results, so if there are 10000 assets in a folder
14
+ # it will return all of them. It is better to use a search to
15
+ # find the assets in a folder and fetch them in pages.
16
+ #
17
+ # http://yourserver.com/services/browse
18
+ # ?path=<assetPath>
19
+ # &fromRoot=<folderPath>
20
+ # &includeFolders=<true|false>
21
+ # &includeAssets=<true|false>
22
+ # &includeExtensions=<comma-delimited extensions>
23
+ #
24
+ # Options
25
+ # path (Required) The path to the folder in Elvis you want to list.
26
+ # Make sure the URL is properly URL-encoded, for example: spaces should
27
+ # often be represented as %20.
28
+ #
29
+ # fromRoot Allows returning multiple levels of folders with their
30
+ # children. When specified, this path is listed, and all folders
31
+ # below it up to the 'path' will have their children returned as well.
32
+ #
33
+ # This ability can be used to initialize an initial path in a
34
+ # column tree folder browser with one server call.
35
+ #
36
+ # Optional. When not specified, only the children of the specified
37
+ # 'path' will be returned.
38
+ #
39
+ # Available since Elvis 2.6
40
+ #
41
+ # includeFolders Indicates if folders should be returned.
42
+ # Optional. Default is true.
43
+ #
44
+ # includeAsset Indicates if files should be returned.
45
+ # Optional. Default is true, but filtered to
46
+ # only include 'container' assets.
47
+ #
48
+ # includeExtensions A comma separated list of file extensions to
49
+ # be returned. Specify 'all' to return all file types.
50
+ # Optional. Default includes all 'container'
51
+ # assets: .collection, .dossier, .task
52
+
53
+ def browse(options={})
54
+
55
+ Utilities.demand_required_options!( :browse, options )
56
+
57
+ url = base_url + "browse"
58
+ response = get_response(url, options)
59
+
60
+ end # browse
61
+
62
+
63
+ end # module Rest
64
+ end # class Elvis
65
+ end # module WoodWing