closeio 2.4.14 → 2.5.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: b6efa6f6ac548b07aad6d17a53d2068e5c5e93dc
4
- data.tar.gz: 9b0532390af62a4e2a86dacc24e872a784794dd0
3
+ metadata.gz: 6d38f5c1d4dae42fe9127f9aba765f4a627e2ece
4
+ data.tar.gz: 3753475417144d5da196868b5bf79b04fcf6927d
5
5
  SHA512:
6
- metadata.gz: 6126a0d0617f0010b017476a7f49f64aa3b163e1c073ce034babd81b9a1d265ea30400d8a07940494dc780cd3064b323b9bb5bc8a6555efb9e4f47aea2ac665e
7
- data.tar.gz: 3da316d60328f4cb17d3a77eb660730631ab8eb9754ee56c853ebb8ee2c0e5553e8b330508dfcef69e2fec74724c84a2f7fc29d1491637631dd3c66a47c84826
6
+ metadata.gz: a2f110db0912312701a22dc8d8e41c1fe2769254f697fa910fc043fd1a70876f33a642d5daf756203950c645e98607b996c52afd32998f824f78db0ff366aa04
7
+ data.tar.gz: 1cc336990cb42688b4cdef3278136b2111107da7748b2bc0769a483490edb63ae1b2eb6f676a20e25772e973e6e78078b91c3e132c11fde49479359f13dac56d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.5.0
2
+ - Add middleware for handling errors when Close.io responds with status codes between 400-599
3
+
1
4
  ## 2.4.0
2
5
 
3
6
  - Add support for `_fields` parameter on leads resource
@@ -1,5 +1,6 @@
1
1
  require 'faraday'
2
2
  require 'faraday_middleware'
3
+ require_relative "error"
3
4
 
4
5
  Dir[File.expand_path('../resources/*.rb', __FILE__)].each{|f| require f}
5
6
 
@@ -21,12 +22,13 @@ module Closeio
21
22
  include Closeio::Client::Task
22
23
  include Closeio::Client::User
23
24
 
24
- attr_reader :api_key, :logger, :ca_file
25
+ attr_reader :api_key, :logger, :ca_file, :errors
25
26
 
26
- def initialize(api_key, logger = true, ca_file = nil)
27
- @api_key = api_key
28
- @logger = logger
29
- @ca_file = ca_file
27
+ def initialize(api_key, logger = true, ca_file = nil, errors = false)
28
+ @api_key = api_key
29
+ @logger = logger
30
+ @ca_file = ca_file
31
+ @errors = errors
30
32
  end
31
33
 
32
34
  def get(path, options={})
@@ -83,6 +85,7 @@ module Closeio
83
85
  conn.response :logger if logger
84
86
  conn.use FaradayMiddleware::Mashify
85
87
  conn.response :json
88
+ conn.use FaradayMiddleware::CloseioErrorHandler if errors
86
89
  conn.adapter Faraday.default_adapter
87
90
  end
88
91
  end
@@ -0,0 +1,25 @@
1
+ module Closeio
2
+ class Error < StandardError; end
3
+ class NotAuthorized < Error; end
4
+ class NotFound < Error; end
5
+ class GatewayTimeout < Error; end
6
+ end
7
+
8
+ require "faraday"
9
+ module FaradayMiddleware
10
+ class CloseioErrorHandler < Faraday::Response::Middleware
11
+ ERROR_STATUSES = 400..600
12
+ def on_complete(env)
13
+ case env[:status]
14
+ when 401
15
+ raise Closeio::NotAuthorized, env.body
16
+ when 404
17
+ raise Closeio::NotFound, env.body
18
+ when 504
19
+ raise Closeio::GatewayTimeout, env.body
20
+ when ERROR_STATUSES
21
+ raise Closeio::Error, "#{env.status}: #{env.body}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Closeio
2
- VERSION = "2.4.14"
2
+ VERSION = "2.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: closeio
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.14
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Brooks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-26 00:00:00.000000000 Z
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -154,6 +154,7 @@ files:
154
154
  - closeio.gemspec
155
155
  - lib/closeio.rb
156
156
  - lib/closeio/client.rb
157
+ - lib/closeio/error.rb
157
158
  - lib/closeio/resources/activity.rb
158
159
  - lib/closeio/resources/bulk_action.rb
159
160
  - lib/closeio/resources/contact.rb