cloudconvert 0.0.5 → 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 +5 -5
- data/LICENSE.txt +17 -18
- data/README.md +234 -39
- data/cloudconvert.gemspec +34 -22
- data/lib/cloudconvert.rb +33 -10
- data/lib/cloudconvert/base.rb +173 -0
- data/lib/cloudconvert/client.rb +107 -0
- data/lib/cloudconvert/collection.rb +15 -0
- data/lib/cloudconvert/entity.rb +21 -0
- data/lib/cloudconvert/error.rb +108 -0
- data/lib/cloudconvert/event.rb +14 -0
- data/lib/cloudconvert/file.rb +9 -0
- data/lib/cloudconvert/job.rb +18 -0
- data/lib/cloudconvert/middleware.rb +9 -0
- data/lib/cloudconvert/resource.rb +9 -0
- data/lib/cloudconvert/resources/jobs.rb +54 -0
- data/lib/cloudconvert/resources/tasks.rb +80 -0
- data/lib/cloudconvert/resources/users.rb +10 -0
- data/lib/cloudconvert/task.rb +43 -0
- data/lib/cloudconvert/user.rb +18 -0
- data/lib/cloudconvert/version.rb +2 -2
- data/lib/cloudconvert/webhook.rb +54 -0
- data/lib/cloudconvert/webhook/processor.rb +29 -0
- metadata +303 -24
- data/.gitignore +0 -21
- data/Gemfile +0 -7
- data/Rakefile +0 -1
- data/lib/cloudconvert/configuration.rb +0 -21
- data/lib/cloudconvert/conversion.rb +0 -105
data/.gitignore
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
*.xml
|
19
|
-
.idea/.name
|
20
|
-
.idea/.rakeTasks
|
21
|
-
*.iml
|
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
@@ -1,21 +0,0 @@
|
|
1
|
-
|
2
|
-
module Cloudconvert
|
3
|
-
class Configuration
|
4
|
-
attr_accessor :api_key, :callback
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
api_key = nil
|
8
|
-
callback = nil
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
class << self
|
14
|
-
attr_accessor :configuration
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.configure
|
18
|
-
self.configuration ||= Configuration.new
|
19
|
-
yield(configuration) if block_given?
|
20
|
-
end
|
21
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
module Cloudconvert
|
2
|
-
class Conversion
|
3
|
-
attr_accessor :convert_request_url, :conn , :request_connection, :process_id, :conversion_connection
|
4
|
-
|
5
|
-
#request_connection => specific to file conversion
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
raise Cloudconvert::API_KEY_ERROR if Cloudconvert.configuration.api_key == nil
|
9
|
-
@conversion_connection = Faraday.new(:url => Cloudconvert::CONVERSION_URL)
|
10
|
-
end
|
11
|
-
|
12
|
-
#convert request for file
|
13
|
-
def convert(inputformat, outputformat, file_path, callback_url = nil, options = {})
|
14
|
-
raise "File path cant be blank" if file_path.nil?
|
15
|
-
@convert_request_url = start_conversion(inputformat, outputformat)
|
16
|
-
#initiate connection with new response host
|
17
|
-
initiate_connection(@convert_request_url)
|
18
|
-
upload(build_upload_params(file_path, outputformat, callback_url, options))
|
19
|
-
end
|
20
|
-
|
21
|
-
#lists all conversions
|
22
|
-
def list_conversions
|
23
|
-
response = @conversion_connection.get '/processes', {:apikey => api_key }
|
24
|
-
parse_response(response.body)
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
#cancels current conversion
|
29
|
-
def cancel_conversion
|
30
|
-
response = @request_connection.get "/process/#{@process_id.to_s}/cancel"
|
31
|
-
parse_response(response.body)
|
32
|
-
end
|
33
|
-
|
34
|
-
#deletes finished conversion
|
35
|
-
def delete_conversion
|
36
|
-
response = @request_connection.get "/process/#{@process_id.to_s}/delete"
|
37
|
-
parse_response(response.body)
|
38
|
-
end
|
39
|
-
|
40
|
-
#upload request
|
41
|
-
def upload(upload_params)
|
42
|
-
response = @request_connection.post "/process/#{@process_id.to_s}", upload_params
|
43
|
-
parse_response(response.body)
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
# checks if conversion finished for process id and returns download link
|
48
|
-
def download_link
|
49
|
-
response = status
|
50
|
-
response["step"] == "finished" ? "http:#{response['output']['url']}" : nil
|
51
|
-
end
|
52
|
-
|
53
|
-
# checks status of conversion with process_id
|
54
|
-
def status
|
55
|
-
response = @request_connection.get "/process/#{@process_id.to_s}"
|
56
|
-
parse_response(response.body)
|
57
|
-
end
|
58
|
-
|
59
|
-
#returns all possible conversions and options
|
60
|
-
def converter_options(inputformat ="", outputformat = "")
|
61
|
-
response = @conversion_connection.get "conversiontypes", {:inputformat => inputformat,:outputformat => outputformat }
|
62
|
-
parse_response(response.body)
|
63
|
-
end
|
64
|
-
|
65
|
-
def api_key
|
66
|
-
raise Cloudconvert::API_KEY_ERROR if Cloudconvert.configuration.api_key == nil
|
67
|
-
Cloudconvert.configuration.api_key
|
68
|
-
end
|
69
|
-
|
70
|
-
def callback(callback_url = nil)
|
71
|
-
callback_url || Cloudconvert.configuration.callback
|
72
|
-
end
|
73
|
-
|
74
|
-
#send conversion http request
|
75
|
-
def conversion_post_request(inputformat, outputformat)
|
76
|
-
@conversion_connection.post "https://api.cloudconvert.org/process?inputformat=#{inputformat}&outputformat=#{outputformat}&apikey=#{api_key}"
|
77
|
-
end
|
78
|
-
|
79
|
-
def start_conversion(inputformat, outputformat)
|
80
|
-
response = conversion_post_request(inputformat,outputformat)
|
81
|
-
|
82
|
-
parsed_response = parse_response(response.body)
|
83
|
-
@process_id = parsed_response["id"]
|
84
|
-
|
85
|
-
"https://#{parsed_response['host']}"
|
86
|
-
end
|
87
|
-
|
88
|
-
def initiate_connection(url)
|
89
|
-
@request_connection = Faraday.new(:url => url)
|
90
|
-
end
|
91
|
-
|
92
|
-
#building params for local file
|
93
|
-
def build_upload_params(file_path, outputformat, callback_url = nil, options = {})
|
94
|
-
upload_params = { :format => outputformat}
|
95
|
-
upload_params.merge!(:callback => callback(callback_url)) if callback(callback_url).present?
|
96
|
-
upload_params.merge!(:input => "download",:link => file_path )
|
97
|
-
upload_params.merge!(options)
|
98
|
-
end
|
99
|
-
|
100
|
-
def parse_response(response)
|
101
|
-
JSON.parse(response)
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|