metamind 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93321e0e8cc66e787becb646044e8f6feb980e96
4
- data.tar.gz: cd6a25ee266841d9f5132181f2a5d4d09d18732d
3
+ metadata.gz: 113d397a3f431904e5738c7f2916c3a4e4f12d78
4
+ data.tar.gz: 49ddef63be4ca38b03e3b08fd47967796df5f8aa
5
5
  SHA512:
6
- metadata.gz: 64a72f0091c838a5d4384f2f0e5e47d68e88d5dfd1b0b8fa80bd6c6272b451f2e41f174e0511167ebd0daf2a90d3698f7aa4fe2ab8ed48918153c06c237de1f7
7
- data.tar.gz: c80665ee5af9a3b9f7286b1baee9eacf512dab1ed81acc100fb2c821fbc9adbc78347edeec0c74b865700c420701d8f8c64debe465d2b758c8a56e0972aa52fc
6
+ metadata.gz: 4f8f70a6fa404479391c846269cfc9ab729a94c210aa08f31e75a7682f95c74553dd11ad623ac1fbef98f7f79f9887d49f13bcd02f27c795d05f38f5b43668a9
7
+ data.tar.gz: 05186f35779bc100c764407353fc94e773867899bbb247b80686e23c498938d21598c939bb9e4cd63a3aa40b8d46230c8484b77580ff65ee96c16863a12d8539
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Metamind
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/metamind`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://travis-ci.org/tzmfreedom/metamind-ruby.svg?branch=master)](https://travis-ci.org/tzmfreedom/metamind-ruby)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ API Client for Salesforce MetaMind(http://metamind.io)
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,7 +22,98 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ - Initialize Client
26
+ ```ruby
27
+ client = Metamind::Client.new(cert: '/path/to/certificate',
28
+ password: 'certificate password',
29
+ email: 'metamind account email')
30
+ ```
31
+ or
32
+ ```ruby
33
+ client = Metamind::Client.new(private_key: '/path/to/private_key',
34
+ password: 'private_key password',
35
+ email: 'metamind account email')
36
+ ```
37
+
38
+ - Prediction with Image URL
39
+ ```ruby
40
+ client.predict_with_url 'url', 'modelId'
41
+ ```
42
+
43
+ - Prediction with Image Base64 String
44
+ ```ruby
45
+ client.predict_with_base64 'base64 string', 'modelId'
46
+ ```
47
+
48
+ - Create a Dataset
49
+ ```ruby
50
+ client.create_dataset 'name', 'labels'
51
+ ```
52
+
53
+ - Get a Dataset
54
+ ```ruby
55
+ client.get_dataset 'dataset_id'
56
+ ```
57
+
58
+ - Get All Datasets
59
+ ```ruby
60
+ client.get_all_datasets
61
+ ```
62
+
63
+ - Delete a Dataset
64
+ ```ruby
65
+ client.delete_dataset 'dataset_id'
66
+ ```
67
+
68
+ - Create a Label
69
+ ```ruby
70
+ client.create_label 'dataset_id', 'name'
71
+ ```
72
+
73
+ - Get a Label
74
+ ```ruby
75
+ client.get_label 'dataset_id', 'label_id'
76
+ ```
77
+
78
+ - Create an Example
79
+ ```ruby
80
+ client.create_example 'dataset_id', params
81
+ ```
82
+
83
+ - Get an Example
84
+ ```ruby
85
+ client.get_example 'dataset_id', 'example_id'
86
+ ```
87
+
88
+ - Get All Examples
89
+ ```ruby
90
+ client.get_all_example 'dataset_id'
91
+ ```
92
+
93
+ - Delete an Example
94
+ ```ruby
95
+ client.delete_example 'dataset_id', 'example_id'
96
+ ```
97
+
98
+ - Train a Dataset
99
+ ```ruby
100
+ client.train_dataset params
101
+ ```
102
+
103
+ - Get Training Status
104
+ ```ruby
105
+ client.get_training_status 'model_id'
106
+ ```
107
+
108
+ - Get Model Metrics
109
+ ```ruby
110
+ client.get_model_metrics 'model_id'
111
+ ```
112
+
113
+ - Get All Models
114
+ ```ruby
115
+ client.get_all_models 'dataset_id'
116
+ ```
26
117
 
27
118
  ## Development
28
119
 
@@ -32,7 +123,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
123
 
33
124
  ## Contributing
34
125
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/metamind.
126
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tzmfreedom/metamind.
36
127
 
37
128
 
38
129
  ## License
@@ -3,14 +3,16 @@ require 'jwt'
3
3
  require 'net/https'
4
4
  require 'securerandom'
5
5
 
6
-
7
6
  module Metamind
8
7
  CRLF = "\r\n"
9
-
10
8
  METAMIND_VISION_API = 'https://api.metamind.io/v1/vision'
11
9
 
12
10
  class Client
13
- def initialize cert: nil, private_key: nil, password: nil, email: nil
11
+ def initialize cert: nil, private_key: nil, password: nil, email:
12
+ if cert.nil? && private_key.nil?
13
+ raise ArgumentError.new 'At least one parameter must be specified: cert or private_key'
14
+ end
15
+
14
16
  if !cert.nil?
15
17
  pkcs12 = OpenSSL::PKCS12::new(File.read(cert), password)
16
18
  @private_key = pkcs12.key
@@ -19,41 +21,22 @@ module Metamind
19
21
  end
20
22
  @email = email
21
23
  @boundary = SecureRandom.hex(10)
22
-
23
- jwt = JWT.encode({
24
- iss: 'developer.force.com',
25
- sub: @email,
26
- aud: 'https://api.metamind.io/v1/oauth2/token',
27
- iat: Time.now.to_i,
28
- exp: Time.now.to_i + 3600
29
- }, @private_key, 'RS256')
30
-
31
- uri = URI.parse('https://api.metamind.io/v1/oauth2/token')
32
- http = Net::HTTP.new(uri.host, uri.port)
33
-
34
- http.use_ssl = true
35
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
36
-
37
- req = Net::HTTP::Post.new(uri.path)
38
- req.set_form_data({grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer', assertion: jwt})
39
-
40
- res = http.request(req)
41
- @access_token = JSON.parse(res.body)['access_token']
42
24
  end
43
25
 
44
26
  def access_token
27
+ get_access_token if @access_token.nil?
45
28
  @access_token
46
29
  end
47
30
 
48
- def predict_by_url url, modelId = 'GeneralImageClassifier'
31
+ def predict_with_url url, modelId = 'GeneralImageClassifier'
49
32
  post "/predict", {sampleLocation: url, modelId: modelId}
50
33
  end
51
34
 
52
- def predict_by_file path, modelId = 'GeneralImageClassifier'
53
- post "#{METAMIND_VISION_API}/predict", {sampleContent: path, modelId: modelId}
54
- end
35
+ # def predict_with_file path, modelId = 'GeneralImageClassifier'
36
+ # post "#{METAMIND_VISION_API}/predict", {sampleContent: path, modelId: modelId}
37
+ # end
55
38
 
56
- def predict_by_base64 base64_string, modelId = 'GeneralImageClassifier'
39
+ def predict_with_base64 base64_string, modelId = 'GeneralImageClassifier'
57
40
  post "#{METAMIND_VISION_API}/predict", {sampleBase64Content: base64_string, modelId: modelId}
58
41
  end
59
42
 
@@ -124,7 +107,7 @@ module Metamind
124
107
 
125
108
  req = Net::HTTP::Get.new(uri.path)
126
109
  req['Accept-Encoding'] = 'identity'
127
- req['Authorization'] = "Bearer #{@access_token}"
110
+ req['Authorization'] = "Bearer #{access_token}"
128
111
 
129
112
  res = http.request(req)
130
113
  JSON.parse(res.body)
@@ -139,7 +122,7 @@ module Metamind
139
122
 
140
123
  req = Net::HTTP::Post.new(uri.path)
141
124
  req['Content-Type'] = "multipart/form-data; boundary=#{@boundary}"
142
- req['Authorization'] = "Bearer #{@access_token}"
125
+ req['Authorization'] = "Bearer #{access_token}"
143
126
  req.body = build_multipart_query(params)
144
127
 
145
128
  res = http.request(req)
@@ -154,7 +137,7 @@ module Metamind
154
137
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
155
138
 
156
139
  req = Net::HTTP::Delete.new(uri.path)
157
- req['Authorization'] = "Bearer #{@access_token}"
140
+ req['Authorization'] = "Bearer #{access_token}"
158
141
 
159
142
  res = http.request(req)
160
143
  JSON.parse(res.body)
@@ -181,5 +164,27 @@ module Metamind
181
164
  end
182
165
  parts.join(CRLF) + "#{CRLF}--#{@boundary}--"
183
166
  end
167
+
168
+ def get_access_token
169
+ jwt = JWT.encode({
170
+ iss: 'developer.force.com',
171
+ sub: @email,
172
+ aud: 'https://api.metamind.io/v1/oauth2/token',
173
+ iat: Time.now.to_i,
174
+ exp: Time.now.to_i + 3600
175
+ }, @private_key, 'RS256')
176
+
177
+ uri = URI.parse('https://api.metamind.io/v1/oauth2/token')
178
+ http = Net::HTTP.new(uri.host, uri.port)
179
+
180
+ http.use_ssl = true
181
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
182
+
183
+ req = Net::HTTP::Post.new(uri.path)
184
+ req.set_form_data({grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer', assertion: jwt})
185
+
186
+ res = http.request(req)
187
+ @access_token = JSON.parse(res.body)['access_token']
188
+ end
184
189
  end
185
190
  end
@@ -1,3 +1,3 @@
1
1
  module Metamind
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metamind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tzmfreedom
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-10 00:00:00.000000000 Z
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt