help_scout 0.5.0 → 0.6.0

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: fb7ba581aa0fce9aca9b69f34bd45d003a832095
4
- data.tar.gz: 16e098e8579676e7b127b21e1f0bf38740b02ed6
3
+ metadata.gz: 81382f7b709606575977992773cbf146b9063a6f
4
+ data.tar.gz: 9d50c47b51f8beff738cc166ff0f41b66aea5cee
5
5
  SHA512:
6
- metadata.gz: d47b06f95c503e9537b8578d9774d3d9e05489605ed31cf609730a6febe9c4557a1ebc328cc92c189e45da5d50baacae168481873c8cd8a698a2a2d42cb2475e
7
- data.tar.gz: 0a43fa20e176e2e3323c596d3caf1f9f501deaeafd944f2cc6ad3e80eca300c79ac91d4c80f8613e39d67ea75ee7c73d2de475728066a805f7b4cce4ab7a1069
6
+ metadata.gz: 4c0d08c3dc4e5a25f98b022419c612b92e9008b8ba0fd0649f539dc153982a7b2a6a9a14336e6cade5215226ff34d35ac66dec7c62200c23b07b48da852555db
7
+ data.tar.gz: 4436eeb10dbb398874b2fa89dd34b7e01fdeeab4f4684e30582dddf4d8820d53925426758f4285316702382ee0c2e62060b4a6feae01342cda47bc6b28cb7256
data/lib/help_scout.rb CHANGED
@@ -5,7 +5,11 @@ class HelpScout
5
5
  class ValidationError < StandardError; end
6
6
  class NotImplementedError < StandardError; end
7
7
 
8
+ # Status codes used by Help Scout, not all are implemented in this gem yet.
9
+ # http://developer.helpscout.net/help-desk-api/status-codes/
10
+ HTTP_OK = 200
8
11
  HTTP_CREATED = 201
12
+ HTTP_NO_CONTENT = 204
9
13
  HTTP_BAD_REQUEST = 400
10
14
 
11
15
  attr_accessor :last_response
@@ -24,16 +28,9 @@ class HelpScout
24
28
  def create_conversation(data)
25
29
  post("conversations", { body: data })
26
30
 
27
- if last_response.code == HTTP_CREATED
28
- # Extract ID of created conversation from the Location header
29
- conversation_uri = last_response.headers["location"]
30
- return conversation_uri.match(/(\d+)\.json$/)[1]
31
- elsif last_response.code == HTTP_BAD_REQUEST
32
- # Validation failed so return the errors
33
- raise ValidationError, last_response.parsed_response["message"]
34
- else
35
- raise NotImplementedError, "Help Scout returned something that is not implemented by the help_scout gem yet: #{last_response.code}: #{last_response.parsed_response["message"] if last_response.parsed_response}"
36
- end
31
+ # Extract ID of created conversation from the Location header
32
+ conversation_uri = last_response.headers["location"]
33
+ conversation_uri.match(/(\d+)\.json$/)[1]
37
34
  end
38
35
 
39
36
  # Public: Get conversation
@@ -195,6 +192,14 @@ class HelpScout
195
192
  }.merge(options)
196
193
 
197
194
  @last_response = HTTParty.send(method, uri, options)
198
- @last_response.parsed_response
195
+
196
+ case @last_response.code
197
+ when HTTP_OK, HTTP_CREATED, HTTP_NO_CONTENT
198
+ @last_response.parsed_response
199
+ when HTTP_BAD_REQUEST
200
+ raise ValidationError, last_response.parsed_response["message"]
201
+ else
202
+ raise NotImplementedError, "Help Scout returned something that is not implemented by the help_scout gem yet: #{@last_response.code}: #{@last_response.parsed_response["message"] if @last_response.parsed_response}"
203
+ end
199
204
  end
200
205
  end
@@ -1,3 +1,3 @@
1
1
  class HelpScout
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: help_scout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Paagman
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-08-25 00:00:00.000000000 Z
13
+ date: 2017-08-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty