cloudconvert 0.0.3 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore DELETED
@@ -1,17 +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
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in cloudconvert.gemspec
4
- gemspec
5
-
6
- gem "faraday"
7
- gem "json"
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