cloudconvert 0.0.3 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +17 -18
- data/README.md +234 -39
- data/cloudconvert.gemspec +39 -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 +318 -46
- data/.gitignore +0 -17
- data/Gemfile +0 -7
- data/Rakefile +0 -1
- data/lib/cloudconvert/configuration.rb +0 -21
- data/lib/cloudconvert/conversion.rb +0 -111
data/.gitignore
DELETED
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,111 +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 = 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, 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
|
-
|
66
|
-
#######################################################################################################
|
67
|
-
#######################################################################################################
|
68
|
-
def api_key
|
69
|
-
raise Cloudconvert::API_KEY_ERROR if Cloudconvert.configuration.api_key == nil
|
70
|
-
Cloudconvert.configuration.api_key
|
71
|
-
end
|
72
|
-
|
73
|
-
def callback
|
74
|
-
Cloudconvert.configuration.callback
|
75
|
-
end
|
76
|
-
|
77
|
-
#send conversion http request
|
78
|
-
def conversion_post_request(inputformat, outputformat)
|
79
|
-
@conversion_connection.post "https://api.cloudconvert.org/process?inputformat=#{inputformat}&outputformat=#{outputformat}&apikey=#{api_key}"
|
80
|
-
end
|
81
|
-
|
82
|
-
def start_conversion(inputformat, outputformat)
|
83
|
-
response = conversion_post_request(inputformat,outputformat)
|
84
|
-
|
85
|
-
parsed_response = parse_response(response.body)
|
86
|
-
@process_id = parsed_response["id"]
|
87
|
-
|
88
|
-
"https://#{parsed_response['host']}"
|
89
|
-
end
|
90
|
-
|
91
|
-
def initiate_connection(url)
|
92
|
-
@request_connection = Faraday.new(:url => url)
|
93
|
-
end
|
94
|
-
|
95
|
-
#building params for local file
|
96
|
-
def build_upload_params(file_path, outputformat, options)
|
97
|
-
upload_params = { :format => outputformat, :options => options}
|
98
|
-
upload_params.merge!(:callback => callback) if callback != nil
|
99
|
-
upload_params.merge!(:input => "download",:link => file_path )
|
100
|
-
end
|
101
|
-
|
102
|
-
def parse_response(response)
|
103
|
-
JSON.parse(response)
|
104
|
-
end
|
105
|
-
|
106
|
-
#######################################################################################################
|
107
|
-
#######################################################################################################
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|