soothsayer 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -1,2 +1,30 @@
1
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.
2
+ Soothsayer is a thin Ruby wrapper around Google's Prediction API.
3
+
4
+ ## Setup
5
+ Go to [Google's API Console](http://code.google.com/apis/console). Sign up and turn on both the "Google Cloud Storage" and "Prediction API" services. Before you can use the Prediction API, you'll have to turn on billing.
6
+
7
+ Go to "API Access" section of the Google API Console and create an "Authorized API Access" key, "Client ID for installed applications." You'll need the "Client ID" and "Client secret."
8
+
9
+ Download Google's Ruby API client gem:
10
+ gem install google-api-client
11
+
12
+ Now you need to download your OAuth keys
13
+ google-api oauth-2-login --scope=https://www.googleapis.com/auth/prediction --client-id=<< YOUR CLIENT ID >> --client-secret=<< YOUR CLIENT SECRET >>
14
+
15
+ This will create a file at <code>~/.google-api.yaml</code> which contains your OAuth keys. Move this file into your project and use it to configure Soothsayer:
16
+ config_file = File.expand_path('path/to/google-api.yaml')
17
+ config = open(config_file, 'r'){ |file| YAML.load(file.read) }
18
+ Soothsayer.config do |c|
19
+ c.client_id = config.client_id
20
+ c.client_secret = config.client_secret
21
+ c.access_token = config.access_token
22
+ c.refresh_token = config.refresh_token
23
+ end
24
+
25
+ ## Usage
26
+ To use Soothsayer, refer to [Google's documentation](https://developers.google.com/prediction/docs/reference/v1.5/reference).
27
+
28
+ Soothsayer::HostedModel.predict("sample.languageid", {:input => {:csvInstance => ["Como se llama?"]}})
29
+ Soothsayer::TrainedModel.list
30
+ Soothsayer::TrainedModel.update("my.trained.model.name", {:label => "my_label", :csvInstance => [col1, col2, col3]})
@@ -1,3 +1,3 @@
1
1
  module Soothsayer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/soothsayer.rb CHANGED
@@ -6,6 +6,30 @@ require 'google/api_client'
6
6
  require 'multi_json'
7
7
 
8
8
  module Soothsayer
9
+ def self.credentials
10
+ @@config
11
+ end
12
+
13
+ # Configures Soothsayer with the credentials downloaded by the Ruby api client into .google-api.yaml
14
+ #
15
+ # config_file = File.expand_path('~/.google-api.yaml')
16
+ # config = open(config_file, 'r'){ |file| YAML.load(file.read) }
17
+ # Soothsayer.config do |c|
18
+ # c.client_id = config.client_id
19
+ # c.client_secret = config.client_secret
20
+ # c.access_token = config.access_token
21
+ # c.refresh_token = config.refresh_token
22
+ # end
23
+ #
24
+ def self.config(config = Configuration.new)
25
+ yield config
26
+ @@config = config
27
+ end
28
+
29
+ class Configuration
30
+ attr_accessor :client_id, :client_secret, :access_token, :refresh_token
31
+ end
32
+
9
33
  class OAuthTokenError < StandardError; end
10
34
  class API
11
35
  include HTTParty
@@ -26,15 +50,14 @@ module Soothsayer
26
50
  end
27
51
 
28
52
  def create_client
29
- config_file = File.expand_path('~/.google-api.yaml')
30
- config = open(config_file, 'r'){ |file| YAML.load(file.read) }
53
+ raise OAuthTokenError, 'Please configure Soothsayer first with Soothsayer.config.' if Soothsayer.credentials.nil?
31
54
  client = Google::APIClient.new(:authorization => :oauth_2)
32
55
  unless client.authorization.nil?
33
56
  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"]
57
+ client.authorization.client_id = Soothsayer.credentials.client_id
58
+ client.authorization.client_secret = Soothsayer.credentials.client_secret
59
+ client.authorization.access_token = Soothsayer.credentials.access_token
60
+ client.authorization.refresh_token = Soothsayer.credentials.refresh_token
38
61
  client.register_discovery_uri('discovery', 'v1.5', nil)
39
62
  self.api_client = client
40
63
  else
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: soothsayer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Marc Love