lucid_intercom 0.9.0 → 0.10.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
  SHA256:
3
- metadata.gz: 8beef1f3263be51c4af94d613b3bddca0c66682a7cac8807ebf7b82e8e6aa845
4
- data.tar.gz: 33802654e114bd97d160d826e90a899cd208be49b16f7fa17ea7f9117c2e2cc6
3
+ metadata.gz: 0fdfafd4312a7ee7bce683223c3b5ce972199834e5668c505a0fca07f5813faa
4
+ data.tar.gz: 93d58ab3f55ea61f6c020dcc6f83a11b9e90ba3ba9521d45cd214bf8990fecfc
5
5
  SHA512:
6
- metadata.gz: 14da6a3129ae5ff7ea436b09b4a5587ba19e44cc40c4d2b932e425773fb7a7bf6b343479e4fbde21f563c1d3e5f45468450e51110672252bf38c847428f8a8d8
7
- data.tar.gz: 81decf10aaaf03cb4dc82d69068a918a1e14ab55e127090816d81062dc85473d77910ecd449528e7aef776c52e89b12c52954f327b84f141d1a3006db3094db9
6
+ metadata.gz: 0c3bb863f4d31b9312b14d9774711f74e02e636bb9e58f092706ea3f2a316899a05b9ca21fbbf691c763e8666a13bbd5f2e2cbda6fa1b1c76a5298457ce94219
7
+ data.tar.gz: 7523ced9f7b08cf4198130b741f13f762e171f653a91138625fa5192143fa7c9a2e5652f6b9fc579f67b3b97b118626a6eff1c9ba3aed8ce8dcbd6d90c58526a
@@ -24,7 +24,7 @@ module LucidIntercom
24
24
  'Content-Type' => 'application/json'
25
25
  ).post("https://api.intercom.io/#{path}", json: data)
26
26
 
27
- Response.new(res.code)
27
+ Response.new(res.code, res.headers.to_h, res.to_s)
28
28
  end
29
29
  end
30
30
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+
3
5
  require 'lucid_intercom'
4
6
 
5
7
  module LucidIntercom
@@ -10,14 +12,14 @@ module LucidIntercom
10
12
  class Error < LucidIntercom::Error
11
13
  extend Dry::Initializer
12
14
 
13
- # @return [Integer]
14
- param :status_code
15
+ # @return [Response]
16
+ param :response
15
17
 
16
18
  #
17
19
  # @return [String]
18
20
  #
19
21
  def message
20
- "bad response (#{status_code})"
22
+ "bad response (#{response.status_code})"
21
23
  end
22
24
  end
23
25
 
@@ -28,22 +30,44 @@ module LucidIntercom
28
30
 
29
31
  # @return [Integer]
30
32
  param :status_code
33
+ # @return [Hash]
34
+ param :headers
35
+ # @return [String]
36
+ param :data
37
+ # @return [Hash] the parsed response body
38
+ param :data_hash, default: -> { parse_data }
39
+
40
+ #
41
+ # @return [Hash]
42
+ #
43
+ private def parse_data
44
+ return {} unless json?
45
+
46
+ JSON.parse(data)
47
+ end
31
48
 
32
49
  #
33
50
  # @return [Boolean]
34
51
  #
52
+ private def json?
53
+ headers['Content-Type'] =~ /application\/json/
54
+ end
55
+
56
+ #
57
+ # @return [self]
58
+ #
35
59
  # @raise [ClientError] for status 4xx
36
60
  # @raise [ServerError] for status 5xx
37
61
  #
38
62
  def assert!
39
63
  case status_code
40
64
  when 400..499
41
- raise ClientError.new(status_code)
65
+ raise ClientError.new(self)
42
66
  when 500..599
43
- raise ServerError.new(status_code)
67
+ raise ServerError.new(self)
44
68
  end
45
69
 
46
- true
70
+ self
47
71
  end
48
72
  end
49
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucidIntercom
4
- VERSION = '0.9.0'
4
+ VERSION = '0.10.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucid_intercom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelsey Judson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-22 00:00:00.000000000 Z
11
+ date: 2019-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake