algorithmia 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e447a94758db3ef21b6c33d5bc51a91fd2ea8fa9
4
+ data.tar.gz: bc2751c57b973ebe204b23581b9faebf370dd496
5
+ SHA512:
6
+ metadata.gz: fa48bb6e91d94bd0074385bf18ad1d40f90370232e8efc38f3f18bc0e3fbd11fdf8f411707ab95c8aaa0f1123f06d669d39c6f2c5a9630f56250a61b04648159
7
+ data.tar.gz: aace9f5700afb51664469bd848ca1b03675eece28440b330d5a5b4dc0a0b49bfacc0ffaa84c2cd80753959f20944f107392f4fbb65d66011847bc1a4d6135ede
@@ -0,0 +1 @@
1
+ Gemfile.lock
@@ -0,0 +1 @@
1
+ 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ ruby "2.2.0"
2
+ source "https://rubygems.org"
3
+
4
+ gem "httparty", "~> 0.13.1"
5
+ gem "ripl", "~> 0.7"
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright © 2014 Bilawal Hameed <me@bilaw.al>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # Algorithmia Ruby wrapper.
2
+ # Released under the MIT License
3
+ # http://github.com/bih/algorithmia
4
+
5
+ # Old dependency stuff.
6
+
7
+ $:.push File.expand_path("../lib", __FILE__)
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
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ # Algorithmia Ruby wrapper.
4
+ # Released under the MIT License
5
+ # http://github.com/bih/algorithmia
6
+
7
+ $:.push File.expand_path("../lib", __FILE__)
8
+ require "algorithmia/version"
9
+
10
+ Gem::Specification.new do |spec|
11
+ spec.name = 'algorithmia'
12
+ spec.version = Algorithmia::VERSION
13
+ spec.required_ruby_version = '>= 2.0.0'
14
+ spec.license = 'MIT'
15
+ spec.summary = "Ruby library for interacting with Algorithmia.com"
16
+ spec.description = "Interact with awesome algorithms created by academics through Algorithmia.com through Ruby."
17
+ spec.authors = ["Bilawal Hameed"]
18
+ spec.email = 'bilawal@studenthack.com'
19
+ spec.homepage = 'http://github.com/bih/algorithmia'
20
+
21
+ spec.files = `git ls-files`.split("\n").select{ |f| f[-4..-1] != ".gem" }
22
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "rake", "~> 10.4"
26
+ spec.add_dependency "json", "~> 1.8"
27
+ spec.add_dependency "httparty", "~> 0.13.1"
28
+
29
+ spec.add_development_dependency "ripl", "~> 0.7"
30
+ end
Binary file
@@ -0,0 +1,18 @@
1
+ # Algorithmia Ruby wrapper.
2
+ # Released under the MIT License
3
+ # http://github.com/bih/algorithmia
4
+
5
+ $:.push File.expand_path("../lib", __FILE__)
6
+
7
+ require 'algorithmia/base'
8
+ require 'algorithmia/version'
9
+ require 'algorithmia/errors'
10
+ require 'algorithmia/authentication'
11
+ require 'algorithmia/result'
12
+ require 'algorithmia/http'
13
+
14
+ class Algorithmia
15
+ def self.call(endpoint, input)
16
+ post_http("/api/#{endpoint}", input)
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ # Algorithmia Ruby wrapper.
2
+ # Released under the MIT License
3
+ # http://github.com/bih/algorithmia
4
+
5
+ class Algorithmia
6
+ attr_writer :api_key
7
+
8
+ # Authentication stuffs.
9
+ def self.api_key
10
+ @api_key
11
+ end
12
+
13
+ def self.api_key?
14
+ not @api_key.nil?
15
+ end
16
+
17
+ def self.api_key=(api_key)
18
+ if not api_key.is_a?(String) or api_key.to_s.empty?
19
+ raise AlgorithmiaApiKeyTooShort.new("Invalid Algorithmia API key")
20
+ end
21
+
22
+ @api_key = api_key
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ # Algorithmia Ruby wrapper.
2
+ # Released under the MIT License
3
+ # http://github.com/bih/algorithmia
4
+
5
+ require 'singleton'
6
+ require 'httparty'
7
+
8
+ class Algorithmia
9
+ include Singleton
10
+ include HTTParty
11
+
12
+ base_uri "https://api.algorithmia.com"
13
+ format :json
14
+ end
@@ -0,0 +1,6 @@
1
+ # Algorithmia Ruby wrapper.
2
+ # Released under the MIT License
3
+ # http://github.com/bih/algorithmia
4
+
5
+ class AlgorithmiaException < Exception; end
6
+ class AlgorithmiaApiKeyTooShort < Exception; end
@@ -0,0 +1,33 @@
1
+ # Algorithmia Ruby wrapper.
2
+ # Released under the MIT License
3
+ # http://github.com/bih/algorithmia
4
+
5
+ class Algorithmia
6
+ private
7
+
8
+ def self.post_http(endpoint, params = {})
9
+ params = params.to_s unless params.is_a?(Hash)
10
+ parse_output post(endpoint, body: params, headers: { "Authorization" => @api_key, "Accept" => "application/json" })
11
+ end
12
+
13
+ def self.get_http(endpoint, params = {})
14
+ params = params.to_s unless params.is_a?(Hash)
15
+ parse_output get(endpoint, query: params, headers: { "Authorization" => @api_key, "Accept" => "application/json" })
16
+ end
17
+
18
+ def self.parse_output(res)
19
+ result = res.parsed_response
20
+
21
+ # Error!
22
+ raise AlgorithmiaException.new(result[:error]) if result.include?(:error)
23
+
24
+ # Result!
25
+ Algorithmia::Result.new(result)
26
+ rescue NoMethodError => e
27
+ raise AlgorithmiaException.new(res.parsed_response)
28
+ rescue JSON::ParserError => e
29
+ raise AlgorithmiaException.new(e)
30
+ rescue Exception => e
31
+ raise AlgorithmiaException.new(e)
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ # Algorithmia Ruby wrapper.
2
+ # Released under the MIT License
3
+ # http://github.com/bih/algorithmia
4
+
5
+ class Algorithmia::Result
6
+ def initialize(hash)
7
+ @json = clean_output(hash) rescue {}
8
+ end
9
+
10
+ def duration
11
+ @json[:duration] rescue -1
12
+ end
13
+
14
+ def result
15
+ @json[:result] rescue nil
16
+ end
17
+
18
+ private
19
+
20
+ def clean_output(hash_without_symbols)
21
+ hash_with_symbols = Hash.new
22
+ hash_without_symbols.each { |k, v| hash_with_symbols[k.to_sym] = v } if hash_without_symbols.is_a?(Hash)
23
+ hash_with_symbols
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ # Algorithmia Ruby wrapper.
2
+ # Released under the MIT License
3
+ # http://github.com/bih/algorithmia
4
+
5
+ class Algorithmia
6
+ VERSION = "0.1.0"
7
+ end
@@ -0,0 +1,37 @@
1
+ ![Algorithmia for Ruby](algorithmia.png)
2
+
3
+ # Ruby Wrapper for Algorithmia
4
+
5
+ Looks very interesting, so I quickly threw together an awesome Ruby wrapper to interact with [Algorithmia.com](http://algorithmia.com).
6
+
7
+ ### Installation
8
+
9
+ ```
10
+ # By your command line.
11
+ $ gem install algorithmia
12
+
13
+ # Alternatively, through your Gemfile.
14
+ gem 'algorithmia'
15
+ ```
16
+
17
+ ### Documentation
18
+ Keeping it simple for now. But it's super easy to make a request to Algorithmia:
19
+
20
+ ```ruby
21
+ require "algorithmia"
22
+
23
+ # Your API key. Get it from your dashboard on Algorithmia.com
24
+ Algorithmia.api_key = "[INSERT API KEY]"
25
+
26
+ query = Algorithmia.call("kenny/Factor", 29)
27
+ # Example for algorithm: https://algorithmia.com/algorithms/kenny/Factor
28
+ # => #<Algorithmia::Result:0x007fad12c4fc68 @json={:duration=>0.035231213000000004, :result=>[29]}>
29
+
30
+ query.result # => [29]
31
+ query.duration # => 0.035231213000000004
32
+ ```
33
+
34
+ See full [Algorithmia.com API docs by clicking here](https://algorithmia.com/docs/api#curl).
35
+
36
+ ### Who made this?
37
+ [Bilawal Hameed](http://github.com/bih). Released freely under the [MIT License](http://bih.mit-license.org/).
@@ -0,0 +1,17 @@
1
+ # Algorithmia Ruby wrapper.
2
+ # Released under the MIT License
3
+ # http://github.com/bih/algorithmia
4
+
5
+ # Required according to the command-line tool.
6
+ gem 'minitest'
7
+
8
+ # Load in the test.
9
+ require 'minitest/autorun'
10
+ require 'minitest/spec'
11
+
12
+ # And the source of Algorithmia, of course.
13
+ FileList['lib/**/*.rb'].each{ |source| load(source) }
14
+
15
+ class AlgorithmiaRubyTest < Minitest::Test
16
+ # TODO: Some tests.
17
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: algorithmia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bilawal Hameed
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: ripl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ description: Interact with awesome algorithms created by academics through Algorithmia.com
70
+ through Ruby.
71
+ email: bilawal@studenthack.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".ruby-version"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - Rakefile
81
+ - algorithmia.gemspec
82
+ - algorithmia.png
83
+ - lib/algorithmia.rb
84
+ - lib/algorithmia/authentication.rb
85
+ - lib/algorithmia/base.rb
86
+ - lib/algorithmia/errors.rb
87
+ - lib/algorithmia/http.rb
88
+ - lib/algorithmia/result.rb
89
+ - lib/algorithmia/version.rb
90
+ - readme.markdown
91
+ - spec/algorithmia_spec.rb
92
+ homepage: http://github.com/bih/algorithmia
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 2.0.0
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.5
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Ruby library for interacting with Algorithmia.com
116
+ test_files:
117
+ - spec/algorithmia_spec.rb