shotgrid_api_ruby 0.1.2 → 0.1.3

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
  SHA256:
3
- metadata.gz: ae7b5145a6416248b3b8b1ae1f2fcd0692dffb84223aa4c6862f6f6126df71a4
4
- data.tar.gz: ce67a7271446889740fa2524085b743a673b49acb8065b3bbc628799478f178d
3
+ metadata.gz: 774dd8aaf768a98b4be34e5f5c9d208605fd590aec94754273452f48130498a5
4
+ data.tar.gz: d3faf78fe7efcd12ecbbfed7c175597a547ecffbcb951586e51de1624e9a6d8a
5
5
  SHA512:
6
- metadata.gz: 1673d552274cfd4eca41511b9cdf9dc7d95e38503cdc8275721e8feb0095226a36091f6b220648ddc1950966e648389e7837b0b585186363818037ed9623dead
7
- data.tar.gz: 184f9af23a48672125112c10f3d28048e00daa94e22c254c27475a9d7a0e26f41f6ed0b8301e1f79d554ceaabf21c541729b596a88b08580136ec0aacacc89fb
6
+ metadata.gz: 4c9e6fd99e54df7499011a75de0884ea8f96bafe1dc6eba86013f1fc5381177467814e7b0590247f632f8ffee7d1a5e2d8f9be8495936235da3d3e238771c3e7
7
+ data.tar.gz: 698dbc0f7d77dad04d5ca3fad5acea4c1ea2d6429dfa587c0e1b4df096ce474bdb2343c658ad8081d154f4adda82baa732243ceebcc25cd89dddb1dbab1e8f2f
data/.rubocop.yml CHANGED
@@ -4,7 +4,7 @@ inherit_from:
4
4
  inherit_gem:
5
5
  prettier: rubocop.yml
6
6
 
7
- require:
7
+ require:
8
8
  - rubocop-performance
9
9
 
10
10
  AllCops:
@@ -12,6 +12,7 @@ AllCops:
12
12
  DisplayStyleGuide: true
13
13
  DisplayCopNames: true
14
14
  SuggestExtensions: false
15
+ TargetRubyVersion: 2.6
15
16
  Exclude:
16
17
  - 'bin/*'
17
18
  - 'vendor/**/*'
@@ -24,7 +25,7 @@ Metrics/BlockLength:
24
25
  - 'config/environments/*.rb'
25
26
  - 'lib/tasks/*.rake'
26
27
  - 'shotgun_api_ruby.gemspec'
27
-
28
+
28
29
  ### Prettier
29
30
  Style:
30
31
  Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.2
1
+ 3.0.2
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.1.3] - 2021-08-24
10
+ ### Changed
11
+ - Updated tooling
12
+ - Adding `ShotgridCallError` to capture call errors and give access to the raw Faraday response
13
+
9
14
  ## [0.1.2] - 2021-06-16
10
15
  ### Changed
11
16
  - Renamed to Shotgrid
data/README.md CHANGED
@@ -71,6 +71,23 @@ client = ShotgridApiRuby.new(shotgrid_site: 'xxx', auth: {session_token: 'sessio
71
71
  client = ShotgridApiRuby.new(shotgrid_site: 'xxx', auth: {refresh_token: 'refresh_token'})
72
72
  ```
73
73
 
74
+ ### ShotgridCallError
75
+
76
+ Every ShotGrid call resulting in an error will throw a ShotgridCallError. This error class derive from StandardError and will implement 2 extra methods:
77
+ - `#response` => Will returns the original HTTP response (a Faraday::Response).
78
+ - `#status` => This method is a shortcut to get the status from the response.
79
+
80
+ exemple
81
+ ```ruby
82
+ begin
83
+ # A ShotGrid call resulting in a error
84
+ rescue StandardError => e
85
+ p e.message, e.backtrace # Will behave as a normal StandardError
86
+ p e.response.body # Original unparsed body from ShotGrid response
87
+ p e.status # Status code from ShotGrid answer
88
+ end
89
+ ```
90
+
74
91
  ### Server Infos
75
92
 
76
93
  Get general server infos:
@@ -107,7 +107,12 @@ module ShotgridApiRuby
107
107
  end
108
108
  resp_body = JSON.parse(resp.body)
109
109
 
110
- raise "Can't login: #{resp_body['errors']}" if resp.status >= 300
110
+ if resp.status >= 300
111
+ raise ShotgridCallError.new(
112
+ response: resp,
113
+ message: "Can't login: #{resp_body['errors']}",
114
+ )
115
+ end
111
116
 
112
117
  @access_token = resp_body['access_token']
113
118
  @token_expiry = Time.now + resp_body['expires_in']
@@ -11,9 +11,11 @@ module ShotgridApiRuby
11
11
 
12
12
  self[:sort] =
13
13
  if sort.is_a?(Hash)
14
- sort.map do |field, direction|
15
- "#{direction.to_s.start_with?('desc') ? '-' : ''}#{field}"
16
- end.join(',')
14
+ sort
15
+ .map do |field, direction|
16
+ "#{direction.to_s.start_with?('desc') ? '-' : ''}#{field}"
17
+ end
18
+ .join(',')
17
19
  else
18
20
  [sort].flatten.join(',')
19
21
  end
@@ -122,9 +124,10 @@ module ShotgridApiRuby
122
124
  filter_val.is_a?(Symbol)
123
125
  ) ||
124
126
  (
125
- filter_val.is_a?(Array) && filter_val.all? do |val|
126
- val.is_a?(String) || val.is_a?(Symbol) || val.is_a?(Integer)
127
- end
127
+ filter_val.is_a?(Array) &&
128
+ filter_val.all? do |val|
129
+ val.is_a?(String) || val.is_a?(Symbol) || val.is_a?(Integer)
130
+ end
128
131
  )
129
132
  end
130
133
  end
@@ -14,7 +14,10 @@ module ShotgridApiRuby
14
14
  resp = @connection.get('')
15
15
 
16
16
  if resp.status >= 300
17
- raise "Error while read schema for #{type}: #{resp.body}"
17
+ raise ShotgridCallError.new(
18
+ response: resp,
19
+ message: "Error while read schema for #{type}: #{resp.body}",
20
+ )
18
21
  end
19
22
 
20
23
  resp_body = JSON.parse(resp.body)
@@ -27,20 +30,26 @@ module ShotgridApiRuby
27
30
  resp_body = JSON.parse(resp.body)
28
31
 
29
32
  if resp.status >= 300
30
- raise "Error while read schema fields for #{type}: #{resp.body}"
33
+ raise ShotgridCallError.new(
34
+ response: resp,
35
+ message:
36
+ "Error while read schema fields for #{type}: #{resp.body}",
37
+ )
31
38
  end
32
39
 
33
40
  OpenStruct.new(
34
41
  resp_body['data'].transform_values do |value|
35
42
  OpenStruct.new(
36
- value.transform_values { |attribute| attribute['value'] }.merge(
37
- properties:
38
- OpenStruct.new(
39
- value['properties'].transform_values do |prop|
40
- prop['value']
41
- end,
42
- ),
43
- ),
43
+ value
44
+ .transform_values { |attribute| attribute['value'] }
45
+ .merge(
46
+ properties:
47
+ OpenStruct.new(
48
+ value['properties'].transform_values do |prop|
49
+ prop['value']
50
+ end,
51
+ ),
52
+ ),
44
53
  )
45
54
  end,
46
55
  )
@@ -51,7 +51,11 @@ module ShotgridApiRuby
51
51
  resp_body = JSON.parse(resp.body)
52
52
 
53
53
  if resp.status >= 300
54
- raise "Error while getting summarize for #{type}: #{resp_body['errors']}"
54
+ raise ShotgridCallError.new(
55
+ response: resp,
56
+ message:
57
+ "Error while getting summarize for #{type}: #{resp_body['errors']}",
58
+ )
55
59
  end
56
60
 
57
61
  Summary.new(
@@ -40,7 +40,10 @@ module ShotgridApiRuby
40
40
  resp_body = JSON.parse(resp.body)
41
41
 
42
42
  if resp.status >= 300
43
- raise "Error while getting #{type}: #{resp_body['errors']}"
43
+ raise ShotgridCallError.new(
44
+ message: "Error while getting #{type}: #{resp_body['errors']}",
45
+ response: resp,
46
+ )
44
47
  end
45
48
 
46
49
  entity = resp_body['data']
@@ -62,9 +65,13 @@ module ShotgridApiRuby
62
65
  resp_body = JSON.parse(resp.body)
63
66
 
64
67
  if resp.status >= 300
65
- raise "Error while creating #{type} with #{attributes}: #{
66
- resp_body['errors']
67
- }"
68
+ raise ShotgridCallError.new(
69
+ response: resp,
70
+ message:
71
+ "Error while creating #{type} with #{attributes}: #{
72
+ resp_body['errors']
73
+ }",
74
+ )
68
75
  end
69
76
 
70
77
  entity = resp_body['data']
@@ -88,9 +95,13 @@ module ShotgridApiRuby
88
95
  resp_body = JSON.parse(resp.body)
89
96
 
90
97
  if resp.status >= 300
91
- raise "Error while updating #{type}##{id} with #{changes}: #{
92
- resp_body['errors']
93
- }"
98
+ raise ShotgridCallError.new(
99
+ response: resp,
100
+ message:
101
+ "Error while updating #{type}##{id} with #{changes}: #{
102
+ resp_body['errors']
103
+ }",
104
+ )
94
105
  end
95
106
 
96
107
  entity = resp_body['data']
@@ -111,7 +122,11 @@ module ShotgridApiRuby
111
122
 
112
123
  if resp.status >= 300
113
124
  resp_body = JSON.parse(resp.body)
114
- raise "Error while deleting #{type}##{id}: #{resp_body['errors']}"
125
+ raise ShotgridCallError.new(
126
+ response: resp,
127
+ message:
128
+ "Error while deleting #{type}##{id}: #{resp_body['errors']}",
129
+ )
115
130
  end
116
131
 
117
132
  true
@@ -122,7 +137,11 @@ module ShotgridApiRuby
122
137
 
123
138
  if resp.status >= 300
124
139
  resp_body = JSON.parse(resp.body)
125
- raise "Error while reviving #{type}##{id}: #{resp_body['errors']}"
140
+ raise ShotgridCallError.new(
141
+ response: resp,
142
+ message:
143
+ "Error while reviving #{type}##{id}: #{resp_body['errors']}",
144
+ )
126
145
  end
127
146
 
128
147
  true
@@ -165,7 +184,10 @@ module ShotgridApiRuby
165
184
  resp_body = JSON.parse(resp.body)
166
185
 
167
186
  if resp.status >= 300
168
- raise "Error while getting #{type}: #{resp_body['errors']}"
187
+ raise ShotgridCallError.new(
188
+ response: resp,
189
+ message: "Error while getting #{type}: #{resp_body['errors']}",
190
+ )
169
191
  end
170
192
 
171
193
  resp_body['data'].map do |entity|
@@ -228,7 +250,10 @@ module ShotgridApiRuby
228
250
  resp_body = JSON.parse(resp.body)
229
251
 
230
252
  if resp.status >= 300
231
- raise "Error while getting #{type}: #{resp_body['errors']}"
253
+ raise ShotgridCallError.new(
254
+ response: resp,
255
+ message: "Error while getting #{type}: #{resp_body['errors']}",
256
+ )
232
257
  end
233
258
 
234
259
  resp_body['data'].map do |entity|
@@ -14,7 +14,11 @@ module ShotgridApiRuby
14
14
  resp_body = JSON.parse(resp.body)
15
15
 
16
16
  if resp.status >= 300
17
- raise "Error while getting server preferences: #{resp_body['errors']}"
17
+ raise ShotgridCallError.new(
18
+ response: resp,
19
+ message:
20
+ "Error while getting server preferences: #{resp_body['errors']}",
21
+ )
18
22
  end
19
23
 
20
24
  data = resp_body['data']
@@ -13,7 +13,11 @@ module ShotgridApiRuby
13
13
  resp_body = JSON.parse(resp.body)
14
14
 
15
15
  if resp.status >= 300
16
- raise "Error while getting server infos: #{resp_body['errors']}"
16
+ raise ShotgridCallError.new(
17
+ response: resp,
18
+ message:
19
+ "Error while getting server infos: #{resp_body['errors']}",
20
+ )
17
21
  end
18
22
 
19
23
  data = resp_body['data']
@@ -0,0 +1,15 @@
1
+ require 'forwardable'
2
+
3
+ module ShotgridApiRuby
4
+ class ShotgridCallError < StandardError
5
+ extend Forwardable
6
+
7
+ def initialize(response:, message:)
8
+ @response = response
9
+ super(message)
10
+ end
11
+
12
+ attr_reader :response
13
+ def_delegators :response, :status
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ShotgridApiRuby
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
data/package.json CHANGED
@@ -5,6 +5,9 @@
5
5
  "repository": "git@github.com:shotgunsoftware/shotgrid_api_ruby.git",
6
6
  "author": "Denis <Zaratan> Pasin <zaratan@hey.com>",
7
7
  "license": "MIT",
8
+ "scripts": {
9
+ "lint": "prettier -w '**/*.rb'"
10
+ },
8
11
  "devDependencies": {
9
12
  "@prettier/plugin-ruby": "^1.3.0",
10
13
  "prettier": "^2.2.1"
data/yarn.lock CHANGED
@@ -3,13 +3,13 @@
3
3
 
4
4
 
5
5
  "@prettier/plugin-ruby@^1.3.0":
6
- version "1.5.5"
7
- resolved "https://registry.yarnpkg.com/@prettier/plugin-ruby/-/plugin-ruby-1.5.5.tgz#9e206fc856a182a292fcfab9043f53c7a3d0af97"
8
- integrity sha512-b387GdXU+LrnY+oaKWRUI5EnsUvrQ0G1jUSVPkvUTGzp/w+BB9/n4SICVPY3V9/wYsvWpAZq4LkE4FdBufXUtA==
6
+ version "1.6.1"
7
+ resolved "https://registry.yarnpkg.com/@prettier/plugin-ruby/-/plugin-ruby-1.6.1.tgz#14489985513a72e052b57c1cf9beae288880faa8"
8
+ integrity sha512-PGDCATgVTQz0s/NB9nStiXVCIr+hG/XnKeAO/kguaHrNf8VwCpP5Ul+/KQao0z0QFBy2PDY8kWptfDQCa7WMXg==
9
9
  dependencies:
10
10
  prettier ">=1.10"
11
11
 
12
12
  prettier@>=1.10, prettier@^2.2.1:
13
- version "2.3.1"
14
- resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.1.tgz#76903c3f8c4449bc9ac597acefa24dc5ad4cbea6"
15
- integrity sha512-p+vNbgpLjif/+D+DwAZAbndtRrR0md0MwfmOVN9N+2RgyACMT+7tfaRnT+WDPkqnuVwleyuBIG2XBxKDme3hPA==
13
+ version "2.3.2"
14
+ resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.2.tgz#ef280a05ec253712e486233db5c6f23441e7342d"
15
+ integrity sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shotgrid_api_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis <Zaratan> Pasin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-17 00:00:00.000000000 Z
11
+ date: 2021-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -357,6 +357,7 @@ files:
357
357
  - lib/shotgrid_api_ruby/entity.rb
358
358
  - lib/shotgrid_api_ruby/preferences.rb
359
359
  - lib/shotgrid_api_ruby/server_info.rb
360
+ - lib/shotgrid_api_ruby/shotgrid_call_error.rb
360
361
  - lib/shotgrid_api_ruby/version.rb
361
362
  - package.json
362
363
  - shotgrid_api_ruby.gemspec
@@ -383,7 +384,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
383
384
  - !ruby/object:Gem::Version
384
385
  version: '0'
385
386
  requirements: []
386
- rubygems_version: 3.2.15
387
+ rubygems_version: 3.2.22
387
388
  signing_key:
388
389
  specification_version: 4
389
390
  summary: Gem to interact easily with Shotgrid REST api.