codat 0.1.4 → 0.1.5

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: 9b359100d300f095792668b5566510b28d0c417c62884b09b82986c5e29ce050
4
- data.tar.gz: f060ecf8c9fb2b2aab07cac48a16f76468bdcf1f650180cf041bf1873d95be7b
3
+ metadata.gz: d09022df4a8325e87d98203d4441da3bb0767abc37b654c2ed2b0901d0f45f4b
4
+ data.tar.gz: f75d4d5a4e8ef1f66201e53d70ea8449d289e18ca0b7355dbd8484a112bb6a6b
5
5
  SHA512:
6
- metadata.gz: 2efbbac8dc086eaf8def830cc9abdbcdff3de04d17c4af1acd788533597c69a0c8f0b52ff3c1f46f119db2cc9aeaead363eb598786aa225ce11452d144be3f07
7
- data.tar.gz: 6576d8cb03153ed9a409b0c95f94992a95387437a85abf7d7d4bc003f2a2c2c9f97e2914bd2be952834fafb7ef3321d526011ef7ca9a1040caba0f97861cc105
6
+ metadata.gz: ee8f01dfbe68c0b176164b054e6191bf9bf2b68dc6c87740eaf6bab195c6dc9e8724b35dd3179612bb2778d12a69da7b20c9db5adbec0595c6330392504c85af
7
+ data.tar.gz: f94df3242b171c2c63d5c130505484143c81697dce53b9d714817f53f28f329f3872c9b147376abcc57fe5664034e844b1a000c49f67ef00beb1fe0387b041be
@@ -12,8 +12,8 @@ Codat.configure do |config|
12
12
  end
13
13
 
14
14
  # To avoid having to namespace everything when inside the console.
15
- Object.send(:include, Codat)
16
- Object.send(:include, Codat::Models)
15
+ Object.include(Codat)
16
+ Object.include(Codat::Models)
17
17
 
18
18
  require 'pry'
19
19
  Pry.start
@@ -39,6 +39,12 @@ module Codat
39
39
 
40
40
  formatted
41
41
  end
42
+
43
+ # As per Codat API doc
44
+ # https://docs.codat.io/reference/errors
45
+ def successful_response?(result)
46
+ result.status < 400
47
+ end
42
48
  end
43
49
 
44
50
  # Sets all the instance variables by reading the JSON from Codat and converting the keys from
@@ -16,7 +16,7 @@ module Codat
16
16
 
17
17
  result = get(url)
18
18
 
19
- return [] if result.status == 404
19
+ return [] unless successful_response?(result)
20
20
 
21
21
  result.body.map { |account| new(json: account) }
22
22
  end
@@ -18,7 +18,7 @@ module Codat
18
18
 
19
19
  result = get(url, accountId: account_id.to_s.strip, page: page.to_s.strip)
20
20
 
21
- return nil if result.status == 404
21
+ return nil unless successful_response?(result)
22
22
 
23
23
  new(json: result.body)
24
24
  end
@@ -18,9 +18,7 @@ module Codat
18
18
  def self.all(params = {})
19
19
  result = get(ENDPOINTS[:collection], params)
20
20
 
21
- return [] if result.status == 404
22
-
23
- return result.body if result.status == 400
21
+ return [] unless successful_response?(result)
24
22
 
25
23
  result.body[:results].map { |company| new(json: company) }
26
24
  end
@@ -30,7 +28,7 @@ module Codat
30
28
 
31
29
  result = get(url)
32
30
 
33
- return nil if result.status == 404
31
+ return nil unless successful_response?(result)
34
32
 
35
33
  new(json: result.body)
36
34
  end
@@ -38,7 +36,7 @@ module Codat
38
36
  def self.create(params = {})
39
37
  result = post(ENDPOINTS[:collection], params)
40
38
 
41
- return { error: 'An error occured.' } if result.status == 404 || result.status == 400
39
+ return { error: 'An error occured.' } unless successful_response?(result)
42
40
 
43
41
  new(json: result.body)
44
42
  end
@@ -36,7 +36,7 @@ module Codat
36
36
 
37
37
  result = get(url, build_query(params))
38
38
 
39
- return nil if result.status == 404 || result.status == 400
39
+ return nil unless successful_response?(result)
40
40
 
41
41
  new(json: result.body)
42
42
  end
@@ -12,9 +12,7 @@ module Codat
12
12
  def self.all(params = {})
13
13
  result = get(ENDPOINT, params)
14
14
 
15
- return [] if result.status == 404
16
-
17
- return result.body if result.status == 400
15
+ return [] unless successful_response?(result)
18
16
 
19
17
  result.body.map { |integration| new(json: integration) }
20
18
  end
@@ -16,7 +16,7 @@ module Codat
16
16
 
17
17
  result = get(url)
18
18
 
19
- return [] if result.status == 404
19
+ return [] unless successful_response?(result)
20
20
 
21
21
  result.body[:data].map { |report| new(json: report) }
22
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Codat
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Otero
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-13 00:00:00.000000000 Z
11
+ date: 2020-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday