shotgun_api_ruby 0.0.5.3 → 0.0.8.4

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: cab4b7bb6b46bc730be51e3d0f690685751b30ed901aa66fd4ede97e2b4526e0
4
- data.tar.gz: ead76e9dca731cb80ab15302195d23ccdfafdc26c61003a26080aa7a2d7ed8e7
3
+ metadata.gz: 40d52da8cf4bb1e972a1a4dd4cd0ec8aa8b572c356dbfa47e6b84ff466a1eb33
4
+ data.tar.gz: 64ee5ecaa4ed9b50fbf1b811ebca28dddf5b3150e99d61824ee327b5913da209
5
5
  SHA512:
6
- metadata.gz: 3aa5b7b697fc482c5a461fc0f851880c0b784d69be3cc515b5d14d0f785c501f7bae26d63a44423e0f14e57314b88c08b711fdfd693146ef36757fd1ed7e5c1d
7
- data.tar.gz: 35704ade665195515fb32d906c2091b3fd4a8cecbb6e4a79f04e1b7831205469659a2d69edac25a6a83f626adef357cb1e3a647f824056f85869de88f718cbaa
6
+ metadata.gz: 1caeabca35f814c45e40a477c4130cddc48d15ced65c1854e8db4d56d0574f4cb20ade9e028ccb8c05256c42bb5dcbfb82b30ec3086837ec5f11ea96423fcdd6
7
+ data.tar.gz: b9b6ba452f09ad70cae2a0c961c7a1712dbf21fba4f985ca2ae467c2bee2aa911cab213eecf6dbc73e671367ea8e0204e25b6e039c3ce61d81d0a04d49f43e8f
@@ -19,3 +19,5 @@ jobs:
19
19
  run: 'git diff main lib/shotgun_api_ruby/version.rb | grep -E "^\+.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?"'
20
20
  - name: Verify if higher version
21
21
  run: '[[ $(git diff main lib/shotgun_api_ruby/version.rb | grep -E "^\+.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?") > $(git diff main lib/shotgun_api_ruby/version.rb | grep -E "^-.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?") ]]'
22
+ - name: Verify if version is updated in Gemfile.lock
23
+ run: '[[ $(cat Gemfile.lock | grep "$(git diff main lib/shotgun_api_ruby/version.rb | grep -E "^\+.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?")") ]]'
@@ -14,6 +14,9 @@ AllCops:
14
14
  Style/GlobalVars:
15
15
  Enabled: false
16
16
 
17
+ Gemspec/RequiredRubyVersion:
18
+ Enabled: false
19
+
17
20
  Layout/DotPosition:
18
21
  Enabled: true
19
22
  EnforcedStyle: trailing
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.0.8.4] - 2021-01-07
10
+ ### Changed
11
+ - Safer eager_load
12
+
13
+ ## [0.0.8.3] - 2021-01-07
14
+ ### Added
15
+ - eager_load files to fix weird bugs in rspec
16
+
17
+ ## [0.0.8] - 2020-12-16
18
+ ### Added
19
+ - Schema: read
20
+ - Schema: read fields
21
+
22
+ ## [0.0.7] - 2020-12-16
23
+ ### Added
24
+ - Entities: update
25
+ - Entities: create
26
+ - Entities: delete
27
+ - Entities: revive
28
+
29
+ [Unreleased]: https://github.com/shotgunsoftware/shotgun_api_ruby/compare/v0.0.8.4...HEAD
30
+ [0.0.8.4]: https://github.com/shotgunsoftware/shotgun_api_ruby/releases/tag/v0.0.8.4
31
+ [0.0.8.3]: https://github.com/shotgunsoftware/shotgun_api_ruby/releases/tag/v0.0.8.3
32
+ [0.0.8]: https://github.com/shotgunsoftware/shotgun_api_ruby/releases/tag/v0.0.8
33
+ [0.0.7]: https://github.com/shotgunsoftware/shotgun_api_ruby/releases/tag/v0.0.7
data/README.md CHANGED
@@ -308,15 +308,57 @@ client.assets.find(724, fields: [:code, 'description'], retired: false)
308
308
 
309
309
  #### Create
310
310
 
311
- Not implemented yet
311
+ Will create the entity referenced by the id with the following fields.
312
+ If successful, it will return the newly created entity.
313
+
314
+ ```ruby
315
+ client.assets.create(code: 'New Asset', project: {type: 'Project', id: 63})
316
+ ```
312
317
 
313
318
  #### Update
314
319
 
315
- Not implemented yet
320
+ Will update the entity referenced by the id with the following fields.
321
+ If successful, it will return the modified entity.
322
+
323
+ ```ruby
324
+ client.assets.update(1226, code: 'Updated Asset', sg_status_list: 'fin')
325
+ ```
316
326
 
317
327
  #### Delete
318
328
 
319
- Not implemented yet
329
+ Will destroys the entity referenced by the id. Will return true if successful.
330
+
331
+ ```ruby
332
+ client.assets.delete(1226)
333
+ ```
334
+
335
+ #### Revive
336
+
337
+ Will try to revive the entity referenced by the id. Will return true if successful.
338
+
339
+ ```ruby
340
+ client.assets.revive(1226)
341
+ ```
342
+
343
+ ### Schema
344
+
345
+ Those calls allow to inspect the schema for a shotgun site.
346
+
347
+ #### Entity
348
+
349
+ ```ruby
350
+ client.assets.schema
351
+ ```
352
+
353
+ #### Entity fields
354
+
355
+ Fetch the different fields available on an entity type and their definition.
356
+
357
+ ```ruby
358
+ fields = client.assets.fields
359
+ fields.code.name # => "Asset Name"
360
+ fields.code.properties.summary_default # => "none"
361
+ ```
320
362
 
321
363
  ### Non implemented calls
322
364
 
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # zeitwerk will take care of auto loading files based on their name :)
4
- require "zeitwerk"
4
+ require 'zeitwerk'
5
5
  require 'active_support/core_ext/string/inflections'
6
6
  require 'ostruct'
7
- require "faraday"
7
+ require 'faraday'
8
8
  require 'json'
9
9
 
10
10
  loader = Zeitwerk::Loader.for_gem
@@ -15,3 +15,5 @@ module ShotgunApiRuby
15
15
  Client.new(**args)
16
16
  end
17
17
  end
18
+
19
+ loader.eager_load
@@ -28,7 +28,7 @@ module ShotgunApiRuby
28
28
  public_send(type)
29
29
  end
30
30
 
31
- def respond_to_missing?(_name, _include_private = false) # rubocop:disable Lint/MissingSuper
31
+ def respond_to_missing?(_name, _include_private = false)
32
32
  true
33
33
  end
34
34
 
@@ -5,6 +5,7 @@ module ShotgunApiRuby
5
5
  def initialize(connection, type)
6
6
  @connection = connection.dup
7
7
  @type = type
8
+ @base_url_prefix = @connection.url_prefix
8
9
  @connection.url_prefix = "#{@connection.url_prefix}/entity/#{type}"
9
10
  end
10
11
 
@@ -52,6 +53,78 @@ module ShotgunApiRuby
52
53
  )
53
54
  end
54
55
 
56
+ def create(attributes)
57
+ resp =
58
+ @connection.post('', attributes.to_json) do |req|
59
+ req.headers['Content-Type'] = 'application/json'
60
+ end
61
+
62
+ resp_body = JSON.parse(resp.body)
63
+
64
+ if resp.status >= 300
65
+ raise "Error while creating #{type}# with #{attributes}: #{resp_body['errors']}"
66
+ end
67
+
68
+ entity = resp_body["data"]
69
+ Entity.new(
70
+ entity['type'],
71
+ OpenStruct.new(entity['attributes']),
72
+ entity['relationships'],
73
+ entity['id'],
74
+ entity['links']
75
+ )
76
+ end
77
+
78
+ def update(id, changes)
79
+ return find(id) if changes.empty?
80
+
81
+ resp =
82
+ @connection.put(id.to_s, changes.to_json) do |req|
83
+ req.headers['Content-Type'] = 'application/json'
84
+ end
85
+
86
+ resp_body = JSON.parse(resp.body)
87
+
88
+ if resp.status >= 300
89
+ raise "Error while updating #{type}##{id} with #{changes}: #{resp_body['errors']}"
90
+ end
91
+
92
+ entity = resp_body["data"]
93
+ Entity.new(
94
+ entity['type'],
95
+ OpenStruct.new(entity['attributes']),
96
+ entity['relationships'],
97
+ entity['id'],
98
+ entity['links']
99
+ )
100
+ end
101
+
102
+ def delete(id)
103
+ resp =
104
+ @connection.delete(id.to_s) do |req|
105
+ req.headers['Content-Type'] = 'application/json'
106
+ end
107
+
108
+ if resp.status >= 300
109
+ resp_body = JSON.parse(resp.body)
110
+ raise "Error while deleting #{type}##{id}: #{resp_body['errors']}"
111
+ end
112
+
113
+ true
114
+ end
115
+
116
+ def revive(id)
117
+ resp =
118
+ @connection.post("#{id}?revive=true")
119
+
120
+ if resp.status >= 300
121
+ resp_body = JSON.parse(resp.body)
122
+ raise "Error while reviving #{type}##{id}: #{resp_body['errors']}"
123
+ end
124
+
125
+ true
126
+ end
127
+
55
128
  def all(
56
129
  fields: nil,
57
130
  logical_operator: 'and',
@@ -148,7 +221,6 @@ module ShotgunApiRuby
148
221
  req.headers['Content-Type'] = 'application/vnd+shotgun.api3_hash+json'
149
222
  end
150
223
  req.body = params.to_h.merge(filters: filter).to_json
151
- pp JSON.parse(req.body)
152
224
  end
153
225
  resp_body = JSON.parse(resp.body)
154
226
 
@@ -167,6 +239,18 @@ module ShotgunApiRuby
167
239
  end
168
240
  end
169
241
 
242
+ def schema_client
243
+ @schema_client ||= Schema.new(connection, type, @base_url_prefix)
244
+ end
245
+
246
+ def schema
247
+ schema_client.read
248
+ end
249
+
250
+ def fields
251
+ schema_client.fields
252
+ end
253
+
170
254
  private
171
255
 
172
256
  def filters_are_simple?(filters)
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShotgunApiRuby
4
+ class Entities
5
+ class Schema
6
+ def initialize(connection, type, base_url_prefix)
7
+ @connection = connection.dup
8
+ @type = type
9
+ @connection.url_prefix = "#{base_url_prefix}/schema/#{type}"
10
+ end
11
+ attr_reader :type, :connection
12
+
13
+ def read
14
+ resp = @connection.get('')
15
+
16
+ if resp.status >= 300
17
+ raise "Error while read schema for #{type}: #{resp.body}"
18
+ end
19
+
20
+ resp_body = JSON.parse(resp.body)
21
+
22
+ OpenStruct.new(
23
+ resp_body["data"].transform_values{ |v| v["value"] }
24
+ )
25
+ end
26
+
27
+ def fields
28
+ resp = @connection.get('fields')
29
+ resp_body = JSON.parse(resp.body)
30
+
31
+ if resp.status >= 300
32
+ raise "Error while read schema fields for #{type}: #{resp.body}"
33
+ end
34
+
35
+ OpenStruct.new(
36
+ resp_body["data"].transform_values do |value|
37
+ OpenStruct.new(
38
+ value.transform_values do |attribute|
39
+ attribute["value"]
40
+ end.merge(
41
+ properties: OpenStruct.new(value["properties"].transform_values{ |prop| prop["value"] })
42
+ )
43
+ )
44
+ end
45
+ )
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ShotgunApiRuby
4
- VERSION = "0.0.5.3"
4
+ VERSION = '0.0.8.4'
5
5
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.metadata["homepage_uri"] = spec.homepage
20
20
  spec.metadata["source_code_uri"] = "https://github.com/shotgunsoftware/shotgun_api_ruby"
21
- # spec.metadata["changelog_uri"] = "http://none.yet.com"
21
+ spec.metadata['changelog_uri'] = "https://github.com/shotgunsoftware/shotgun_api_ruby/blob/main/CHANGELOG.md"
22
22
 
23
23
  # Specify which files should be added to the gem when it is released.
24
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shotgun_api_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5.3
4
+ version: 0.0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis <Zaratan> Pasin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-06 00:00:00.000000000 Z
11
+ date: 2021-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -210,7 +210,9 @@ files:
210
210
  - ".ruby-gemset"
211
211
  - ".ruby-version"
212
212
  - ".travis.yml"
213
+ - CHANGELOG.md
213
214
  - Gemfile
215
+ - Gemfile.lock
214
216
  - LICENSE.txt
215
217
  - README.md
216
218
  - Rakefile
@@ -221,6 +223,7 @@ files:
221
223
  - lib/shotgun_api_ruby/client.rb
222
224
  - lib/shotgun_api_ruby/entities.rb
223
225
  - lib/shotgun_api_ruby/entities/params.rb
226
+ - lib/shotgun_api_ruby/entities/schema.rb
224
227
  - lib/shotgun_api_ruby/entity.rb
225
228
  - lib/shotgun_api_ruby/preferences.rb
226
229
  - lib/shotgun_api_ruby/server_info.rb
@@ -232,6 +235,7 @@ licenses:
232
235
  metadata:
233
236
  homepage_uri: https://github.com/shotgunsoftware/shotgun_api_ruby
234
237
  source_code_uri: https://github.com/shotgunsoftware/shotgun_api_ruby
238
+ changelog_uri: https://github.com/shotgunsoftware/shotgun_api_ruby/blob/main/CHANGELOG.md
235
239
  post_install_message:
236
240
  rdoc_options: []
237
241
  require_paths:
@@ -247,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
251
  - !ruby/object:Gem::Version
248
252
  version: '0'
249
253
  requirements: []
250
- rubygems_version: 3.1.2
254
+ rubygems_version: 3.1.4
251
255
  signing_key:
252
256
  specification_version: 4
253
257
  summary: Gem to interact easily with Shotgun REST api.