mindmatch 0.0.1.pre.beta → 0.0.1.pre.beta2

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: a09df61006a852532db079fa7d5ce3615e3d537e
4
- data.tar.gz: 6b57d2c5dcec3ac65b018aacf87a6ba00ff11f60
3
+ metadata.gz: 510b993b376f44566ac27c884bd6bf84ce0f90fb
4
+ data.tar.gz: 005357f6ac53c683862e04f9c7c2099e0f8ce14a
5
5
  SHA512:
6
- metadata.gz: d7b3b78e243129cc409b51f1b1a6f68ca9d8fd2794ccb320f81abbfa9e7cc325aefa5d15149f2db0c5c5f5eb485b3f195cef880d2f4e0682eef6748d2b4a2945
7
- data.tar.gz: 8a963298365251bdafdad42386debb2b0d75d1c9d4278b06a7d20d37f0259967a141f68ae8b7d8f820ae98fc8cf9de598e05eb0d95413b70204266052b05ff6d
6
+ metadata.gz: 5134b594b3dc800fbd59f1732c2714c1e019f04cafcd4042a1d600a9fa1b9db5c91b9b8c0ca0f2a7e7c7b53bf2db6890a907846f9820efe052dc821ca73eaedc
7
+ data.tar.gz: 6b080267bbe523da2aefbfae20d3230c33657404ea63c61bac626c747678788a7de77649af8c662c7061dd1020036036110d00b38a4412f1716d44b22372af34
@@ -2,6 +2,10 @@ require 'faraday'
2
2
  require 'json'
3
3
 
4
4
  module MindMatch
5
+ class ArgumentError < StandardError; end
6
+ class Unauthorized < StandardError; end
7
+ class UnexpectedError < StandardError; end
8
+
5
9
  class Client
6
10
 
7
11
  DEFAULT_ENDPOINT = 'https://api.mindmatch.ai'
@@ -52,6 +56,7 @@ module MindMatch
52
56
  raw_response = conn.get do |req|
53
57
  req.body = JSON.generate(query: query_match_score)
54
58
  end
59
+ handle_error(raw_response)
55
60
  response = JSON.parse(raw_response.body)
56
61
  match = response.dig('data', 'match')
57
62
  match = match['data'] if match.has_key?('data') # FIX: remove data namespece in mindmatch api
@@ -80,6 +85,7 @@ module MindMatch
80
85
  raw_response = conn.post do |req|
81
86
  req.body = JSON.generate(query: create_match_mutation)
82
87
  end
88
+ handle_error(raw_response)
83
89
  response = JSON.parse(raw_response.body)
84
90
  response['data']['match']['id']
85
91
  end
@@ -139,5 +145,15 @@ module MindMatch
139
145
  "Content-Type": "application/json"
140
146
  }
141
147
  end
148
+
149
+ def handle_error(raw_response)
150
+ return if raw_response.status.to_s =~ /2\d\d/
151
+
152
+ case raw_response.status
153
+ when 400 then raise(ArgumentError, raw_response.body)
154
+ when 401 then raise(Unauthorized, raw_response.body)
155
+ else raise(UnexpectedError, raw_response.status, raw_response.body)
156
+ end
157
+ end
142
158
  end
143
159
  end
@@ -1,3 +1,3 @@
1
1
  module MindMatch
2
- VERSION = "0.0.1-beta"
2
+ VERSION = "0.0.1-beta2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mindmatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre.beta
4
+ version: 0.0.1.pre.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - MindMatch
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-09-25 00:00:00.000000000 Z
13
+ date: 2017-09-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday