shotgun_api_ruby 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +16 -2
- data/lib/shotgun_api_ruby/entities.rb +77 -43
- data/lib/shotgun_api_ruby/entities/params.rb +53 -0
- data/lib/shotgun_api_ruby/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81e63f04a043edf0f4e28d98959cde8ca3b28d758b899f13f2a6f0888d7e2c79
|
4
|
+
data.tar.gz: bc6c97071892f5f236d95e1f47d59ccff5e53c2b4cb0c370951f9823d243c9d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20fe88744936a2fce96771ca1abdb1310536d94547ecb276a6a28b052bb11794338dc49dde98e6a2846f9eba8a86cdbbd677b628ca2b9697d67679858827b1d9
|
7
|
+
data.tar.gz: 1fc22594f7144215eeed1b5895e3891ba5dab62ce9ccfa8b93181fa7268bf22f92420121bad44822d1fc9d67cc06361182bab0828cd0506f7f205c3933d4b98d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -160,6 +160,18 @@ The all call will return all possible entities.
|
|
160
160
|
client.assets.all
|
161
161
|
```
|
162
162
|
|
163
|
+
##### search
|
164
|
+
|
165
|
+
Does the same thing as `all`
|
166
|
+
|
167
|
+
##### first
|
168
|
+
|
169
|
+
Will return only the first entity found (same thing as setting the page_size to 1)
|
170
|
+
|
171
|
+
```
|
172
|
+
client.assets.first
|
173
|
+
```
|
174
|
+
|
163
175
|
##### fields
|
164
176
|
|
165
177
|
This attribute describe the wanted fields in the returned entity
|
@@ -191,8 +203,6 @@ client.assets.all(fields: [:code, :description], sort: {code: :asc, description:
|
|
191
203
|
|
192
204
|
##### filter
|
193
205
|
|
194
|
-
**Complex filters are not implemented yet**
|
195
|
-
|
196
206
|
For simple filters, the filter field is waiting for a hash.
|
197
207
|
|
198
208
|
Each value is:
|
@@ -206,6 +216,10 @@ Example:
|
|
206
216
|
client.assets.all(fields: [:code, :description], filter: {code: ['Buck', :Darcy], description: 'I LOVE SG'})
|
207
217
|
```
|
208
218
|
|
219
|
+
For complex filters, see the documentation [here](https://developer.shotgunsoftware.com/rest-api/#searching)
|
220
|
+
|
221
|
+
The complexity of calling a different route and passing different headers/body/params will be taken care of automatically.
|
222
|
+
|
209
223
|
##### page
|
210
224
|
|
211
225
|
You can ask for any page size or page number.
|
@@ -10,6 +10,23 @@ module ShotgunApiRuby
|
|
10
10
|
|
11
11
|
attr_reader :connection, :type
|
12
12
|
|
13
|
+
def first(
|
14
|
+
fields: nil,
|
15
|
+
sort: nil,
|
16
|
+
filter: nil,
|
17
|
+
retired: nil,
|
18
|
+
include_archived_projects: nil
|
19
|
+
)
|
20
|
+
all(
|
21
|
+
fields: fields,
|
22
|
+
sort: sort,
|
23
|
+
filter: filter,
|
24
|
+
retired: retired,
|
25
|
+
include_archived_projects: include_archived_projects,
|
26
|
+
page_size: 1
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
13
30
|
def all(
|
14
31
|
fields: nil,
|
15
32
|
sort: nil,
|
@@ -19,7 +36,17 @@ module ShotgunApiRuby
|
|
19
36
|
retired: nil,
|
20
37
|
include_archived_projects: nil
|
21
38
|
)
|
22
|
-
|
39
|
+
if filter && !filters_are_simple?(filter)
|
40
|
+
return search(
|
41
|
+
fields: fields,
|
42
|
+
sort: sort,
|
43
|
+
filter: filter,
|
44
|
+
page: page,
|
45
|
+
page_size: page_size,
|
46
|
+
retired: retired,
|
47
|
+
include_archived_projects: include_archived_projects
|
48
|
+
)
|
49
|
+
end
|
23
50
|
|
24
51
|
params = Params.new
|
25
52
|
|
@@ -47,60 +74,67 @@ module ShotgunApiRuby
|
|
47
74
|
end
|
48
75
|
end
|
49
76
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
77
|
+
def search(
|
78
|
+
fields: nil,
|
79
|
+
sort: nil,
|
80
|
+
filter: nil,
|
81
|
+
page: nil,
|
82
|
+
page_size: nil,
|
83
|
+
retired: nil,
|
84
|
+
include_archived_projects: nil
|
85
|
+
)
|
86
|
+
if filter.nil? || filters_are_simple?(filter)
|
87
|
+
return all(
|
88
|
+
fields: fields,
|
89
|
+
sort: sort,
|
90
|
+
filter: filter,
|
91
|
+
page: page,
|
92
|
+
page_size: page_size,
|
93
|
+
retired: retired,
|
94
|
+
include_archived_projects: include_archived_projects
|
95
|
+
)
|
56
96
|
end
|
57
|
-
|
97
|
+
params = Params.new
|
58
98
|
|
59
|
-
|
60
|
-
|
61
|
-
|
99
|
+
params.add_fields(fields)
|
100
|
+
params.add_sort(sort)
|
101
|
+
params.add_page(page, page_size)
|
102
|
+
params.add_options(retired, include_archived_projects)
|
62
103
|
|
63
|
-
|
64
|
-
|
65
|
-
|
104
|
+
resp =
|
105
|
+
@connection.post('_search', params) do |req|
|
106
|
+
if filter.is_a? Array
|
107
|
+
req.headers["Content-Type"] = 'application/vnd+shotgun.api3_array+json'
|
66
108
|
else
|
67
|
-
[
|
109
|
+
req.headers['Content-Type'] = 'application/vnd+shotgun.api3_hash+json'
|
68
110
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
return unless page || page_size
|
73
|
-
|
74
|
-
page = page.to_i if page
|
75
|
-
page_size = page_size.to_i if page_size
|
111
|
+
req.body = params.to_h.merge(filters: filter).to_json
|
112
|
+
end
|
113
|
+
resp_body = JSON.parse(resp.body)
|
76
114
|
|
77
|
-
|
78
|
-
|
115
|
+
if resp.status >= 300
|
116
|
+
raise "Error while getting #{type}: #{resp_body['errors']}"
|
79
117
|
end
|
80
118
|
|
81
|
-
|
82
|
-
|
119
|
+
resp_body["data"].map do |entity|
|
120
|
+
Entity.new(
|
121
|
+
entity['type'],
|
122
|
+
OpenStruct.new(entity['attributes']),
|
123
|
+
entity['relationships'],
|
124
|
+
entity['id'],
|
125
|
+
entity['links']
|
126
|
+
)
|
83
127
|
end
|
128
|
+
end
|
84
129
|
|
85
|
-
|
86
|
-
return if return_only.nil? && include_archived_projects.nil?
|
87
|
-
|
88
|
-
self[:options] = {
|
89
|
-
return_only: return_only ? 'retired' : 'active',
|
90
|
-
include_archived_projects: !!include_archived_projects,
|
91
|
-
}
|
92
|
-
end
|
130
|
+
private
|
93
131
|
|
94
|
-
|
95
|
-
|
132
|
+
def filters_are_simple?(filters)
|
133
|
+
return false if filters.is_a? Array
|
96
134
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
field.to_s,
|
101
|
-
value.is_a?(Array) ? value.map(&:to_s).join(',') : value.to_s,
|
102
|
-
]
|
103
|
-
end.to_h
|
135
|
+
filters.values.all? do |filter_val|
|
136
|
+
(filter_val.is_a?(String) || filter_val.is_a?(Symbol)) ||
|
137
|
+
(filter_val.is_a?(Array) && filter_val.all?{ |val| val.is_a?(String) || val.is_a?(Symbol) })
|
104
138
|
end
|
105
139
|
end
|
106
140
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShotgunApiRuby
|
4
|
+
class Entities
|
5
|
+
class Params < Hash
|
6
|
+
def add_sort(sort)
|
7
|
+
return unless sort
|
8
|
+
|
9
|
+
self[:sort] =
|
10
|
+
if sort.is_a?(Hash)
|
11
|
+
sort.map{ |field, direction| "#{direction.to_s.start_with?('desc') ? '-' : ''}#{field}" }.join(',')
|
12
|
+
else
|
13
|
+
[sort].flatten.join(',')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_page(page, page_size)
|
18
|
+
return unless page || page_size
|
19
|
+
|
20
|
+
page = page.to_i if page
|
21
|
+
page_size = page_size.to_i if page_size
|
22
|
+
|
23
|
+
page = 1 if page && page < 1
|
24
|
+
self[:page] = { size: page_size || 20, number: page || 1 }
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_fields(fields)
|
28
|
+
self[:fields] = [fields].flatten.join(',') if fields
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_options(return_only, include_archived_projects)
|
32
|
+
return if return_only.nil? && include_archived_projects.nil?
|
33
|
+
|
34
|
+
self[:options] = {
|
35
|
+
return_only: return_only ? 'retired' : 'active',
|
36
|
+
include_archived_projects: !!include_archived_projects,
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_filter(filters)
|
41
|
+
return unless filters
|
42
|
+
|
43
|
+
# filter
|
44
|
+
self['filter'] = filters.map do |field, value|
|
45
|
+
[
|
46
|
+
field.to_s,
|
47
|
+
value.is_a?(Array) ? value.map(&:to_s).join(',') : value.to_s,
|
48
|
+
]
|
49
|
+
end.to_h
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis <Zaratan> Pasin
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/shotgun_api_ruby/auth.rb
|
191
191
|
- lib/shotgun_api_ruby/client.rb
|
192
192
|
- lib/shotgun_api_ruby/entities.rb
|
193
|
+
- lib/shotgun_api_ruby/entities/params.rb
|
193
194
|
- lib/shotgun_api_ruby/entity.rb
|
194
195
|
- lib/shotgun_api_ruby/preferences.rb
|
195
196
|
- lib/shotgun_api_ruby/server_info.rb
|