shotgun_api_ruby 0.0.5.2 → 0.0.8.3

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: 7bbe794f988991a22c4625aae5c8075585f4fc49e50c532f681ee63614c9352e
4
- data.tar.gz: e5875a67ae26b682ece8865e08c650b239ea057112c1922700b3a1826b05f82a
3
+ metadata.gz: 06c5375e4155418ae69004dd39b03339072744f2e6d95150c78356d5bf0c16cf
4
+ data.tar.gz: 887e4c5b773fb2e20dd24d70a91268db0a67b872bd105d5259dbfe3f7ff1ebcf
5
5
  SHA512:
6
- metadata.gz: be31578709bd8ee4b5816d8a6c5ec87772efe709505d9df4679c10811f90da408319b51f28038a7dcd00ff20a8057aebc2a072523efa0794c681486eccae949c
7
- data.tar.gz: 199806ba4ee6d1228474b8f486bbd2955da15d08a614b51371b8e142adcc163deddaca5825a2df51858b43f7957b8a2a164f8454e9c5ee6c188a36aa83df605f
6
+ metadata.gz: 187e5c60a1dd8a9d2b3e06abc908a085c43f939a90d9312ac78a5d72069fb4456cd3c1ad0aaf9797154b66b48b82ef4064318ee75e31162fdb3bec4361f5b7fb
7
+ data.tar.gz: 53b1f6d9f3cccb07f79b83ac257959c586c66f3fcc49859dfcae9bcb9099df76f3ba5b8d8929625a4e44aab9db984395cc160a403b565cd36b4996b0de6a31ff
@@ -14,8 +14,10 @@ jobs:
14
14
  - name: Fetch main branch
15
15
  run: git fetch origin main:main
16
16
  - name: Verify if there's a change in version
17
- run: "git diff main lib/rspec_in_context/version.rb | grep VERSION"
17
+ run: "git diff main lib/shotgun_api_ruby/version.rb | grep VERSION"
18
18
  - name: Print new version
19
- run: 'git diff main lib/rspec_in_context/version.rb | grep -E "^\+.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?"'
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
- run: '[[ $(git diff main lib/rspec_in_context/version.rb | grep -E "^\+.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?") > $(git diff main lib/rspec_in_context/version.rb | grep -E "^-.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?") ]]'
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,27 @@
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.3] - 2021-01-07
10
+ ### Added
11
+ - eager_load files to fix weird bugs in rspec
12
+
13
+ ## [0.0.8] - 2020-12-16
14
+ ### Added
15
+ - Schema: read
16
+ - Schema: read fields
17
+
18
+ ## [0.0.7] - 2020-12-16
19
+ ### Added
20
+ - Entities: update
21
+ - Entities: create
22
+ - Entities: delete
23
+ - Entities: revive
24
+
25
+ [Unreleased]: https://github.com/shotgunsoftware/shotgun_api_ruby/compare/v0.0.8...HEAD
26
+ [0.0.8]: https://github.com/shotgunsoftware/shotgun_api_ruby/releases/tag/v0.0.8
27
+ [0.0.7]: https://github.com/shotgunsoftware/shotgun_api_ruby/releases/tag/v0.0.7
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # ShotgunApiRuby
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/shotgun_api_ruby.svg)](https://badge.fury.io/rb/shotgun_api_ruby)
4
+ ![Test and Release badge](https://github.com/shotgunsoftware/shotgun_api_ruby/workflows/Test%20and%20Release/badge.svg)
5
+
3
6
  A gem to integrate with shotgun REST API easily.
4
7
 
5
8
  ## Installation
@@ -305,15 +308,57 @@ client.assets.find(724, fields: [:code, 'description'], retired: false)
305
308
 
306
309
  #### Create
307
310
 
308
- 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
+ ```
309
317
 
310
318
  #### Update
311
319
 
312
- 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
+ ```
313
326
 
314
327
  #### Delete
315
328
 
316
- 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
+ ```
317
362
 
318
363
  ### Non implemented calls
319
364
 
@@ -9,6 +9,7 @@ require 'json'
9
9
 
10
10
  loader = Zeitwerk::Loader.for_gem
11
11
  loader.setup # ready!
12
+ loader.eager_load
12
13
 
13
14
  module ShotgunApiRuby
14
15
  def self.new(**args)
@@ -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.2"
4
+ VERSION = "0.0.8.3"
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.2
4
+ version: 0.0.8.3
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.