yhat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/README.md +3 -0
  4. data/lib/yhat.rb +40 -0
  5. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ad2e33ec34dffa5ade5fa482f4ac2b3f14b02ac
4
+ data.tar.gz: 8b107801f165a5722dcb8a15f0793bda8e9a9473
5
+ SHA512:
6
+ metadata.gz: c439e42d563948728b30ee1110ef4f0b525062f2efb92ca7dcd3ac1a41a8fbe82a4cc948630aade07a3615004edda0fb80b9cb5e0d7c73063233609e48587165
7
+ data.tar.gz: 7c1fe108b614df6d63c71123990eb79269bd1b726a713f9121b218a61facb9b719a73d5584333a57790c7237ae91eead16e07e82c7352da5def1b66246580989
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gem "json"
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # yhat-ruby
2
+ A ruby wrapper for the Yhat API.
3
+
data/lib/yhat.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+
4
+
5
+ class Yhat
6
+ # Class that can be used to access the Yhat API
7
+
8
+ def initialize(username, apikey, uri = 'api.yhathq.com')
9
+ @username = username
10
+ @apikey = apikey
11
+ @base_uri = uri
12
+
13
+ if @base_uri == 'api.yhathq.com'
14
+ @is_enterprise = false
15
+ else
16
+ @is_enterprise = true
17
+ end
18
+
19
+ end
20
+
21
+ # Make a prediction by calling Yhat via HTTP. You should pass both
22
+ # the name of the model you want to use to make a prediction as well
23
+ # as a JSON object (or a Hash) that contains the data requried to
24
+ # make a prediction.
25
+ #
26
+ # @param modelname [String]
27
+ # @param data [Hash]
28
+ # @return [Hash]
29
+ def predict(modelname, data)
30
+ uri = URI.parse(@base_uri)
31
+ http = Net::HTTP.new(uri.host, uri.port)
32
+ request = Net::HTTP::Post.new("/models/" + modelname + "/")
33
+ request.add_field('Content-Type', 'application/json')
34
+ request.body = data
35
+ response = http.request(request)
36
+ data = response.body
37
+ JSON.parse(data)
38
+ end
39
+ end
40
+
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yhat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Greg Lamp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A ruby wrapper for the Yhat API.
14
+ email:
15
+ - greg@yhathq.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - README.md
22
+ - lib/yhat.rb
23
+ homepage: http://github.com/yhat/yhat-ruby
24
+ licenses:
25
+ - BSD
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.0.6
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Call models from the Yhat API.
47
+ test_files: []