ubiquity-wiredrive 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4ccd5f3318034434414e3b07000317126d2e6d1f4bf30f2cdfc5f8680911f011
4
+ data.tar.gz: cc92e7e91a7cedaea4e2f4aa48477c1f9b0fa12b8557cd8033eb05f8811b829b
5
+ SHA512:
6
+ metadata.gz: 99bfad05b74cfd9194b19a3b6966fc7565aa98bd103b81d45300726b928536a868a4624bf95897dfe1d195b0c063bce5e10cbd471eb6e25a43fd6b983e3be309
7
+ data.tar.gz: 1291cb4b05760c751152837b1556257c84e2d94a20808d390c5878e8bdf2a6acd6deb82ad61f2dcada727ca5daf5fef16b96986f3a930176505f5b3dc534aab2
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.gems/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /dev/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ *.bundle
13
+ *.so
14
+ *.o
15
+ *.a
16
+ mkmf.log
data/.rbenv-gemsets ADDED
@@ -0,0 +1,3 @@
1
+ .gems
2
+ ubiquity-wiredrive
3
+ -global
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'json', :platforms => :mri_18
4
+
5
+ # Specify your gem's dependencies in ubiquity-mediasilo-api-v3.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 John Whitson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Ubiquity::Wiredrive
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ubiquity-wiredrive'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ubiquity-wiredrive
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/XPlatform-Consulting/ubiquity-wiredrive/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ubiquity-wiredrive'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ begin
11
+ require 'pry'
12
+ Pry.start
13
+ rescue LoadError => e
14
+ require 'irb'
15
+ IRB.start(__FILE__)
16
+ end
17
+
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require 'ubiquity/wiredrive/version'
2
+
3
+ module Ubiquity
4
+ module Wiredrive
5
+
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Ubiquity
2
+ module Wiredrive
3
+ module API
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ # require 'ubiquity/wiredrive/api/v2'
2
+
3
+ module Ubiquity
4
+ module Wiredrive
5
+ module API
6
+ class Client
7
+
8
+ def self.new(args = { })
9
+ new_v2(args)
10
+ end
11
+
12
+ def self.new_v2(args)
13
+ version = '2'
14
+ require "ubiquity/wiredrive/api/v#{version}"
15
+ Ubiquity::Wiredrive::API::V2::Client.new(args)
16
+ end
17
+
18
+ def self.new_v3(args)
19
+ version = '3'
20
+ require "ubiquity/wiredrive/api/v#{version}"
21
+ Ubiquity::Wiredrive::API::V3::Client.new(args)
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
28
+ # class Ubiquity::Wiredrive::API::Client
29
+ #
30
+ # # def self.new(args = { })
31
+ # # # Ubiquity::Wiredrive::API::V2::Client.new(args)
32
+ # # end
33
+ #
34
+ #
35
+ # end
@@ -0,0 +1,25 @@
1
+ # require 'ubiquity/wiredrive/api/v2'
2
+
3
+ module Ubiquity
4
+ module Wiredrive
5
+ module API
6
+ class Utilities
7
+
8
+ def self.new(args = { })
9
+ version = '2'
10
+ require "ubiquity/wiredrive/api/v#{version}"
11
+ Ubiquity::Wiredrive::API::V2::Utilities.new(args)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+ # class Ubiquity::Wiredrive::API::Client
19
+ #
20
+ # # def self.new(args = { })
21
+ # # # Ubiquity::Wiredrive::API::V2::Client.new(args)
22
+ # # end
23
+ #
24
+ #
25
+ # end
@@ -0,0 +1,12 @@
1
+ require 'ubiquity/wiredrive/api/v2/client'
2
+ require 'ubiquity/wiredrive/api/v2/utilities'
3
+
4
+ module Ubiquity
5
+ module Wiredrive
6
+ module API
7
+ module V2
8
+
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,301 @@
1
+ require 'ubiquity/wiredrive/api/v2/http_client'
2
+
3
+ class Ubiquity::Wiredrive::API::V2::Client
4
+
5
+ attr_accessor :logger
6
+
7
+ attr_accessor :http_client, :request, :response, :http_response
8
+
9
+ def initialize(args = { })
10
+ require 'ubiquity/wiredrive/api/v2/client/requests'
11
+
12
+ initialize_logger(args)
13
+ initialize_http_client(args)
14
+ end
15
+
16
+ def initialize_logger(args = { })
17
+ @logger = args[:logger] ||= Logger.new(args[:log_to] || STDOUT)
18
+ log_level = args[:log_level]
19
+ if log_level
20
+ @logger.level = log_level
21
+ args[:logger] = @logger
22
+ end
23
+ @logger
24
+ end
25
+
26
+ def initialize_http_client(args = { })
27
+ @http_client = Ubiquity::Wiredrive::API::V2::HTTPClient.new(args)
28
+ end
29
+
30
+ # @param [Requests::BaseRequest] request
31
+ # @param [Hash, nil] options
32
+ # @option options [Boolean] :execute_request (true) Will execute the request
33
+ # @option options [Boolean] :return_request (true) Will return the request instance instead of nil. Only applies if
34
+ # execute_request is false.
35
+ def process_request(request, options = nil)
36
+ # @paginator = nil
37
+ @response = nil
38
+ @request = request
39
+ logger.warn { "Request is Missing Required Arguments: #{request.missing_required_arguments.inspect}" } unless request.missing_required_arguments.empty?
40
+
41
+ # if ([:all, 'all'].include?(request.arguments[:_page]))
42
+ # request.arguments[:_page] = 1
43
+ # include_remaining_pages = true
44
+ # else
45
+ # include_remaining_pages = false
46
+ # end
47
+
48
+ request.client = self unless request.client
49
+ options ||= request.options
50
+
51
+ return (options.fetch(:return_request, true) ? request : nil) unless options.fetch(:execute_request, true)
52
+
53
+ #@response = http_client.call_method(request.http_method, { :path => request.path, :query => request.query, :body => request.body }, options)
54
+ @response = request.execute
55
+
56
+ # if include_remaining_pages
57
+ # return paginator.include_remaining_pages
58
+ # end
59
+
60
+ if @response.is_a?(Hash)
61
+ _results = @response['results']
62
+ return _results if _results
63
+ end
64
+
65
+ @response
66
+ end
67
+
68
+ # def paginator
69
+ # @paginator ||= Paginator.new(self) if @response
70
+ # end
71
+
72
+ def process_request_using_class(request_class, args = { }, options = { })
73
+ @response = nil
74
+ @request = request_class.new(args, options)
75
+ process_request(request, options)
76
+ end
77
+
78
+ def error
79
+ _error = errors.first
80
+ return _error.inspect if _error.is_a?(Hash)
81
+ _error
82
+ end
83
+
84
+ def error_message
85
+ _error = error
86
+ _error.is_a?(Hash) ? (_error['message'] || _error) : _error
87
+ end
88
+
89
+ def errors
90
+ return (response['errors'] || [ ]) if response.is_a?(Hash)
91
+ [ ]
92
+ end
93
+
94
+ def success?
95
+ return unless request
96
+ return request.success? if request.respond_to?(:success?)
97
+
98
+ _code = http_client.response.code
99
+ _code and _code.start_with?('2')
100
+ end
101
+
102
+ # ################################################################################################################## #
103
+ # @!group API METHODS
104
+
105
+ def asset_create(args = { }, options = { })
106
+ _request = Requests::BaseRequest.new(
107
+ args,
108
+ {
109
+ :http_path => 'assets',
110
+ :http_method => :post,
111
+ :default_parameter_send_in_value => :body,
112
+ :parameters => [
113
+ :name,
114
+ :description,
115
+ :workflow,
116
+ :is_folder,
117
+ { :name => :parent, :aliases => [ :parentid ] },
118
+ { :name => :project, :aliases => [ :projectid ] },
119
+ ]
120
+ }
121
+ )
122
+ # http_client.get('assets')
123
+ _response = process_request(_request, options)
124
+
125
+ _response.first if _response.is_a?(Array)
126
+ end
127
+
128
+ def asset_primary_file_init(args = { }, options = { })
129
+ args = { :id => args } if args.is_a?(String)
130
+ _request = Requests::BaseRequest.new(
131
+ args,
132
+ {
133
+ :http_path => 'assets/#{arguments[:id]}/primary_file',
134
+ :http_success_code => 202,
135
+ :http_method => :post,
136
+ :parameters => [
137
+ { :name => :id, :aliases => [ :assetid ], :send_in => :path }
138
+ ]
139
+ }
140
+ )
141
+ process_request(_request, options)
142
+ http_client.response['location']
143
+ end
144
+ alias :asset_upload_session_get :asset_primary_file_init
145
+
146
+ def asset_delete(args = { }, options = { })
147
+ _request = Requests::BaseRequest.new(
148
+ args,
149
+ {
150
+ :http_path => 'assets/#{arguments[:id]}',
151
+ :http_method => :delete,
152
+ :parameters => [
153
+ { :name => :id, :aliases => [ :assetid ], :send_in => :path },
154
+ ]
155
+ }
156
+ )
157
+ response = process_request(_request, options)
158
+ response
159
+ end
160
+
161
+ def asset_get(args = { }, options = { })
162
+
163
+ end
164
+
165
+ def assets_get(args = { }, options = { })
166
+ _request = Requests::BaseRequest.new(
167
+ args,
168
+ {
169
+ :http_path => 'assets',
170
+ :parameters => [
171
+ :limit,
172
+ :offset,
173
+ :id,
174
+ :name,
175
+ :workflow,
176
+ :is_folder,
177
+ :is_active,
178
+ :has_default_thumbs,
179
+ :date_created,
180
+ :date_modified,
181
+ :created_by,
182
+ { :name => :parent, :aliases => [ :parentid ] },
183
+ { :name => :project, :aliases => [ :projectid ] },
184
+ :height,
185
+ :width,
186
+ :mime_type,
187
+ :include
188
+ ]
189
+ }
190
+ )
191
+
192
+ name = _request.arguments[:name]
193
+ _request.arguments[:name] = CGI.escapeHTML(name) if name
194
+
195
+ # http_client.get('assets')
196
+ response = process_request(_request, options)
197
+ response
198
+ end
199
+
200
+ def file_upload(args = { }, options = { })
201
+ file_path = args[:file_path]
202
+ file_name = args[:file_name] || File.basename(file_path)
203
+
204
+ uri = args[:destination_uri]
205
+ uri = URI(uri) if uri.is_a?(String)
206
+
207
+ res = nil
208
+ File.open(file_path) do |file|
209
+ req = Net::HTTP::Post::Multipart.new uri.path,
210
+ 'file' => UploadIO.new(file, 'application/octet-stream', file_name)
211
+ http = Net::HTTP.new(uri.host, uri.port)
212
+ http.use_ssl = true
213
+ res = http.request(req)
214
+ end
215
+
216
+ res ? res.code.start_with?('2') : false
217
+ end
218
+
219
+ def project_create(args = { }, options = { })
220
+ _request = Requests::BaseRequest.new(
221
+ args,
222
+ {
223
+ :http_path => 'projects',
224
+ :http_method => :post,
225
+ :default_parameter_send_in_value => :body,
226
+ :parameters => [
227
+ :name,
228
+ :description,
229
+ :code,
230
+ :manager,
231
+ :notify_manager,
232
+ :is_active,
233
+ ]
234
+ }
235
+ )
236
+ _response = process_request(_request, options)
237
+
238
+ _response.first if _response.is_a?(Array)
239
+ end
240
+
241
+ def project_delete(args = { }, options = { })
242
+ _request = Requests::BaseRequest.new(
243
+ args,
244
+ {
245
+ :http_path => 'projects/#{arguments[:id]}',
246
+ :http_method => :delete,
247
+ :parameters => [
248
+ { :name => :id, :aliases => [ :projectid ], :send_in => :path },
249
+ ]
250
+ }
251
+ )
252
+ response = process_request(_request, options)
253
+ response
254
+ end
255
+
256
+ def project_get(args = { }, options = { })
257
+ _request = Requests::BaseRequest.new(
258
+ args,
259
+ {
260
+ :http_path => 'projects/#{arguments[:id]}',
261
+ :parameters => [
262
+ { :name => :id, :send_in => :path },
263
+ :q,
264
+ :include
265
+ ]
266
+ }
267
+ )
268
+ response = process_request(_request, options)
269
+ response
270
+ end
271
+
272
+ def projects_get(args = { }, options = { })
273
+ _request = Requests::BaseRequest.new(
274
+ args,
275
+ {
276
+ :http_path => 'projects',
277
+ :parameters => [
278
+ :id,
279
+ :name,
280
+ :code,
281
+ :notify_manager,
282
+ :is_active,
283
+ :date_last_accessed,
284
+ :date_created,
285
+ :date_modified,
286
+ :date_deleted,
287
+ :manager
288
+ ]
289
+ }
290
+ )
291
+
292
+ name = _request.arguments[:name]
293
+ _request.arguments[:name] = CGI.escapeHTML(name) if name
294
+
295
+ response = process_request(_request, options)
296
+ response
297
+ end
298
+
299
+ # @!endgroup API METHODS
300
+
301
+ end