soothsayer 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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in soothsayer.gemspec
4
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,2 @@
1
+ # Soothsayer
2
+ Soothsayer is an easy Ruby client for Google's Prediction API. It is still very alpha and a proper README will be forthcoming.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ module Soothsayer
2
+ class HostedModel
3
+ class << self
4
+ def predict(hosted_model_name, params)
5
+ API.post("/hostedmodels/#{hosted_model_name}/predict", opts(params))
6
+ end
7
+
8
+ private
9
+ def opts(params=nil)
10
+ options = {
11
+ :headers => {
12
+ "Authorization" => "Bearer #{API.oauth_token}",
13
+ "Content-Type" => "application/json"
14
+ }
15
+ }
16
+ options[:body] = MultiJson.dump(params) unless params.nil?
17
+ options
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ module Soothsayer
2
+ class TrainedModel
3
+ class << self
4
+ def list
5
+ API.get("/trainedmodels/list", opts)
6
+ end
7
+
8
+ def get(model_id)
9
+ API.get("/trainedmodels/#{model_id}", opts)
10
+ end
11
+
12
+ def insert(params)
13
+ API.post("/trainedmodels", opts(params))
14
+ end
15
+
16
+ def update(model_id, params)
17
+ API.put("/trainedmodels/#{model_id}", opts(params))
18
+ end
19
+
20
+ def delete(model_id)
21
+ API.delete("/trainedmodels/#{model_id}", opts)
22
+ end
23
+
24
+ def predict(model_id, params)
25
+ API.post("/trainedmodels/#{model_id}/predict", opts(params))
26
+ end
27
+
28
+ def analyze(model_id)
29
+ API.get("/trainedmodels/#{id}/analyze", opts)
30
+ end
31
+
32
+ private
33
+ def opts(params=nil)
34
+ options = {
35
+ :headers => {
36
+ "Authorization" => "Bearer #{API.oauth_token}",
37
+ "Content-Type" => "application/json"
38
+ }
39
+ }
40
+ options[:body] = MultiJson.dump(params) unless params.nil?
41
+ options
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Soothsayer
2
+ VERSION = "0.0.1"
3
+ end
data/lib/soothsayer.rb ADDED
@@ -0,0 +1,46 @@
1
+ require "soothsayer/version"
2
+ require "soothsayer/hosted_model"
3
+ require "soothsayer/trained_model"
4
+ require 'httparty'
5
+ require 'google/api_client'
6
+ require 'multi_json'
7
+
8
+ module Soothsayer
9
+ class OAuthTokenError < StandardError; end
10
+ class API
11
+ include HTTParty
12
+ format :json
13
+ base_uri 'https://www.googleapis.com/prediction/v1.5'
14
+
15
+ class << self
16
+ attr_accessor :api_client
17
+
18
+ def oauth_token
19
+ if api_client.nil?
20
+ create_client
21
+ api_client.authorization.fetch_access_token!
22
+ elsif api_client.authorization.expired?
23
+ api_client.authorization.fetch_access_token!
24
+ end
25
+ api_client.authorization.access_token
26
+ end
27
+
28
+ def create_client
29
+ config_file = File.expand_path('~/.google-api.yaml')
30
+ config = open(config_file, 'r'){ |file| YAML.load(file.read) }
31
+ client = Google::APIClient.new(:authorization => :oauth_2)
32
+ unless client.authorization.nil?
33
+ client.authorization.scope = nil
34
+ client.authorization.client_id = config["client_id"]
35
+ client.authorization.client_secret = config["client_secret"]
36
+ client.authorization.access_token = config["access_token"]
37
+ client.authorization.refresh_token = config["refresh_token"]
38
+ client.register_discovery_uri('discovery', 'v1.5', nil)
39
+ self.api_client = client
40
+ else
41
+ raise OAuthTokenError
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "soothsayer/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "soothsayer"
7
+ s.version = Soothsayer::VERSION
8
+ s.authors = ["Marc Love"]
9
+ s.email = ["marcslove@gmail.com"]
10
+ s.homepage = "http://github.com/marclove/soothsayer"
11
+ s.summary = %q{A Ruby client for Google's Prediction API}
12
+ s.description = %q{A Ruby client for Google's Prediction API}
13
+
14
+ s.rubyforge_project = "soothsayer"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "httparty"
24
+ s.add_runtime_dependency "google-api-client"
25
+ s.add_runtime_dependency "multi_json"
26
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soothsayer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Marc Love
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-04-20 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: google-api-client
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: multi_json
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ description: A Ruby client for Google's Prediction API
49
+ email:
50
+ - marcslove@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - README.markdown
61
+ - Rakefile
62
+ - lib/soothsayer.rb
63
+ - lib/soothsayer/hosted_model.rb
64
+ - lib/soothsayer/trained_model.rb
65
+ - lib/soothsayer/version.rb
66
+ - soothsayer.gemspec
67
+ homepage: http://github.com/marclove/soothsayer
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project: soothsayer
90
+ rubygems_version: 1.8.16
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: A Ruby client for Google's Prediction API
94
+ test_files: []
95
+