cloudconvert-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +10 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +151 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cloudconvert-ruby.gemspec +39 -0
- data/lib/.DS_Store +0 -0
- data/lib/cloud_convert/.DS_Store +0 -0
- data/lib/cloud_convert/client.rb +57 -0
- data/lib/cloud_convert/exceptions.rb +4 -0
- data/lib/cloud_convert/lib/deep_symbolize.rb +20 -0
- data/lib/cloud_convert/process.rb +147 -0
- data/lib/cloud_convert/version.rb +10 -0
- data/lib/cloudconvert-ruby.rb +14 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 04793b94b43c41945fd265cada8f44d9c1858c61
|
4
|
+
data.tar.gz: afd96fcdddcd38b3b489a5b2881a5f2816de6203
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e098eabbf65450936db49767c5fa9c11a3244303170875b95b26e5db2d7fbf7bdd73fc5d27bee147ef503a9f9847b50b8247294accc4b862e9ee87d64864debf
|
7
|
+
data.tar.gz: 2daa7255282f1dff45f98eeed3c02987b810457ddc63ee297b2b6b74b8a3b602eb0afa825ecd35508d80fdbd905cf2278a8520ecbef82fb995493529fdc5ed7c
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at edwin.velasquez89@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Edwin Velasquez
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
# CloudConvert-Ruby
|
2
|
+
|
3
|
+
CloudConvert-Ruby is a ruby wrapper for the [Cloud Convert](https://www.google.com) api. It takes an object oriented approach to using the API, allowing you to quickly execute and access your conversions.
|
4
|
+
|
5
|
+
This gem is in its very early stage and is updated as the need arises for a new feature. I would appreciate any comments or suggestions.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'cloudconvert-ruby'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
## Basic Example
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
@client = CloudConvert::Client.new(api_key: "Your API Key")
|
23
|
+
@process = @client.build_process(input_format: "jpg", output_format: "pdf")
|
24
|
+
@process_response = @process.create
|
25
|
+
@conversion_response = @process.convert(
|
26
|
+
input: "download",
|
27
|
+
outputformat: "pdf",
|
28
|
+
file: "link to image",
|
29
|
+
download: "false"
|
30
|
+
) if @process_response[:success]
|
31
|
+
if @process_response[:success]
|
32
|
+
path = File.join(File.dirname(__FILE__), "output")
|
33
|
+
@download = @process.download(path)
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Basic Usage
|
38
|
+
|
39
|
+
We will start by creating a client. You will need to pass your API key to the initializer.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
@client = CloudConvert::Client.new(api_key: "Your API Key")
|
43
|
+
```
|
44
|
+
Once the client object is created, we can build a process for our conversion. In this example, we will convert a jpg image into a pdf.
|
45
|
+
|
46
|
+
Note: You can build as many processes as you want, just make sure that you are aware of any limitations placed on your account by Cloud Convert before you start converting files.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
@process = @client.build_process(input_format: "jpg", output_format: "pdf")
|
50
|
+
```
|
51
|
+
|
52
|
+
We now need to tell Cloud Convert that we are creating a process. To do this, we will use the `create` method.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
@process_response = @process.create
|
56
|
+
```
|
57
|
+
|
58
|
+
The response returned will be a hash containing all the information provided to us by Cloud Convert. (https://cloudconvert.com/apidoc#create)
|
59
|
+
|
60
|
+
Note: All the keys for the response hash are symbolized.
|
61
|
+
|
62
|
+
To start a conversion, you can execute the `convert` method. For all the parameters supported, visit the Cloud Convert API Doc [here](https://cloudconvert.com/apidoc#start)
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
@conversion_response = @process.convert(
|
66
|
+
input: "download",
|
67
|
+
outputformat: "pdf",
|
68
|
+
file: "link to image",
|
69
|
+
download: "false"
|
70
|
+
)
|
71
|
+
```
|
72
|
+
|
73
|
+
If you want to upload a file directly to Cloud Convert, pass the file object to the file argument. Make sure that the file object you are passing responds to the `read` method. Examples: `File`, `Tempfile`, `ActionDispatch::Http::UploadedFile`, etc.
|
74
|
+
|
75
|
+
Cloud Convert does a great job of quickly converting files. For coversions that might take longer, you can use the status method to check the progress of the conversion (https://cloudconvert.com/apidoc#status).
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
@status_response = @process.status
|
79
|
+
```
|
80
|
+
|
81
|
+
Once the conversion finishes, you can use the `download` method to grab the converted file. You will need to pass the directory where you want the file to be downloaded. The method will return the full path where the file was downloaded. If the file has yet to be converter, it will return the current status of the conversion as a hash.
|
82
|
+
|
83
|
+
Note: If you indicated that you want your files to be uploaded directly to another service, like S3, the file will start uploading once the conversion is finished. There is no need to download the file (https://cloudconvert.com/apidoc#download).
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
path = File.join(File.dirname(__FILE__), "output")
|
87
|
+
@download = @process.download(path)
|
88
|
+
```
|
89
|
+
|
90
|
+
If you would like to handle the download process, you can use the download_url method to grab the url of the file.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
@download_url = @process.download_url
|
94
|
+
```
|
95
|
+
|
96
|
+
There might be a time when you will want to cancel a conversion. To cancel a conversion, use the `delete` method (https://cloudconvert.com/apidoc#delete).
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
@delete_response = @process.delete
|
100
|
+
```
|
101
|
+
|
102
|
+
## Diving Deeper
|
103
|
+
|
104
|
+
### Accessing API responses throughout the life-cycle of a process
|
105
|
+
|
106
|
+
Each time a request is made to Cloud Convert, a copy of the response is saved to the process object. You can access them by using the following attributes.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
@process.process_response # Response returned by @process.create
|
110
|
+
@process.conversion_response # Response returned by @process.convert
|
111
|
+
@process.status_response # * Response returned by @process.status and @process.download
|
112
|
+
```
|
113
|
+
If you try to download a file before the conversion is completed, the response will be the current status of the conversion. This response wil update the `status_response` attribute.
|
114
|
+
|
115
|
+
### Converting objects that outputs multiple files
|
116
|
+
|
117
|
+
If a conversion produces multiple files, like converting pdf to html when the css files are not embedded, you will obtain a zip file from the `download` method. If you want to download an individual file, pass the name of the file when executing the `download` method.
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
@css_path = @process.download("base.min.css")
|
121
|
+
|
122
|
+
```
|
123
|
+
|
124
|
+
### Keeping track of the current step
|
125
|
+
|
126
|
+
Every `Process` object keeps the state of the conversion in the step attribute. All the steps are documented in the Cloud Convert API (https://cloudconvert.com/apidoc#status). Keep in mind that there are two steps that are unique to this gem.
|
127
|
+
|
128
|
+
* :awaiting_creation - Initial state of the process before it is sent to the API.
|
129
|
+
* :awaiting_conversion - The state after the executing the create method before starting the conversion process.
|
130
|
+
|
131
|
+
Also note, the step attribute is local and might not up to date unless you communicate to the API. If you want the most up-to date step, call the `status` method before you call `step`.
|
132
|
+
|
133
|
+
### Changing the return type of response from `Hash` to `Net::HTTPResponse`
|
134
|
+
|
135
|
+
You can change the return type of responses by changing the `return_type` of the client.
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
@client.return_type = :response
|
139
|
+
@process.status # Will return a Net::HTTPResponse object
|
140
|
+
@client.return_type = :hash
|
141
|
+
@process.status # Will return a Hash object
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
## Contributing
|
146
|
+
|
147
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/edwinv710/cloudconvert-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
148
|
+
|
149
|
+
## License
|
150
|
+
|
151
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cloud_convert"
|
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
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cloud_convert/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cloudconvert-ruby"
|
8
|
+
spec.version = CloudConvert::VERSION
|
9
|
+
spec.authors = ["Edwin Velasquez"]
|
10
|
+
spec.email = ["edwin.velasquez89@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby wrapper for the Cloud Convert API"
|
13
|
+
spec.description = "cloudconver-ruby is a ruby wrapper for the Cloud Convert API"
|
14
|
+
spec.homepage = "http://github.com/edwinv710/cloudconver-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org/"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
33
|
+
spec.add_development_dependency "webmock", "~> 1.22.3"
|
34
|
+
spec.add_development_dependency "sinatra", "~> 1.4.3"
|
35
|
+
spec.add_development_dependency "vcr", "~> 3.0.0"
|
36
|
+
spec.add_development_dependency "rake-notes"
|
37
|
+
|
38
|
+
spec.add_dependency "httmultiparty", "~> 0.3.15"
|
39
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,57 @@
|
|
1
|
+
##
|
2
|
+
# Client handles all the information needed to connect to the api.
|
3
|
+
|
4
|
+
|
5
|
+
# TODO research other wrappers to see how they handle the client without an api key. Do they allow the creating of the client with out one?
|
6
|
+
# TODO Build 'running_conversions' method.
|
7
|
+
# TODO Build 'conversion_types' method.
|
8
|
+
# TODO Inspect the initialize to see if I should add or remove options. Parameters vs hash.
|
9
|
+
|
10
|
+
|
11
|
+
module CloudConvert
|
12
|
+
class Client
|
13
|
+
include HTTMultiParty
|
14
|
+
##
|
15
|
+
# The api key obtained from the cloud convert service.
|
16
|
+
attr_reader :api_key
|
17
|
+
##
|
18
|
+
# An array containing references to the processes created through the client.
|
19
|
+
attr_reader :processes
|
20
|
+
attr_accessor :return_type
|
21
|
+
|
22
|
+
##
|
23
|
+
# Creates a new client with an api key. Optionally, you can also pass an array of processes.
|
24
|
+
def initialize(args = {})
|
25
|
+
@api_key = args[:api_key]
|
26
|
+
args[:processes].nil? ?
|
27
|
+
@processes = [] :
|
28
|
+
@processes = args[:processes]
|
29
|
+
@return_type = args[:return_type] || :json
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Builds a process object and adds it to the client. Accepts the input format and output format for the conversion.
|
34
|
+
def build_process(opts = {})
|
35
|
+
opts[:client] = self
|
36
|
+
process = CloudConvert::Process.new(opts)
|
37
|
+
processes.push(process)
|
38
|
+
return process
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Returns an array of hash with the results from the Cloud Convert list endpoint.
|
43
|
+
def list
|
44
|
+
url = "#{CloudConvert::PROTOCOL}://api.#{CloudConvert::DOMAIN}/processes"
|
45
|
+
response = CloudConvert::Client.send(:get, url, query: {apikey: self.api_key})
|
46
|
+
return convert_response response
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def convert_response(response)
|
52
|
+
return response.response if self.return_type == :response
|
53
|
+
return response.parsed_response.deep_symbolize
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Hash
|
2
|
+
def deep_symbolize
|
3
|
+
self.inject({}) do |new_hash, (key,value)|
|
4
|
+
new_hash[key.to_sym] = value.deep_symbolize
|
5
|
+
new_hash
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Array
|
11
|
+
def deep_symbolize
|
12
|
+
map(&:deep_symbolize)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Object
|
17
|
+
def deep_symbolize
|
18
|
+
return self
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module CloudConvert
|
5
|
+
|
6
|
+
class Process
|
7
|
+
attr_reader :client,
|
8
|
+
:input_format,
|
9
|
+
:output_format,
|
10
|
+
:process_response,
|
11
|
+
:conversion_response,
|
12
|
+
:status_response,
|
13
|
+
:download_url,
|
14
|
+
:step
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
def initialize(args = {})
|
19
|
+
@input_format = args[:input_format]
|
20
|
+
@output_format = args[:output_format]
|
21
|
+
@step = :awaiting_creation
|
22
|
+
@client = args[:client]
|
23
|
+
end
|
24
|
+
|
25
|
+
def create
|
26
|
+
raise CloudConvert::InvalidStep unless @step == :awaiting_creation
|
27
|
+
url = construct_url("api", "process")
|
28
|
+
response = send_request(http_method: :post,
|
29
|
+
url: url,
|
30
|
+
params: {
|
31
|
+
"apikey" => @client.api_key,
|
32
|
+
"inputformat" => @input_format,
|
33
|
+
"outputformat" => @outputformat
|
34
|
+
}) do | response|
|
35
|
+
@step = :awaiting_conversion
|
36
|
+
response.parsed_response[:success] = true
|
37
|
+
create_parsed_response(:process_response, response.parsed_response)
|
38
|
+
@process_response[:subdomain] = extract_subdomain_from_url(@process_response[:url])
|
39
|
+
end
|
40
|
+
return convert_response response
|
41
|
+
end
|
42
|
+
|
43
|
+
def convert(opts)
|
44
|
+
raise CloudConvert::InvalidStep if @step == :awaiting_creation
|
45
|
+
url = process_url(include_process_id: true)
|
46
|
+
multi = opts[:file].respond_to?("read")
|
47
|
+
response = send_request(http_method: :post,
|
48
|
+
url: url,
|
49
|
+
params: opts,
|
50
|
+
multi: multi) do |response|
|
51
|
+
response.parsed_response[:success] = true
|
52
|
+
create_parsed_response(:conversion_response, response.parsed_response)
|
53
|
+
@step = @conversion_response[:step].to_sym
|
54
|
+
end
|
55
|
+
return convert_response response
|
56
|
+
end
|
57
|
+
|
58
|
+
def status
|
59
|
+
url = process_url(include_process_id: true)
|
60
|
+
response = send_request(http_method: :get,
|
61
|
+
url: url) do |response|
|
62
|
+
create_parsed_response(:status_response, response.parsed_response)
|
63
|
+
@step = @status_response[:step].to_sym
|
64
|
+
end
|
65
|
+
return convert_response response
|
66
|
+
end
|
67
|
+
|
68
|
+
def download(path, file_name="")
|
69
|
+
response = HTTMultiParty.get(download_url(file_name))
|
70
|
+
return update_download_progress response unless response.response.code == "200"
|
71
|
+
file_name = response.response.header['content-disposition'][/filename=(\"?)(.+)\1/, 2] if file_name.strip.empty?
|
72
|
+
full_path = full_path(path, file_name)
|
73
|
+
return full_path.open("w") do |f|
|
74
|
+
f.binmode
|
75
|
+
f.write response.parsed_response
|
76
|
+
full_path.to_s
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def delete
|
81
|
+
url = construct_url(process_response[:subdomain], "process", process_response[:id])
|
82
|
+
response = HTTMultiParty.delete(url)
|
83
|
+
@step = :deleted if response.response.code == "200"
|
84
|
+
return convert_response response
|
85
|
+
end
|
86
|
+
|
87
|
+
def download_url(file = "")
|
88
|
+
file = "/#{file}" unless file.nil? or file.strip.empty?
|
89
|
+
return "https://#{@process_response[:subdomain]}.cloudconvert.com/download/#{@process_response[:id]}#{file}"
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def send_request(opts)
|
96
|
+
request = opts[:params] || {}
|
97
|
+
args = [opts[:http_method], opts[:url], {query: request, detect_mime_type: (true if opts[:multi])}]
|
98
|
+
response = CloudConvert::Client.send(*args)
|
99
|
+
yield(response) if block_given? and (response.response.code == "200" ||
|
100
|
+
(response.parsed_response.kind_of?(Hash) and response.parsed_response.key?("step")))
|
101
|
+
return response
|
102
|
+
end
|
103
|
+
|
104
|
+
def construct_url(subdomain, action, id="")
|
105
|
+
id = "/#{id}" if id.length > 0
|
106
|
+
return "#{CloudConvert::PROTOCOL}://#{subdomain}.#{CloudConvert::DOMAIN}/#{action}#{id}"
|
107
|
+
end
|
108
|
+
|
109
|
+
def process_url(opts = {})
|
110
|
+
action = (opts[:include_process_id] ? "process/#{@process_response[:id]}" : "process")
|
111
|
+
return construct_url(@process_response[:subdomain], action)
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
def create_parsed_response(variable_symbol, parsed_response)
|
116
|
+
symbolized_response = parsed_response.deep_symbolize
|
117
|
+
return self.instance_variable_set("@#{variable_symbol.to_s}", symbolized_response)
|
118
|
+
end
|
119
|
+
|
120
|
+
def extract_subdomain_from_url(url)
|
121
|
+
return url.split(".")[0].tr('/','')
|
122
|
+
end
|
123
|
+
|
124
|
+
def convert_response(response)
|
125
|
+
case @client.return_type
|
126
|
+
when :response
|
127
|
+
return response.response
|
128
|
+
else
|
129
|
+
parsed_response = response.parsed_response.deep_symbolize
|
130
|
+
return parsed_response
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def full_path(dir, file_name)
|
135
|
+
return Pathname(dir).join(file_name)
|
136
|
+
end
|
137
|
+
|
138
|
+
def update_download_progress(response)
|
139
|
+
if response.parsed_response["step"]
|
140
|
+
create_parsed_response(:status_response, response.parsed_response)
|
141
|
+
@step = @status_response[:step].to_sym
|
142
|
+
end
|
143
|
+
return convert_response response
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'httmultiparty'
|
3
|
+
require "cloud_convert/exceptions"
|
4
|
+
|
5
|
+
require "cloud_convert/version"
|
6
|
+
require "cloud_convert/client"
|
7
|
+
require "cloud_convert/process"
|
8
|
+
require "cloud_convert/lib/deep_symbolize"
|
9
|
+
|
10
|
+
module CloudConvert
|
11
|
+
# Your code goes here...
|
12
|
+
PROTOCOL = "https"
|
13
|
+
DOMAIN = "cloudconvert.com"
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloudconvert-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Edwin Velasquez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.22.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.22.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake-notes
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: httmultiparty
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.3.15
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.3.15
|
125
|
+
description: cloudconver-ruby is a ruby wrapper for the Cloud Convert API
|
126
|
+
email:
|
127
|
+
- edwin.velasquez89@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".DS_Store"
|
133
|
+
- ".gitignore"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- cloudconvert-ruby.gemspec
|
143
|
+
- lib/.DS_Store
|
144
|
+
- lib/cloud_convert/.DS_Store
|
145
|
+
- lib/cloud_convert/client.rb
|
146
|
+
- lib/cloud_convert/exceptions.rb
|
147
|
+
- lib/cloud_convert/lib/deep_symbolize.rb
|
148
|
+
- lib/cloud_convert/process.rb
|
149
|
+
- lib/cloud_convert/version.rb
|
150
|
+
- lib/cloudconvert-ruby.rb
|
151
|
+
homepage: http://github.com/edwinv710/cloudconver-ruby
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata:
|
155
|
+
allowed_push_host: https://rubygems.org/
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.5.1
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: Ruby wrapper for the Cloud Convert API
|
176
|
+
test_files: []
|