algorithmiaio / algorithmia-ruby Goto Github PK
View Code? Open in Web Editor NEWRuby Client for Algorithmia Algorithms and Data API
Home Page: https://algorithmia.com/developers/clients/ruby/
License: MIT License
Ruby Client for Algorithmia Algorithms and Data API
Home Page: https://algorithmia.com/developers/clients/ruby/
License: MIT License
The class name Http is not great. Maybe "Requests" or "requestor"?
The way to set these was based on spec, but should be refactored to be more Ruby intuitive.
Instead of an algorithm response (in the event of an exception) getting returned to the user as a named exception with a stacktrace (like with out other clients) the ruby client instead returns "Oops, something went wrong" instead.
This was experienced by one of our customers and has slowed down their development, we should look to investigate this further.
Not really worth the separate file here now that client has been refactored to be small.
2 related points:
/v1
but rather default to https://api.algorithmia.com
. This is consistent with other clients and is especially helpful in the 2nd point:Hi. Are having some problems with the JSON gem and algorithmia, version 2.01 (and all others). In Ruby json-gem 2.04 is default, but the requirement here is json 1.8.6. There seems to be a conflict of some sort however:
usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems/specification.rb:2302:in `raise_if_conflicts': Unable to activate algorithmia-1.0.1, because json-2.0.2 conflicts with json (~> 1.8) (Gem::ConflictError)
Is it necessary to require 1.8, or could it be jumped to at least 2.0.2 so this doesn't happen? Don't know how to solve the problem otherwise, it occurs on an Ubuntu machine 14.04 LTS. I know it's a rather old distro, but its the one C9.io runs on and that's what I'm working on.
I tried to get file from algorithmia. I used SmartThumbnail algorithm for creating thumbnails and uploading it to directory. But i got error Encoding::UndefinedConversionError: "\xFF" from ASCII-8BIT to UTF-8
in algorithmia.rb
, Algorithmia::Algorithm.new(Unauth.....
can be replaced with UnauthenticatedClient.new.algo(...
In file http.rb
, change case statement on line 65 to use case response.code
and when XXX
.
Exists should not throw the 404 when it occurs, but it should def ...rescue error:not found ...end
See Addressable.
Also use match
methods to validate presence of "data://" on data URIs & "algo://" on algorithm URIs.
pipe_json should explicitly set Content-Type to application/json
, however in skimming a little deeper, Http.post
will try to do .to_json
on it if that header is present, and that would escape the string incorrectly. So, I don't think it's quite as simple as just setting Content-Type to fix. Off the top of my head, this may need some sort of change to Http
or perhaps just parsing the json_string before calling post
(a bit redundant to deserialize and reserialize, but at least it would verify the string was valid JSON)
the underlying HttpParty defaults to a 60 second client timeout for all requests and we never override it, even when setting the timeout query parameter.
This caught me by surprise because I tried comparing a DataFile.basename
with a local Pathname.basename
and they weren't equal when I expected them to be because DataObject.basename
returns a String
but the std library's Pathname.basename
returns a Pathname
Method should be private. Algo & DataFile & Data Directory
sanitize_data_uri
and parent
could both share implementation in DataObject
rather than being implemented twice (DataFile
and DataDirectory
)
The actual problem seems to be URI.encode, which is an alias for URI.escape. I think this could be changed to just CGI.encode the file name in lines 51 and 70 of lib/algorithmia/data_directory
. I'll research further and open a PR as soon as possible, but could use some feedback on this if possible.
When an algorithm developer attempts to invoke another algorithm with an improperly configured client:
client = Algorithmia.client('<api key>')
client.algo('example/algo').pipe(input)
The API returns an appropriately descriptive error message in its response:
{
"error": {
"message": "invalid authorization: api keys are not allowed within algorithms"
}
}
That tells the algorithm developer that API keys are not to be used within algorithms.
However, the algorithmia-ruby
library does not surface this message. Instead, it raises an exception with a rather misleading message:
Error: The request you are making requires authorization. Please check that you have permissions & that you've set your API key.
/opt/algorithm/vendor/bundle/ruby/2.2.0/gems/algorithmia-1.0.1/lib/algorithmia/requester.rb:92:in `check_for_errors'
# ...
Requester#check_for_errors
intends to surface the API response error message, as can be seen on line 87:
message = response.dig("error", "message") if response.is_a?(Hash)
However, the response object returned is a HTTParty::Response
object. This HTTParty::Response
object is returned by the delegated get, post, put, head, and delete within Requester
Note that while the HTTParty::Response
responds to Hash-like methods due to internal method_missing delegation, is_a? Hash
will evaluate to false
.
Even if we were to remove a Hash
type check, we must be careful. Hash#dig
was added in Ruby 2.3; and the Algorithmia developer platform runs on Ruby 2.2. Therefore Hash#dig
is not available to algorithm developers and will raise an error if invoked within an algorithm.
There are a few possible solutions. First, we should remove the Hash
type check. Additionally, we should either find a way other than Hash#dig
to retrieve the error message, or we should specify a required ruby version in the gem specification for this library.
Also, it may make sense to add a regression test to exercise this code path such that it doesn't resurface in the future.
I didn't spend enough time characterizing this, but wanted to file it for tracking/followup. It seems like most non-200 responses raise exceptions just fine, but an algorithm that returns an error doesn't seem to raise an exception, and at least at first glance I failed to figure out how to extract the error message (short of just printing the entire response object)
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.