shotgun_api_ruby 0.0.4.1 → 0.0.7
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 +4 -4
- data/.github/workflows/test_and_publish.yml +73 -0
- data/.github/workflows/test_only.yml +53 -0
- data/.github/workflows/verify_version_change.yml +21 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +44 -39
- data/README.md +64 -5
- data/lib/shotgun_api_ruby/client.rb +1 -1
- data/lib/shotgun_api_ruby/entities.rb +124 -4
- data/lib/shotgun_api_ruby/entities/params.rb +13 -2
- data/lib/shotgun_api_ruby/entity.rb +1 -1
- data/lib/shotgun_api_ruby/version.rb +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 331b2df4f527205c4803c47cb3a80373578aa740d56fe79c092930881afb9a01
|
4
|
+
data.tar.gz: '09a83792f0f2b93d3b877cb10501d27c0049ef23c928e34ec65b90b9db956900'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f47383023c6a67909c1eb1a54c8acc55880ba978bd20292633fb77362fdfd2e216d5b70869e1da88f1286a8640cec180fa12ef8b7d67351d8815b6b86d3d0e2e
|
7
|
+
data.tar.gz: db5f9915dd9d40558d627efc6ed1860d254ef0f324e40a30aaa4f2e1cf8d78ea10baab866572a82444e40f4b12c3d18da537474fecd7e1a3c839ce0faa4900e9
|
@@ -0,0 +1,73 @@
|
|
1
|
+
name: Test and Release
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test-2_5:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: 2.5
|
18
|
+
- name: Install dependencies
|
19
|
+
run: bundle install
|
20
|
+
- name: Run linter
|
21
|
+
run: bundle exec rubocop
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rspec
|
24
|
+
test-2_6:
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v2
|
29
|
+
- name: Set up Ruby
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: 2.6
|
33
|
+
- name: Install dependencies
|
34
|
+
run: bundle install
|
35
|
+
- name: Run linter
|
36
|
+
run: bundle exec rubocop
|
37
|
+
- name: Run tests
|
38
|
+
run: bundle exec rspec
|
39
|
+
test-2_7:
|
40
|
+
runs-on: ubuntu-latest
|
41
|
+
|
42
|
+
steps:
|
43
|
+
- uses: actions/checkout@v2
|
44
|
+
- name: Set up Ruby
|
45
|
+
uses: ruby/setup-ruby@v1
|
46
|
+
with:
|
47
|
+
ruby-version: 2.7
|
48
|
+
- name: Install dependencies
|
49
|
+
run: bundle install
|
50
|
+
- name: Run linter
|
51
|
+
run: bundle exec rubocop
|
52
|
+
- name: Run tests
|
53
|
+
run: bundle exec rspec
|
54
|
+
release:
|
55
|
+
needs: [test-2_5, test-2_6, test-2_7]
|
56
|
+
runs-on: ubuntu-latest
|
57
|
+
|
58
|
+
steps:
|
59
|
+
- uses: actions/checkout@v2
|
60
|
+
- name: Set up Ruby
|
61
|
+
uses: ruby/setup-ruby@v1
|
62
|
+
with:
|
63
|
+
ruby-version: 2.7
|
64
|
+
- name: Install dependencies
|
65
|
+
run: bundle install
|
66
|
+
- name: Prepare credentials
|
67
|
+
env:
|
68
|
+
RUBYGEM_KEY: ${{ secrets.RUBYGEM_KEY }}
|
69
|
+
run: "echo -e \"---\\r\\n:rubygems_api_key: $RUBYGEM_KEY\" > ~/.gem/credentials && chmod 0600 ~/.gem/credentials"
|
70
|
+
- name: Setup username/email
|
71
|
+
run: "git config --global user.email zaratan@hey.com && git config --global user.name \"Denis <Zaratan> Pasin\""
|
72
|
+
- name: Publish
|
73
|
+
run: rake release
|
@@ -0,0 +1,53 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches-ignore:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test-2_5:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: 2.5
|
18
|
+
- name: Install dependencies
|
19
|
+
run: bundle install
|
20
|
+
- name: Run linter
|
21
|
+
run: bundle exec rubocop
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rspec
|
24
|
+
test-2_6:
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v2
|
29
|
+
- name: Set up Ruby
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: 2.6
|
33
|
+
- name: Install dependencies
|
34
|
+
run: bundle install
|
35
|
+
- name: Run linter
|
36
|
+
run: bundle exec rubocop
|
37
|
+
- name: Run tests
|
38
|
+
run: bundle exec rspec
|
39
|
+
test-2_7:
|
40
|
+
runs-on: ubuntu-latest
|
41
|
+
|
42
|
+
steps:
|
43
|
+
- uses: actions/checkout@v2
|
44
|
+
- name: Set up Ruby
|
45
|
+
uses: ruby/setup-ruby@v1
|
46
|
+
with:
|
47
|
+
ruby-version: 2.7
|
48
|
+
- name: Install dependencies
|
49
|
+
run: bundle install
|
50
|
+
- name: Run linter
|
51
|
+
run: bundle exec rubocop
|
52
|
+
- name: Run tests
|
53
|
+
run: bundle exec rspec
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Verify version change
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
version_change:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Fetch main branch
|
15
|
+
run: git fetch origin main:main
|
16
|
+
- name: Verify if there's a change in version
|
17
|
+
run: "git diff main lib/shotgun_api_ruby/version.rb | grep VERSION"
|
18
|
+
- name: Print new version
|
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
|
+
- name: Verify if higher version
|
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]+)?") ]]'
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
shotgun_api_ruby (0.0.
|
4
|
+
shotgun_api_ruby (0.0.7)
|
5
5
|
activesupport
|
6
6
|
faraday (~> 1)
|
7
7
|
zeitwerk (~> 2.2)
|
@@ -9,12 +9,12 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (6.0
|
12
|
+
activesupport (6.1.0)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (>=
|
15
|
-
minitest (
|
16
|
-
tzinfo (~>
|
17
|
-
zeitwerk (~> 2.
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
zeitwerk (~> 2.3)
|
18
18
|
ast (2.4.1)
|
19
19
|
backport (1.1.2)
|
20
20
|
benchmark (0.1.0)
|
@@ -27,83 +27,88 @@ GEM
|
|
27
27
|
diff-lcs (1.4.4)
|
28
28
|
dotenv (2.7.6)
|
29
29
|
e2mmap (0.1.0)
|
30
|
-
faraday (1.0
|
30
|
+
faraday (1.1.0)
|
31
31
|
multipart-post (>= 1.2, < 3)
|
32
|
+
ruby2_keywords
|
32
33
|
i18n (1.8.5)
|
33
34
|
concurrent-ruby (~> 1.0)
|
34
35
|
iniparse (1.5.0)
|
35
36
|
jaro_winkler (1.5.4)
|
36
|
-
|
37
|
+
kramdown (2.3.0)
|
38
|
+
rexml
|
39
|
+
kramdown-parser-gfm (1.1.0)
|
40
|
+
kramdown (~> 2.0)
|
37
41
|
method_source (1.0.0)
|
38
42
|
mini_portile2 (2.4.0)
|
39
43
|
minitest (5.14.2)
|
40
44
|
multipart-post (2.1.1)
|
41
45
|
nokogiri (1.10.10)
|
42
46
|
mini_portile2 (~> 2.4.0)
|
43
|
-
overcommit (0.
|
47
|
+
overcommit (0.57.0)
|
44
48
|
childprocess (>= 0.6.3, < 5)
|
45
49
|
iniparse (~> 1.4)
|
46
|
-
parallel (1.
|
47
|
-
parser (2.7.
|
50
|
+
parallel (1.20.1)
|
51
|
+
parser (2.7.2.0)
|
48
52
|
ast (~> 2.4.1)
|
49
53
|
pry (0.13.1)
|
50
54
|
coderay (~> 1.1)
|
51
55
|
method_source (~> 1.0)
|
52
56
|
rainbow (3.0.0)
|
53
57
|
rake (13.0.1)
|
54
|
-
regexp_parser (
|
58
|
+
regexp_parser (2.0.0)
|
55
59
|
reverse_markdown (2.0.0)
|
56
60
|
nokogiri
|
57
61
|
rexml (3.2.4)
|
58
|
-
rspec (3.
|
59
|
-
rspec-core (~> 3.
|
60
|
-
rspec-expectations (~> 3.
|
61
|
-
rspec-mocks (~> 3.
|
62
|
-
rspec-core (3.
|
63
|
-
rspec-support (~> 3.
|
64
|
-
rspec-expectations (3.
|
62
|
+
rspec (3.10.0)
|
63
|
+
rspec-core (~> 3.10.0)
|
64
|
+
rspec-expectations (~> 3.10.0)
|
65
|
+
rspec-mocks (~> 3.10.0)
|
66
|
+
rspec-core (3.10.0)
|
67
|
+
rspec-support (~> 3.10.0)
|
68
|
+
rspec-expectations (3.10.0)
|
65
69
|
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
-
rspec-support (~> 3.
|
67
|
-
rspec-mocks (3.
|
70
|
+
rspec-support (~> 3.10.0)
|
71
|
+
rspec-mocks (3.10.0)
|
68
72
|
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
-
rspec-support (~> 3.
|
70
|
-
rspec-support (3.
|
71
|
-
rubocop (
|
73
|
+
rspec-support (~> 3.10.0)
|
74
|
+
rspec-support (3.10.0)
|
75
|
+
rubocop (1.6.1)
|
72
76
|
parallel (~> 1.10)
|
73
|
-
parser (>= 2.7.1.
|
77
|
+
parser (>= 2.7.1.5)
|
74
78
|
rainbow (>= 2.2.2, < 4.0)
|
75
|
-
regexp_parser (>= 1.
|
79
|
+
regexp_parser (>= 1.8, < 3.0)
|
76
80
|
rexml
|
77
|
-
rubocop-ast (>=
|
81
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
78
82
|
ruby-progressbar (~> 1.7)
|
79
83
|
unicode-display_width (>= 1.4.0, < 2.0)
|
80
|
-
rubocop-ast (
|
81
|
-
parser (>= 2.7.1.
|
82
|
-
rubocop-performance (1.
|
83
|
-
rubocop (>= 0.
|
84
|
+
rubocop-ast (1.3.0)
|
85
|
+
parser (>= 2.7.1.5)
|
86
|
+
rubocop-performance (1.9.1)
|
87
|
+
rubocop (>= 0.90.0, < 2.0)
|
88
|
+
rubocop-ast (>= 0.4.0)
|
84
89
|
ruby-progressbar (1.10.1)
|
85
|
-
|
90
|
+
ruby2_keywords (0.0.2)
|
91
|
+
solargraph (0.40.0)
|
86
92
|
backport (~> 1.1)
|
87
93
|
benchmark
|
88
94
|
bundler (>= 1.17.2)
|
89
95
|
e2mmap
|
90
96
|
jaro_winkler (~> 1.5)
|
91
|
-
|
92
|
-
|
97
|
+
kramdown (~> 2.3)
|
98
|
+
kramdown-parser-gfm (~> 1.1)
|
93
99
|
parser (~> 2.3)
|
94
100
|
reverse_markdown (>= 1.0.5, < 3)
|
95
|
-
rubocop (
|
101
|
+
rubocop (>= 0.52)
|
96
102
|
thor (~> 1.0)
|
97
103
|
tilt (~> 2.0)
|
98
104
|
yard (~> 0.9, >= 0.9.24)
|
99
105
|
thor (1.0.1)
|
100
|
-
thread_safe (0.3.6)
|
101
106
|
tilt (2.0.10)
|
102
|
-
tzinfo (
|
103
|
-
|
107
|
+
tzinfo (2.0.3)
|
108
|
+
concurrent-ruby (~> 1.0)
|
104
109
|
unicode-display_width (1.7.0)
|
105
110
|
yard (0.9.25)
|
106
|
-
zeitwerk (2.4.
|
111
|
+
zeitwerk (2.4.2)
|
107
112
|
|
108
113
|
PLATFORMS
|
109
114
|
ruby
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# ShotgunApiRuby
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/shotgun_api_ruby)
|
4
|
+

|
5
|
+
|
3
6
|
A gem to integrate with shotgun REST API easily.
|
4
7
|
|
5
8
|
## Installation
|
@@ -166,7 +169,7 @@ Does the same thing as `all`
|
|
166
169
|
|
167
170
|
#### first
|
168
171
|
|
169
|
-
Will return only the first entity found (same thing as setting the page_size to 1)
|
172
|
+
Will return only the first entity found (same thing as setting the page_size to 1 and then getting the first result)
|
170
173
|
|
171
174
|
```
|
172
175
|
client.assets.first
|
@@ -203,6 +206,14 @@ Example:
|
|
203
206
|
client.assets.all(fields: [:code, :description], sort: {code: :asc, description: :desc})
|
204
207
|
```
|
205
208
|
|
209
|
+
##### logical_operator
|
210
|
+
|
211
|
+
Default: "and"
|
212
|
+
|
213
|
+
This will be only used on complex queries. This is how we treat multiple first level conditions.
|
214
|
+
|
215
|
+
Accepted values: 'and', 'or'
|
216
|
+
|
206
217
|
##### filter
|
207
218
|
|
208
219
|
For simple filters, the filter field is waiting for a hash.
|
@@ -218,7 +229,33 @@ Example:
|
|
218
229
|
client.assets.all(fields: [:code, :description], filter: {code: ['Buck', :Darcy], description: 'I LOVE SG'})
|
219
230
|
```
|
220
231
|
|
221
|
-
For complex filters, see the documentation [here](https://developer.shotgunsoftware.com/rest-api/#searching)
|
232
|
+
For complex filters, see the documentation [here](https://developer.shotgunsoftware.com/rest-api/#searching).
|
233
|
+
|
234
|
+
If the filters are complex there's many cases:
|
235
|
+
|
236
|
+
* If they are a hash containing logical_operator and conditions => we will use them
|
237
|
+
* If the filter is **not** a hash => we will use it without translation
|
238
|
+
* If the filter is a hash not containing "conditions". We will try to translate this to SG compatible query.
|
239
|
+
|
240
|
+
Example:
|
241
|
+
```ruby
|
242
|
+
client.assets.all(
|
243
|
+
filter: {
|
244
|
+
project: { id: 2 },
|
245
|
+
sg_status_list: ["act", "hld", "omt"]
|
246
|
+
},
|
247
|
+
)
|
248
|
+
# Will be translated to:
|
249
|
+
{
|
250
|
+
"filters"=>{
|
251
|
+
"conditions"=> [
|
252
|
+
["project.Project.id", "is", 2],
|
253
|
+
["sg_status_list", "in", ["act", "hld", "omt"]]
|
254
|
+
],
|
255
|
+
"logical_operator"=>"and"
|
256
|
+
}
|
257
|
+
}
|
258
|
+
```
|
222
259
|
|
223
260
|
The complexity of calling a different route and passing different headers/body/params will be taken care of automatically.
|
224
261
|
|
@@ -271,15 +308,37 @@ client.assets.find(724, fields: [:code, 'description'], retired: false)
|
|
271
308
|
|
272
309
|
#### Create
|
273
310
|
|
274
|
-
|
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
|
+
```
|
275
317
|
|
276
318
|
#### Update
|
277
319
|
|
278
|
-
|
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
|
+
```
|
279
326
|
|
280
327
|
#### Delete
|
281
328
|
|
282
|
-
|
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
|
+
```
|
283
342
|
|
284
343
|
### Non implemented calls
|
285
344
|
|
@@ -15,16 +15,18 @@ module ShotgunApiRuby
|
|
15
15
|
sort: nil,
|
16
16
|
filter: nil,
|
17
17
|
retired: nil,
|
18
|
-
include_archived_projects: nil
|
18
|
+
include_archived_projects: nil,
|
19
|
+
logical_operator: 'and'
|
19
20
|
)
|
20
21
|
all(
|
21
22
|
fields: fields,
|
22
23
|
sort: sort,
|
23
24
|
filter: filter,
|
24
25
|
retired: retired,
|
26
|
+
logical_operator: logical_operator,
|
25
27
|
include_archived_projects: include_archived_projects,
|
26
28
|
page_size: 1
|
27
|
-
)
|
29
|
+
).first
|
28
30
|
end
|
29
31
|
|
30
32
|
def find(id, fields: nil, retired: nil, include_archived_projects: nil)
|
@@ -50,8 +52,81 @@ module ShotgunApiRuby
|
|
50
52
|
)
|
51
53
|
end
|
52
54
|
|
55
|
+
def create(**attributes)
|
56
|
+
resp =
|
57
|
+
@connection.post('', attributes.to_json) do |req|
|
58
|
+
req.headers['Content-Type'] = 'application/json'
|
59
|
+
end
|
60
|
+
|
61
|
+
resp_body = JSON.parse(resp.body)
|
62
|
+
|
63
|
+
if resp.status >= 300
|
64
|
+
raise "Error while creating #{type}# with #{attributes}: #{resp_body['errors']}"
|
65
|
+
end
|
66
|
+
|
67
|
+
entity = resp_body["data"]
|
68
|
+
Entity.new(
|
69
|
+
entity['type'],
|
70
|
+
OpenStruct.new(entity['attributes']),
|
71
|
+
entity['relationships'],
|
72
|
+
entity['id'],
|
73
|
+
entity['links']
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def update(id, **changes)
|
78
|
+
return find(id) if changes.empty?
|
79
|
+
|
80
|
+
resp =
|
81
|
+
@connection.put(id.to_s, changes.to_json) do |req|
|
82
|
+
req.headers['Content-Type'] = 'application/json'
|
83
|
+
end
|
84
|
+
|
85
|
+
resp_body = JSON.parse(resp.body)
|
86
|
+
|
87
|
+
if resp.status >= 300
|
88
|
+
raise "Error while updating #{type}##{id} with #{changes}: #{resp_body['errors']}"
|
89
|
+
end
|
90
|
+
|
91
|
+
entity = resp_body["data"]
|
92
|
+
Entity.new(
|
93
|
+
entity['type'],
|
94
|
+
OpenStruct.new(entity['attributes']),
|
95
|
+
entity['relationships'],
|
96
|
+
entity['id'],
|
97
|
+
entity['links']
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
def delete(id)
|
102
|
+
resp =
|
103
|
+
@connection.delete(id.to_s) do |req|
|
104
|
+
req.headers['Content-Type'] = 'application/json'
|
105
|
+
end
|
106
|
+
|
107
|
+
if resp.status >= 300
|
108
|
+
resp_body = JSON.parse(resp.body)
|
109
|
+
raise "Error while deleting #{type}##{id}: #{resp_body['errors']}"
|
110
|
+
end
|
111
|
+
|
112
|
+
true
|
113
|
+
end
|
114
|
+
|
115
|
+
def revive(id)
|
116
|
+
resp =
|
117
|
+
@connection.post("#{id}?revive=true")
|
118
|
+
|
119
|
+
if resp.status >= 300
|
120
|
+
resp_body = JSON.parse(resp.body)
|
121
|
+
raise "Error while reviving #{type}##{id}: #{resp_body['errors']}"
|
122
|
+
end
|
123
|
+
|
124
|
+
true
|
125
|
+
end
|
126
|
+
|
53
127
|
def all(
|
54
128
|
fields: nil,
|
129
|
+
logical_operator: 'and',
|
55
130
|
sort: nil,
|
56
131
|
filter: nil,
|
57
132
|
page: nil,
|
@@ -62,6 +137,7 @@ module ShotgunApiRuby
|
|
62
137
|
if filter && !filters_are_simple?(filter)
|
63
138
|
return search(
|
64
139
|
fields: fields,
|
140
|
+
logical_operator: logical_operator,
|
65
141
|
sort: sort,
|
66
142
|
filter: filter,
|
67
143
|
page: page,
|
@@ -99,6 +175,7 @@ module ShotgunApiRuby
|
|
99
175
|
|
100
176
|
def search(
|
101
177
|
fields: nil,
|
178
|
+
logical_operator: 'and',
|
102
179
|
sort: nil,
|
103
180
|
filter: nil,
|
104
181
|
page: nil,
|
@@ -109,6 +186,7 @@ module ShotgunApiRuby
|
|
109
186
|
if filter.nil? || filters_are_simple?(filter)
|
110
187
|
return all(
|
111
188
|
fields: fields,
|
189
|
+
logical_operator: logical_operator,
|
112
190
|
sort: sort,
|
113
191
|
filter: filter,
|
114
192
|
page: page,
|
@@ -123,6 +201,16 @@ module ShotgunApiRuby
|
|
123
201
|
params.add_sort(sort)
|
124
202
|
params.add_page(page, page_size)
|
125
203
|
params.add_options(retired, include_archived_projects)
|
204
|
+
new_filter = {}
|
205
|
+
if filter.is_a?(Hash)
|
206
|
+
new_filter[:conditions] =
|
207
|
+
(filter[:conditions] || translate_complex_to_sg_filters(filter))
|
208
|
+
new_filter[:logical_operator] = filter[:logical_operator] || filter['logical_operator'] || logical_operator
|
209
|
+
else
|
210
|
+
new_filter[:conditions] = filter
|
211
|
+
new_filter[:logical_operator] = logical_operator
|
212
|
+
end
|
213
|
+
filter = new_filter
|
126
214
|
|
127
215
|
resp =
|
128
216
|
@connection.post('_search', params) do |req|
|
@@ -132,6 +220,7 @@ module ShotgunApiRuby
|
|
132
220
|
req.headers['Content-Type'] = 'application/vnd+shotgun.api3_hash+json'
|
133
221
|
end
|
134
222
|
req.body = params.to_h.merge(filters: filter).to_json
|
223
|
+
pp JSON.parse(req.body)
|
135
224
|
end
|
136
225
|
resp_body = JSON.parse(resp.body)
|
137
226
|
|
@@ -156,8 +245,39 @@ module ShotgunApiRuby
|
|
156
245
|
return false if filters.is_a? Array
|
157
246
|
|
158
247
|
filters.values.all? do |filter_val|
|
159
|
-
(filter_val.is_a?(String) || filter_val.is_a?(Symbol)) ||
|
160
|
-
(filter_val.is_a?(Array) && filter_val.all?{ |val|
|
248
|
+
(filter_val.is_a?(Integer) || filter_val.is_a?(String) || filter_val.is_a?(Symbol)) ||
|
249
|
+
(filter_val.is_a?(Array) && filter_val.all?{ |val|
|
250
|
+
val.is_a?(String) || val.is_a?(Symbol) || val.is_a?(Integer)
|
251
|
+
} )
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def translate_complex_to_sg_filters(filters)
|
256
|
+
# We don't know how to translate anything but hashes
|
257
|
+
return filters if !filters.is_a?(Hash)
|
258
|
+
|
259
|
+
filters.each.with_object([]) do |item, result|
|
260
|
+
field, value = item
|
261
|
+
case value
|
262
|
+
when String, Symbol, Integer, Float
|
263
|
+
result << [field, "is", value]
|
264
|
+
when Hash
|
265
|
+
value.each do |subfield, subvalue|
|
266
|
+
sanitized_subfield = "#{field.capitalize}.#{subfield}" unless subfield.to_s.include?(".")
|
267
|
+
case subvalue
|
268
|
+
when String, Symbol, Integer, Float
|
269
|
+
result << ["#{field}.#{sanitized_subfield}", "is", subvalue]
|
270
|
+
when Array
|
271
|
+
result << ["#{field}.#{sanitized_subfield}", "in", subvalue]
|
272
|
+
else
|
273
|
+
raise "This case is too complex to auto-translate. Please use shotgun query syntax."
|
274
|
+
end
|
275
|
+
end
|
276
|
+
when Array
|
277
|
+
result << [field, "in", value]
|
278
|
+
else
|
279
|
+
raise "This case is too complex to auto-translate. Please use shotgun query syntax."
|
280
|
+
end
|
161
281
|
end
|
162
282
|
end
|
163
283
|
end
|
@@ -25,7 +25,12 @@ module ShotgunApiRuby
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def add_fields(fields)
|
28
|
-
self[:fields] =
|
28
|
+
self[:fields] =
|
29
|
+
if fields
|
30
|
+
[fields].flatten.join(',')
|
31
|
+
else
|
32
|
+
"*"
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
def add_options(return_only, include_archived_projects)
|
@@ -41,7 +46,13 @@ module ShotgunApiRuby
|
|
41
46
|
return unless filters
|
42
47
|
|
43
48
|
# filter
|
44
|
-
self['filter'] = filters
|
49
|
+
self['filter'] = translate_simple_filter_to_sg(filters)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def translate_simple_filter_to_sg(filters)
|
55
|
+
filters.map do |field, value|
|
45
56
|
[
|
46
57
|
field.to_s,
|
47
58
|
value.is_a?(Array) ? value.map(&:to_s).join(',') : value.to_s,
|
@@ -14,7 +14,7 @@ module ShotgunApiRuby
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def respond_to_missing?(name, _private_methods = false)
|
17
|
+
def respond_to_missing?(name, _private_methods = false)
|
18
18
|
attributes.respond_to?(name) || super
|
19
19
|
end
|
20
20
|
end
|
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.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis <Zaratan> Pasin
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -199,6 +199,9 @@ executables: []
|
|
199
199
|
extensions: []
|
200
200
|
extra_rdoc_files: []
|
201
201
|
files:
|
202
|
+
- ".github/workflows/test_and_publish.yml"
|
203
|
+
- ".github/workflows/test_only.yml"
|
204
|
+
- ".github/workflows/verify_version_change.yml"
|
202
205
|
- ".gitignore"
|
203
206
|
- ".overcommit.yml"
|
204
207
|
- ".rspec"
|
@@ -230,7 +233,7 @@ licenses:
|
|
230
233
|
metadata:
|
231
234
|
homepage_uri: https://github.com/shotgunsoftware/shotgun_api_ruby
|
232
235
|
source_code_uri: https://github.com/shotgunsoftware/shotgun_api_ruby
|
233
|
-
post_install_message:
|
236
|
+
post_install_message:
|
234
237
|
rdoc_options: []
|
235
238
|
require_paths:
|
236
239
|
- lib
|
@@ -245,8 +248,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
248
|
- !ruby/object:Gem::Version
|
246
249
|
version: '0'
|
247
250
|
requirements: []
|
248
|
-
rubygems_version: 3.
|
249
|
-
signing_key:
|
251
|
+
rubygems_version: 3.1.4
|
252
|
+
signing_key:
|
250
253
|
specification_version: 4
|
251
254
|
summary: Gem to interact easily with Shotgun REST api.
|
252
255
|
test_files: []
|