transloadit / ruby-sdk Goto Github PK
View Code? Open in Web Editor NEWTransloadit's official Ruby SDK, maintained by the community
Home Page: https://transloadit.com/
License: MIT License
Transloadit's official Ruby SDK, maintained by the community
Home Page: https://transloadit.com/
License: MIT License
What used to be a warning on Ruby 2.7
gems/transloadit-2.0.1/lib/transloadit/request.rb:154: warning: URI.escape is obsolete
is not fully deprecated and crashes.
In the POST payload to /assemblies
, the signature should come right after the "params" field, and not after the files. There are various reasons:
Relevant code parts are:
https://github.com/transloadit/ruby-sdk/blob/master/lib/transloadit/assembly.rb#L60
https://github.com/transloadit/ruby-sdk/blob/master/lib/transloadit/request.rb#L77
https://github.com/transloadit/ruby-sdk/blob/master/lib/transloadit/request.rb#L129
I feel it's good design that the signature calculation code lives in the Request class and is added as an after thought. But I feel it might need to be moved to the assembly class and added before the files are added.
Hey there,
I've committed an initial TravisCI config (35e8dfc, db88647) to get rid of the manual multiruby-test thing we did in the past.
There are some things failing right now (have to figure out what happens there). Few notes / questions:
That's that, just wanted to let you know. If anywant wants to help, go for it :)
Thanks for your work on this gem :)
ruby-sdk has dependency on 'mime-types', '~> 2.99'
Rails 5 depends on mime-types (3.1)
Can you loosen the dependency so ruby-sdk can be used in a Rails 5 app?
Hi everyone,
First of all let me apologize, I know I'm not on the right channel here, but you are the only guys I found that can help me solve my problem.
I can't use this Gem because I do the main Transloadit code with Javascript on the front-end.
The only thing I have to deal on the server side with (Ruby 2.1.1 and Rails 4.1) is the signature generation, but I can't make it work.
I tried the example present in the documentation, with the code provided at https://transloadit.com/docs/api-docs#authentication-implementations.
It seems that you guys use the same code: https://github.com/transloadit/ruby-sdk/blob/master/lib/transloadit/request.rb#L199
p = JSON.generate({ auth: { expires: "2010/10/19 09:01:20+00:00", key: "2b0c45611f6440dfb64611e872ec3211"}, steps: { encode: { robot: "/video/encode" } } })
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), "d805593620e689465d7da6b8caf2ac7384fdb7e9", p)
the result is 00320965b86d42b6d983d1fad3f126ee7385b962
but according to the documentation it should be 6032b7b62879829941b84df5cfaebfe4644ab4e3
Could you please tell me what I'm doing wrong ?
PS: I have also posted a stackoverflow question if you want to gain some karma ;)
http://stackoverflow.com/questions/24230394/transloadit-unable-to-generate-the-right-signature-with-ruby
Using a working Transloadit Ruby-SDK setup (processes video files correctly), I cannot seem to get the assembly.list or Transloadit.bill calls to work. I have "Deny requests that do not include a signature or a wrong one?" turned off on my account for now.
irb(main):001:0> assembly = Transloadit.assembly
=> {:auth=>{:key=>"MY_KEY_HERE", :expires=>"2018/05/19 01:24:57+00:00"}}
irb(main):002:0> assembly.list
=> {"error"=>"INVALID_SIGNATURE", "message"=>"The given signature does not match ours."}
I'm pretty sure it's because the signature is not being generated/sent but that's not made clear that it needs to be sent anywhere other than the transloadit docs.
Also, there's no documentation here on how to send a signature or if it's automatic.
Edit: Inspecting the request shows that it is indeed generating a signature, unclear why it's wrong.
Hi Steven,
I want to go ahead and finally release the ruby / rails sdks. I was just wondering if both have the latest source code published as a gem at this point / if not if you could go ahead and do that.
Cheers, Felix
Awesome library! One improvement came to mind. Since we're building steps as an array of objects, it would be nice for the library to detect if the user accidentally named two different steps with the same name, and raise an error. I just think that the way assemblies are built, this mistake can happen easily.
The current behaviour is probably that the latter step will silently override the previous, and I was just thinking that it would be great to explicitly let the user know that they made a mistake.
Can you clearly describe what license this code is released under?
It seems like the only way to send a file to Transloadit is with the open def. Our image, audio and video files are in the database as Base64 encoded binary files. Creating a temp file to upload is really a waste of resources when we already have a binary format. Any ideas how to solve it? Thanks
Hi,
I was looking for a code snippet that illustrates how to set the audio segment of a video. Do you have that?
Thanks very much!
I am using transloadit gem version '1.0.4' on ruby ruby-1.9.3-p551.
I receive the error
NoMethodError: undefined method `body' for nil:NilClass
from /Users/aarram/.rvm/gems/ruby-1.9.3-p551@srma_api/gems/transloadit-1.0.4/lib/transloadit/response.rb:34:in `body'
when I do
require 'transloadit'
file_to_process = "https://dashboarddev.s3.amazonaws.com/e1/840430299911e786fee949b8f945fb/Penguins.png"
transloadit = Transloadit.new(
:key => KEY,
:secret => SECRET_KEY)
import = transloadit.step 'import', '/http/import',
{ :url => file_to_process}
resize_avatar = transloadit.step 'resize_avatar', '/image/resize',
{ :use => "import",
:background => "transparent",
:resize_strategy => "pad",
:width => 50,
:height => 50,
:format => "png" }
export = transloadit.step 'export', '/sftp/store',
{ :use => "resize_avatar",
:user => "sshacs",
:host => HOST,
:path => PATH,
:url_template => URL_TEMPLATE,
:ssl_url_template => SSL_URL_TEMPLATE,
:sshkey => SSH_KEY }
assembly = transloadit.assembly(
:steps => [ import, resize_avatar, export ]
)
response = assembly.submit!
Can you please help me? Currently I do not want to upgrade my ruby version.
We had a use case where we wanted to specifically use the european endpoint (https://api2-eu-west-1.transloadit.com) instead of the default one (http://api2.transloadit.com/) to the Transloadit API.
Would be nice if we could define a specific endpoint when initializing the request.
Sometimes the API returns a basic HTML 404 that the SDK tries to parse anyway, and I'm getting JSON::ParseError
exception notifications from the following response:
<html>
<head>
<title>404 Not Found</title>
</head>
<body bgcolor="white">
<center>
<h1>404 Not Found</h1>
</center>
<hr>
<center>nginx/1.7.1</center>
</body>
</html>
Totally understand the API being unreachable every so often (this happened only twice in two minutes), but I did expect the SDK to catch the 404 response and raise it's own exception or return a response object.
Right now the response object is very confusing. If you wait for response.completed? to be true, it will never happen if there is an error. This is because completed? returns false even if the assembly failed to execute.
I suggest changing the methods to be something more like:
depend on multi_json so that the json engine is pluggable
The latest git tag on GitHub is v1.1.0
, so the following tags are missing:
v1.1.1
v1.1.2
v1.1.3
v1.1.4
v1.2.0
v2.0.0
v2.0.1
I would recommend using the Rake tasks provided by Bundler, which automate the process of building, releasing, tagging, and pushing:
# Rakefile
require "bundler/gem_tasks"
# ...
$ rake release # builds, releases, tags, and pushes the version specified in transloadit.gemspec
Since Travis isn't usable for open source anymore.
When we are done, we should also update the badge at https://transloadit.com/docs/#sdks by adding this frontmatter to the ruby-sdk integration file:
ghactions_workflow: Ruby SDK CI # assuming that becomes the github actions workflow name
ruby-sdk/lib/transloadit/request.rb
Lines 123 to 128 in 42ad458
After submitting an assembly, response['assembly_id'] returns the assembly id, but response[:assembly_id] just returns nil.
However, the README promises that response[:assembly_id] will work.
Looking at the code for Transloadit::Response, you're just doing JSON.parse on the body, which returns string keys, not symbol keys.
This could be easily fixed by adding a #to_s coercion in Transloadit::Response#[]:
def [](attribute)
self.body[attribute.to_s]
end
A low timeout makes sense for direct API access, but not so much for the Rails SDK. The timeout should be configurable so the Rails SDK can override it with a higher default (and let the client override it if need be).
I'm creating assemblies in background jobs, and polling until they are finished so that I can save the results in the database. The README here shows a simple polling example, and notes "you'll want to implement a timeout in your production app" -- here's a helper I rolled up, with a simple max tries timeout threshold: https://gist.github.com/gbuesing/e2f0b94ae3d2f9b0c6848b82ace51201
Seems like this is a common enough pattern that it could be provided by this library, vs. everyone rolling their own. I think the api could look something like:
response = assembly.create!
response.reload_until_finished! max_tries: 300
results = response['results'] # i.e. can work with results now, or MaxTries exception was raised
I don't think Ruby's Timeout is worth pursuing here, after reading http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/
As per documentation, to do synchronous processing
# loop until processing is finished
until response.finished?
sleep 1; response.reload! # you'll want to implement a timeout in your production app
end
I use this code but it locks up the ruby thread indefinitely (even though Assembly has completed) only when i upload large files ~ 3GB
< 1 gb files works fine which makes this a very odd problem
Is there an internal timeout which is not caught?
Is this something it can handle?
If it currently cannot handle it, let me know, I will try and build it in.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.