workable 1.0.0.rc1 → 1.0.0.rc2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a09a961ce4873bd3a9f5d5ca68f74a7332af0c71
4
- data.tar.gz: 613aae7f8c29374abcb0fd1b6dfb1043d4dfdeec
3
+ metadata.gz: ada51e56baba92f9000eef95141cf2398a1e928f
4
+ data.tar.gz: c3d58edf13520d31ea1f318c28757301b986db89
5
5
  SHA512:
6
- metadata.gz: 58fff5454c71ac7eaed87a20f34273d66a5ba86050686c8c28c95fbb0b3d128073fb41904cbb63d81f05bdb5ad5ed1c7b9ed2bbb920b51f585947b1dea8a66de
7
- data.tar.gz: 2bc4952238a7c751c75480d7f70898a51b73a6cf6bee812f65f0a373807c00b8f4eec67327f24f1a763c2016cd873f1e051383237f187ba6f72f6defec76b00c
6
+ metadata.gz: c2a4cff53fe413453ab557278c2f90c7762fd0a425842db4f0eb94081f9c348da28adf2c8fd88eb95a9929caabec0a0e64968360be4f94f666bcf9b1394719d0
7
+ data.tar.gz: c816f6b7c325a148da17b2765ca63cdd9fc06117c7f6c2222f817bc6b9cea00081b934480966bc482556ce5bddb6b9a642f62049e6875dcc80db4f179477e082
@@ -120,14 +120,16 @@ module Workable
120
120
  # parse the api response
121
121
  def parse!(response)
122
122
  case response.code.to_i
123
- when 204, 205
123
+ when 204, 205 # handled no response
124
124
  nil
125
- when 200...300
125
+ when 200...300 # handled with response
126
126
  JSON.parse(response.body)
127
127
  when 401
128
- raise Errors::NotAuthorized, response.body
128
+ raise Errors::NotAuthorized, JSON.parse(response.body)["error"]
129
129
  when 404
130
- raise Errors::NotFound, response.body
130
+ raise Errors::NotFound, JSON.parse(response.body)["error"]
131
+ when 422
132
+ handle_response_422(response)
131
133
  when 503
132
134
  raise Errors::RequestToLong, response.body
133
135
  else
@@ -135,6 +137,19 @@ module Workable
135
137
  end
136
138
  end
137
139
 
140
+ def handle_response_422(response)
141
+ data = JSON.parse(response.body)
142
+ if
143
+ data["validation_errors"] &&
144
+ data["validation_errors"]["email"] &&
145
+ data["validation_errors"]["email"].include?("candidate already exists")
146
+ then
147
+ raise Errors::AlreadyExists, data["error"]
148
+ else
149
+ raise Errors::NotFound, data["error"]
150
+ end
151
+ end
152
+
138
153
  # default headers for authentication and JSON support
139
154
  def headers
140
155
  {
@@ -5,6 +5,7 @@ module Workable
5
5
  class NotAuthorized < WorkableError; end
6
6
  class InvalidResponse < WorkableError; end
7
7
  class NotFound < WorkableError; end
8
+ class AlreadyExists < WorkableError; end
8
9
  class RequestToLong < WorkableError; end
9
10
  end
10
11
  end
@@ -1,3 +1,3 @@
1
1
  module Workable
2
- VERSION = "1.0.0.rc1"
2
+ VERSION = "1.0.0.rc2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafał Wojsznis