algorithmia 0.2.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -1
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +3 -3
- data/LICENSE +21 -0
- data/README.md +196 -0
- data/Rakefile +6 -63
- data/algorithmia.gemspec +22 -24
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/algorithmia.rb +28 -15
- data/lib/algorithmia/algorithm.rb +49 -0
- data/lib/algorithmia/client.rb +21 -0
- data/lib/algorithmia/data_directory.rb +91 -0
- data/lib/algorithmia/data_file.rb +55 -0
- data/lib/algorithmia/data_object.rb +26 -0
- data/lib/algorithmia/errors.rb +19 -5
- data/lib/algorithmia/requester.rb +104 -0
- data/lib/algorithmia/response.rb +39 -0
- data/lib/algorithmia/unauthenticated_client.rb +7 -0
- data/lib/algorithmia/version.rb +3 -7
- metadata +56 -36
- data/.ruby-version +0 -1
- data/LICENSE.txt +0 -8
- data/algorithmia.png +0 -0
- data/lib/algorithmia/authentication.rb +0 -24
- data/lib/algorithmia/base.rb +0 -14
- data/lib/algorithmia/http.rb +0 -33
- data/lib/algorithmia/result.rb +0 -25
- data/readme.markdown +0 -37
- data/spec/algorithmia_spec.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15bebf58e21513e4d156ac2cf371be83a716751e
|
4
|
+
data.tar.gz: 2318772a07f846302e7552081d8cd410e1c298c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46a702c1c1c063e808978b7746f033ce6de312fa3af45bd27b86a2cabf4cfbf73555e724110fe2939d29b6a57a8a7a2a437bb9bc3b470793418a581917b34810
|
7
|
+
data.tar.gz: 324a9e6ae7c64e6ac749d28e7958903448ce885f6920d054a6970fa44640eb122cbf3d8ff532c1cb58b3143fa6fc21f57377d4d97e644b2fe07c8fea0fd6f26a
|
data/.gitignore
CHANGED
data/.rspec
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 support@algorithmia.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
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem
|
4
|
-
|
3
|
+
# Specify your gem's dependencies in algorithmia.gemspec
|
4
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Algorithmia
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
# The Algorithmia Ruby Client
|
2
|
+
|
3
|
+
The Algorithmia Ruby client is a wrapper for making calls to the Algorithmia API and Data API.
|
4
|
+
|
5
|
+
With Algorithmia, you can leverage algorithms written in any language by including them in your Ruby project with a simple API call! Browse the collection of algorithms available on [Algorithmia.com](http://algorithmia.com).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
#### Local Builds:
|
10
|
+
|
11
|
+
Because this gem is yet to be released on ruby gems, follow these instructions to build and use it locally:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem build algorithmia.gemspec && gem install algorithmia-0.1.0.gem
|
15
|
+
```
|
16
|
+
|
17
|
+
#### Regular installation:
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'algorithmia'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
$ bundle
|
28
|
+
```
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
```bash
|
32
|
+
$ gem install algorithmia
|
33
|
+
```
|
34
|
+
|
35
|
+
## Basic Usage
|
36
|
+
|
37
|
+
To call to the API, the gem uses a client model. Create and configure a client object with your API key to start making requests.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require algorithmia
|
41
|
+
|
42
|
+
# Create a new client instance & set your API key
|
43
|
+
client = Algorithmia.client('YOUR_API_KEY')
|
44
|
+
|
45
|
+
algorithm = 'demo/Hello/0.1.1'
|
46
|
+
algorithm_result = client.algo(algorithm).pipe("HAL 9000").result
|
47
|
+
puts algorithm_result
|
48
|
+
# => Hello HAL 9000
|
49
|
+
```
|
50
|
+
|
51
|
+
### Algorithm Objects
|
52
|
+
|
53
|
+
When you call `.algo` on your client, it will return a new instance of `Algorithmia::Algorithm`. On this object, you have the the following methods:
|
54
|
+
- `pipe`: the default method to calling an algorithm (recommended)
|
55
|
+
- `pipeJson`
|
56
|
+
- `set_options`: set query parameters on your request
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
algorithm = client.algo('demo/Hello/0.1.1')
|
60
|
+
# => #<Algorithmia::Algorithm:0x007f80ea092fc8 @client=Algorithmia::Client, @endpoint="demo/Hello/0.1.1", @query_options={:timeout=>300, :stdout=>false, :output=>"default"}>
|
61
|
+
|
62
|
+
# Pass in a hash of options to override the default query parameters
|
63
|
+
algorithm.set_options({'timeout': 500})
|
64
|
+
# => {:timeout=>500, :stdout=>false, :output=>"default"}
|
65
|
+
|
66
|
+
# Use these helper methods to enable stdout or change the timeout value
|
67
|
+
algorithm.set_timeout(500)
|
68
|
+
# => 500
|
69
|
+
algorithm.enable_stdout
|
70
|
+
# => true
|
71
|
+
algorithm
|
72
|
+
# => #<Algorithmia::Algorithm:0x007fa008b02de0 @client=Algorithmia::Client, @endpoint="demo/hello", @query_options={:timeout=>500, :stdout=>true, :output=>"default"}>
|
73
|
+
|
74
|
+
# Pass the input to the algorithm
|
75
|
+
result = algorithm.pipe('HAL 9000')
|
76
|
+
# => Hello HAL 9000
|
77
|
+
```
|
78
|
+
|
79
|
+
### Algorithm Responses
|
80
|
+
|
81
|
+
When a successful response from the algorithm is returned, a new Algorithmia::Response object is created.
|
82
|
+
|
83
|
+
``` ruby
|
84
|
+
# Call an algorithm
|
85
|
+
algorithm_response = client.algo(algorithm).pipe("HAL 9000").result
|
86
|
+
puts algorithm_response
|
87
|
+
# => #<Algorithmia::Response:0x007f9fc2845850 @json={:result=>0.14970585904042558, :metadata=>{:content_type=>"json", :duration=>0.0006857780000000001}}>
|
88
|
+
|
89
|
+
# Get the raw json returned from the API
|
90
|
+
puts algorithm_response.json
|
91
|
+
# => {:result=>0.14970585904042558, :metadata=>{:content_type=>"json", :duration=>0.0006857780000000001}}
|
92
|
+
|
93
|
+
# Use any one of the following helper methods to understand the response
|
94
|
+
puts algorithm_response.result
|
95
|
+
# => 0.14970585904042558
|
96
|
+
puts algorithm_response.metadata
|
97
|
+
# => {:content_type=>"json", :duration=>0.0006857780000000001}
|
98
|
+
puts algorithm_response.duration
|
99
|
+
# => 0.0006857780000000001
|
100
|
+
puts algorithm_response.content_type
|
101
|
+
# => "json"
|
102
|
+
puts algorithm_response.stdout
|
103
|
+
# => nil
|
104
|
+
puts algorithm_response.alerts
|
105
|
+
# => nil
|
106
|
+
```
|
107
|
+
|
108
|
+
### The Data API
|
109
|
+
|
110
|
+
The client also allows you to work with the Algorithmia Data API. You can manage your files and directories using DataObjects. There are two types of DataObjects: `DataFile` and `DataDirectory`.
|
111
|
+
|
112
|
+
#### DataFiles
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
file = client.file('data://test_user/test/sample_file.txt')
|
116
|
+
=> #<Algorithmia::DataFile:0x007ffbaa8747d8 @client=#<Algorithmia::Client:0x007ffbab0fc798 @api_key="YOUR_API_KEY">, @data_uri="data://test_user/test/sample_file.txt", @url="/data/test_user/test/sample_file.txt">
|
117
|
+
|
118
|
+
file.put_file('/path/to/local/file/sample_file.txt')
|
119
|
+
# => true
|
120
|
+
|
121
|
+
file.exists?
|
122
|
+
# => true
|
123
|
+
|
124
|
+
# Write a string to the file. This will overwrite any existing content!
|
125
|
+
file.put("This is the contents of the file.")
|
126
|
+
# => true
|
127
|
+
|
128
|
+
# Get the file and write to a local file
|
129
|
+
file.get_file
|
130
|
+
# => #<File:/var/folders/yl/vv6ws5196cvb61xzwrg8l3vm0000gp/T/test.txt20160328-94761-i8cqxg>
|
131
|
+
|
132
|
+
file.get
|
133
|
+
# => "This is the contents of the file."
|
134
|
+
|
135
|
+
file.delete
|
136
|
+
# => true
|
137
|
+
```
|
138
|
+
|
139
|
+
#### DataDirectories
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
# Create a DataDirectory object
|
143
|
+
dir = client.dir('data://test_user/test')
|
144
|
+
# => #<Algorithmia::DataDirectory:0x007ffbab0fc748 @client=#<Algorithmia::Client:0x007ffbab0fc798 @api_key="YOUR_API_KEY">, @data_uri="data://test_user/test", @url="/data/test_user/test">
|
145
|
+
|
146
|
+
# Create a new directory
|
147
|
+
dir.create
|
148
|
+
# => true
|
149
|
+
|
150
|
+
dir.exists?
|
151
|
+
# => true
|
152
|
+
|
153
|
+
# Get a new DataDirectory object for the parent directory
|
154
|
+
dir.parent
|
155
|
+
# => #<Algorithmia::DataDirectory:0x007ffba924e148 @client=#<Algorithmia::Client:0x007ffbab0fc798 @api_key="YOUR_API_KEY">, @data_uri="data://test_user", @url="/data/test_user">
|
156
|
+
|
157
|
+
# Delete the directory
|
158
|
+
dir.delete
|
159
|
+
# => true
|
160
|
+
```
|
161
|
+
|
162
|
+
##### Working with directories:
|
163
|
+
|
164
|
+
You can iterate over all contents in a directory, only the sub-directories, or the files within the directory by using of the the `each` methods provided. If no block is given to the method, an enumerator will be returned:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
# Return an enumerator for all directory contents, each sub-directory, or each file in the directory
|
168
|
+
dir.each
|
169
|
+
dir.each_directory
|
170
|
+
dir.each_file
|
171
|
+
# => #<Enumerator: #<Algorithmia::DataDirectory:0x007ffba89bbcd8 @client=#<Algorithmia::Client:0x007ffbab0fc798 @api_key="YOUR_API_KEY">, @data_uri="data://test_user/test_two", @url="/data/test_user/test_two">:each>
|
172
|
+
|
173
|
+
# Iterate all directory contents, each sub-directory, or each file in the directory
|
174
|
+
dir.each { |item| block }
|
175
|
+
dir.each_directory { |dir| block }
|
176
|
+
dir.each_file { |file| block }
|
177
|
+
```
|
178
|
+
|
179
|
+
|
180
|
+
## Stuck? Need help?
|
181
|
+
|
182
|
+
Check out our guides, tutorials, and how-tos in the [Algorithmia Developer Center](http://developers.algorithmia.com) as well as finding more specifics in our [API documentation](http://docs.algorithmia.com).
|
183
|
+
|
184
|
+
## Development
|
185
|
+
|
186
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
187
|
+
|
188
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
189
|
+
|
190
|
+
## Contributing
|
191
|
+
|
192
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/algorithmiaio/algorithmia-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.
|
193
|
+
|
194
|
+
## Not Yet Implemented:
|
195
|
+
- Tests! :scream:
|
196
|
+
|
data/Rakefile
CHANGED
@@ -1,65 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# http://github.com/bih/algorithmia
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
4
3
|
|
5
|
-
#
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
7
|
|
7
|
-
|
8
|
-
require "rubygems"
|
9
|
-
|
10
|
-
def gem_available?(name)
|
11
|
-
Gem::Specification.find_by_name(name)
|
12
|
-
rescue Gem::LoadError
|
13
|
-
false
|
14
|
-
rescue
|
15
|
-
Gem.available?(name)
|
16
|
-
end
|
17
|
-
|
18
|
-
def build_gem
|
19
|
-
# Cleanup.
|
20
|
-
sh "sudo gem uninstall algorithmia" if gem_available?("algorithmia")
|
21
|
-
Dir['*.gem'].map{ |f| File.delete(f) } if Dir['*.gem'].any?
|
22
|
-
|
23
|
-
# Build the new gem.
|
24
|
-
sh "sudo gem build algorithmia.gemspec"
|
25
|
-
|
26
|
-
# Bundle all gems.
|
27
|
-
sh "bundle install"
|
28
|
-
|
29
|
-
# And install it locally!
|
30
|
-
spec = Gem::Specification::load("algorithmia.gemspec")
|
31
|
-
sh "sudo gem install ./algorithmia-#{spec.version}.gem"
|
32
|
-
end
|
33
|
-
|
34
|
-
def load_console
|
35
|
-
# Load the library.
|
36
|
-
require "algorithmia"
|
37
|
-
require "ripl"
|
38
|
-
|
39
|
-
# Loading the console.
|
40
|
-
puts ("-" * 5) + " Loading Algorithmia Console " + ("-" * 5)
|
41
|
-
|
42
|
-
require "ripl"
|
43
|
-
Ripl.start({ binding: binding })
|
44
|
-
end
|
45
|
-
|
46
|
-
# Rake stuff.
|
47
|
-
|
48
|
-
task :test do
|
49
|
-
$LOAD_PATH.unshift('lib', 'spec')
|
50
|
-
Dir.glob('./spec/**/*_spec.rb') { |f| require f }
|
51
|
-
end
|
52
|
-
|
53
|
-
task :console do
|
54
|
-
build_gem
|
55
|
-
load_console
|
56
|
-
end
|
57
|
-
|
58
|
-
task :deploy do
|
59
|
-
build_gem
|
60
|
-
|
61
|
-
spec = Gem::Specification::load("algorithmia.gemspec")
|
62
|
-
sh "gem push algorithmia-#{spec.version}.gem"
|
63
|
-
|
64
|
-
puts ("-" * 5) + " SUCCESS - Gem has been pushed live! " + ("-" * 5)
|
65
|
-
end
|
8
|
+
task :default => :spec
|
data/algorithmia.gemspec
CHANGED
@@ -1,30 +1,28 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# http://github.com/bih/algorithmia
|
6
|
-
|
7
|
-
$:.push File.expand_path("../lib", __FILE__)
|
8
|
-
require "algorithmia/version"
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'algorithmia/version'
|
9
5
|
|
10
6
|
Gem::Specification.new do |spec|
|
11
|
-
spec.name =
|
7
|
+
spec.name = "algorithmia"
|
12
8
|
spec.version = Algorithmia::VERSION
|
13
|
-
spec.
|
14
|
-
spec.
|
15
|
-
spec.
|
16
|
-
spec.
|
17
|
-
spec.
|
18
|
-
spec.
|
19
|
-
|
20
|
-
|
21
|
-
spec.
|
22
|
-
spec.
|
9
|
+
spec.authors = ["Algorithmia"]
|
10
|
+
spec.email = ["developer@algorithmia.com"]
|
11
|
+
spec.licenses = ["MIT"]
|
12
|
+
spec.summary = %q{A Ruby client for making API calls to Algorithmia}
|
13
|
+
spec.description = %q{This gem provides a friendly client interface to the Algorithmia API, allowing you to call any of the algorithms on the Algorithmia Marketplace.}
|
14
|
+
spec.homepage = "https://algorithmia.com/"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
19
|
spec.require_paths = ["lib"]
|
24
|
-
|
25
|
-
spec.
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 11.1"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
24
|
+
|
26
25
|
spec.add_dependency "json", "~> 1.8"
|
27
|
-
spec.add_dependency "httparty", "~> 0.13
|
26
|
+
spec.add_dependency "httparty", "~> 0.13"
|
28
27
|
|
29
|
-
|
30
|
-
end
|
28
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "algorithmia"
|
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
|