fickle-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Norbert Crombach
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Fickle: Ruby
2
+
3
+ Experimental machine learning REST API client.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.pattern = 'test/*_test.rb'
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "fickle-ruby"
3
+ s.version = "0.0.1"
4
+ s.platform = Gem::Platform::RUBY
5
+ s.authors = ["Norbert Crombach"]
6
+ s.email = ["norbert.crombach@primetheory.org"]
7
+ s.homepage = "http://github.com/norbert/fickle-ruby"
8
+ s.summary = %q{Experimental machine learning REST API client.}
9
+
10
+ s.rubyforge_project = "fickle-ruby"
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = s.files.grep(/^test\//)
14
+ s.require_paths = ["lib"]
15
+
16
+ s.add_dependency 'faraday'
17
+ s.add_dependency 'multi_json'
18
+ s.add_development_dependency 'rake'
19
+ end
@@ -0,0 +1,3 @@
1
+ module Fickle
2
+ VERSION = "0.0.1"
3
+ end
data/lib/fickle.rb ADDED
@@ -0,0 +1,77 @@
1
+ require 'faraday'
2
+ require 'multi_json'
3
+
4
+ module Fickle
5
+ class Client
6
+ USERNAME = 'fickle'
7
+ MIME_TYPE = 'application/json'
8
+
9
+ attr_reader :host, :password
10
+
11
+ def initialize(host, password = nil)
12
+ @host = host
13
+ @password = password
14
+ end
15
+
16
+ def self.connection(url, password = nil)
17
+ Faraday.new(url) do |builder|
18
+ if !password.nil?
19
+ builder.use Faraday::Request::BasicAuthentication, USERNAME, password
20
+ end
21
+
22
+ builder.headers['Content-Type'] = MIME_TYPE
23
+ builder.use Faraday::Response::RaiseError
24
+
25
+ builder.adapter Faraday.default_adapter
26
+ end
27
+ end
28
+
29
+ def connection
30
+ @connection ||= self.class.connection(host, password)
31
+ end
32
+
33
+ def load(dataset)
34
+ post('/load', encode(dataset))
35
+ true
36
+ end
37
+
38
+ def fit
39
+ post('/fit')
40
+ true
41
+ end
42
+
43
+ def validate
44
+ response = post('/validate')
45
+ decode(response)
46
+ end
47
+
48
+ def predict(samples, probabilities = false)
49
+ path = '/predict'
50
+ path += '/probabilities' if probabilities
51
+
52
+ response = post(path, encode(samples))
53
+ decode(response)
54
+ end
55
+
56
+ def recommend(keys, n = nil)
57
+ response = connection.post('/recommend') do |req|
58
+ req.params['n'] = Integer(n) if n
59
+ req.body = encode(keys)
60
+ end
61
+ decode(response)
62
+ end
63
+
64
+ private
65
+ def post(url, body = nil)
66
+ connection.post(url, body)
67
+ end
68
+
69
+ def encode(body)
70
+ MultiJson.encode(body)
71
+ end
72
+
73
+ def decode(response)
74
+ MultiJson.decode(response.body)
75
+ end
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fickle-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Norbert Crombach
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: multi_json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description:
63
+ email:
64
+ - norbert.crombach@primetheory.org
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .travis.yml
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - fickle-ruby.gemspec
76
+ - lib/fickle.rb
77
+ - lib/fickle/version.rb
78
+ homepage: http://github.com/norbert/fickle-ruby
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ segments:
91
+ - 0
92
+ hash: -2117253940617438175
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: -2117253940617438175
102
+ requirements: []
103
+ rubyforge_project: fickle-ruby
104
+ rubygems_version: 1.8.23
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Experimental machine learning REST API client.
108
+ test_files: []