shotgun_api_ruby 0.0.1 → 0.0.5

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: e2163b85f62993d2674a47792d3370ebcbf1a6c283e915c781bc27801868a172
4
- data.tar.gz: e26ff2d7d7beae08aaa041f893bbb0f46eb44bd305313d576c2407a99a5e4123
3
+ metadata.gz: 6e8f35c879d4875bb2fd7aaf64717735ef915ca5dd4229097eb9a9d3eb8265b1
4
+ data.tar.gz: 0576b201159e2dcf3cfdcf7805e26e70f6796475153b0c7712c634aa4bb7fd48
5
5
  SHA512:
6
- metadata.gz: 5956601d851995c92204f03541b5c5e7e07a428df8170884d976b01388b1acfe4022d5781cea92510d6ef83e99ef25c5caa983b02a7d602267970afa3caf889f
7
- data.tar.gz: 33c191b51f8ea193eedb15f5655b51d453173c41e86c0da1f8540e5d08c396e04522aa89fd8f66ea286ccf3d6df6bf3a28df4ddff6e5f77264cb1038bc6f1278
6
+ metadata.gz: 193682e3bbd32fdac36a9bebd5bd6c48d2e2e1652e6d6f1149a2bd103ef8028bcaae91f85320c322468e37bdbfb8e8667134a32dbe4c31c98b62799fa6551b70
7
+ data.tar.gz: e782ea8785bb79dbed938e966bfb80fddafcc4b058f62a65342451be01b4587fff6f67461ab3648c54bbfb01196b0121cbf92fb3067b98ed1b85ab3dcc596d1f
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .env
@@ -1,5 +1,5 @@
1
1
  # Relaxed.Ruby.Style
2
- ## Version 2.4
2
+ ## Version 2.5
3
3
 
4
4
  Style/Alias:
5
5
  Enabled: false
@@ -145,30 +145,9 @@ Lint/AssignmentInCondition:
145
145
  Enabled: false
146
146
  StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition
147
147
 
148
- Metrics/AbcSize:
148
+ Layout/LineLength:
149
149
  Enabled: false
150
150
 
151
- Metrics/BlockNesting:
152
- Enabled: false
153
-
154
- Metrics/ClassLength:
155
- Enabled: false
156
-
157
- Metrics/ModuleLength:
158
- Enabled: false
159
-
160
- Metrics/CyclomaticComplexity:
161
- Enabled: false
162
-
163
- Metrics/LineLength:
164
- Enabled: false
165
-
166
- Metrics/MethodLength:
167
- Enabled: false
168
-
169
- Metrics/ParameterLists:
170
- Enabled: false
171
-
172
- Metrics/PerceivedComplexity:
151
+ Metrics:
173
152
  Enabled: false
174
153
 
@@ -5,6 +5,7 @@ require:
5
5
  - rubocop-performance
6
6
 
7
7
  AllCops:
8
+ NewCops: enable
8
9
  DisplayStyleGuide: true
9
10
  DisplayCopNames: true
10
11
  Exclude:
@@ -46,7 +47,7 @@ Layout/FirstMethodArgumentLineBreak:
46
47
  Layout/MultilineAssignmentLayout:
47
48
  Enabled: true
48
49
 
49
- Metrics/LineLength:
50
+ Layout/LineLength:
50
51
  Enabled: true
51
52
  Max: 120
52
53
  AutoCorrect: true
@@ -1,91 +1,126 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shotgun_api_ruby (0.0.1)
4
+ shotgun_api_ruby (0.0.5)
5
5
  activesupport
6
- faraday (~> 0.17)
6
+ faraday (~> 1)
7
7
  zeitwerk (~> 2.2)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (6.0.0)
12
+ activesupport (6.0.3.3)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 0.7, < 2)
15
15
  minitest (~> 5.1)
16
16
  tzinfo (~> 1.1)
17
- zeitwerk (~> 2.1, >= 2.1.8)
18
- ast (2.4.0)
19
- bundler-audit (0.6.1)
17
+ zeitwerk (~> 2.2, >= 2.2.2)
18
+ ast (2.4.1)
19
+ backport (1.1.2)
20
+ benchmark (0.1.0)
21
+ bundler-audit (0.7.0.1)
20
22
  bundler (>= 1.2.0, < 3)
21
- thor (~> 0.18)
22
- childprocess (3.0.0)
23
- coderay (1.1.2)
24
- concurrent-ruby (1.1.5)
25
- diff-lcs (1.3)
26
- faraday (0.17.0)
23
+ thor (>= 0.18, < 2)
24
+ childprocess (4.0.0)
25
+ coderay (1.1.3)
26
+ concurrent-ruby (1.1.7)
27
+ diff-lcs (1.4.4)
28
+ dotenv (2.7.6)
29
+ e2mmap (0.1.0)
30
+ faraday (1.0.1)
27
31
  multipart-post (>= 1.2, < 3)
28
- i18n (1.7.0)
32
+ i18n (1.8.5)
29
33
  concurrent-ruby (~> 1.0)
30
- iniparse (1.4.4)
31
- jaro_winkler (1.5.3)
32
- method_source (0.9.2)
33
- minitest (5.12.2)
34
+ iniparse (1.5.0)
35
+ jaro_winkler (1.5.4)
36
+ maruku (0.7.3)
37
+ method_source (1.0.0)
38
+ mini_portile2 (2.4.0)
39
+ minitest (5.14.2)
34
40
  multipart-post (2.1.1)
35
- overcommit (0.51.0)
36
- childprocess (>= 0.6.3, < 4)
41
+ nokogiri (1.10.10)
42
+ mini_portile2 (~> 2.4.0)
43
+ overcommit (0.55.0)
44
+ childprocess (>= 0.6.3, < 5)
37
45
  iniparse (~> 1.4)
38
- parallel (1.18.0)
39
- parser (2.6.5.0)
40
- ast (~> 2.4.0)
41
- pry (0.12.2)
42
- coderay (~> 1.1.0)
43
- method_source (~> 0.9.0)
46
+ parallel (1.19.2)
47
+ parser (2.7.1.4)
48
+ ast (~> 2.4.1)
49
+ pry (0.13.1)
50
+ coderay (~> 1.1)
51
+ method_source (~> 1.0)
44
52
  rainbow (3.0.0)
45
- rake (10.5.0)
53
+ rake (13.0.1)
54
+ regexp_parser (1.8.0)
55
+ reverse_markdown (2.0.0)
56
+ nokogiri
57
+ rexml (3.2.4)
46
58
  rspec (3.9.0)
47
59
  rspec-core (~> 3.9.0)
48
60
  rspec-expectations (~> 3.9.0)
49
61
  rspec-mocks (~> 3.9.0)
50
- rspec-core (3.9.0)
51
- rspec-support (~> 3.9.0)
52
- rspec-expectations (3.9.0)
62
+ rspec-core (3.9.2)
63
+ rspec-support (~> 3.9.3)
64
+ rspec-expectations (3.9.2)
53
65
  diff-lcs (>= 1.2.0, < 2.0)
54
66
  rspec-support (~> 3.9.0)
55
- rspec-mocks (3.9.0)
67
+ rspec-mocks (3.9.1)
56
68
  diff-lcs (>= 1.2.0, < 2.0)
57
69
  rspec-support (~> 3.9.0)
58
- rspec-support (3.9.0)
59
- rubocop (0.75.1)
60
- jaro_winkler (~> 1.5.1)
70
+ rspec-support (3.9.3)
71
+ rubocop (0.91.0)
61
72
  parallel (~> 1.10)
62
- parser (>= 2.6)
73
+ parser (>= 2.7.1.1)
63
74
  rainbow (>= 2.2.2, < 4.0)
75
+ regexp_parser (>= 1.7)
76
+ rexml
77
+ rubocop-ast (>= 0.4.0, < 1.0)
64
78
  ruby-progressbar (~> 1.7)
65
- unicode-display_width (>= 1.4.0, < 1.7)
66
- rubocop-performance (1.5.0)
67
- rubocop (>= 0.71.0)
79
+ unicode-display_width (>= 1.4.0, < 2.0)
80
+ rubocop-ast (0.4.2)
81
+ parser (>= 2.7.1.4)
82
+ rubocop-performance (1.8.1)
83
+ rubocop (>= 0.87.0)
84
+ rubocop-ast (>= 0.4.0)
68
85
  ruby-progressbar (1.10.1)
69
- thor (0.20.3)
86
+ solargraph (0.39.15)
87
+ backport (~> 1.1)
88
+ benchmark
89
+ bundler (>= 1.17.2)
90
+ e2mmap
91
+ jaro_winkler (~> 1.5)
92
+ maruku (~> 0.7, >= 0.7.3)
93
+ nokogiri (~> 1.9, >= 1.9.1)
94
+ parser (~> 2.3)
95
+ reverse_markdown (>= 1.0.5, < 3)
96
+ rubocop (~> 0.52)
97
+ thor (~> 1.0)
98
+ tilt (~> 2.0)
99
+ yard (~> 0.9, >= 0.9.24)
100
+ thor (1.0.1)
70
101
  thread_safe (0.3.6)
71
- tzinfo (1.2.5)
102
+ tilt (2.0.10)
103
+ tzinfo (1.2.7)
72
104
  thread_safe (~> 0.1)
73
- unicode-display_width (1.6.0)
74
- zeitwerk (2.2.0)
105
+ unicode-display_width (1.7.0)
106
+ yard (0.9.25)
107
+ zeitwerk (2.4.0)
75
108
 
76
109
  PLATFORMS
77
110
  ruby
78
111
 
79
112
  DEPENDENCIES
80
- bundler (~> 2.0)
113
+ bundler
81
114
  bundler-audit
115
+ dotenv
82
116
  overcommit
83
117
  pry
84
- rake (~> 10.0)
118
+ rake
85
119
  rspec (~> 3.0)
86
- rubocop (~> 0.75)
87
- rubocop-performance (~> 1.5)
120
+ rubocop
121
+ rubocop-performance
88
122
  shotgun_api_ruby!
123
+ solargraph
89
124
 
90
125
  BUNDLED WITH
91
- 2.0.2
126
+ 2.1.4
data/README.md CHANGED
@@ -67,6 +67,48 @@ client = ShotgunApiRuby.new(shotgun_site: 'xxx', auth: {session_token: 'session_
67
67
  client = ShotgunApiRuby.new(shotgun_site: 'xxx', auth: {refresh_token: 'refresh_token'})
68
68
  ```
69
69
 
70
+ ### Server Infos
71
+
72
+ Get general server infos:
73
+
74
+ ```ruby
75
+ client.server_info.get
76
+
77
+ # #<OpenStruct
78
+ shotgun_version="v8.6.0.0-dev (build 12864de)",
79
+ api_version="v1",
80
+ shotgun_version_number="8.6.0.0-dev",
81
+ shotgun_build_number="12864de",
82
+ portfolio_version="UNKNOWN",
83
+ unified_login_flow_enabled=true,
84
+ user_authentication_method="default">
85
+ ```
86
+
87
+ ### Preferences
88
+
89
+ Get some preferences infos:
90
+
91
+ ```ruby
92
+ prefs = client.preferences.get
93
+ prefs.to_h.keys
94
+
95
+ # [:format_date_fields,
96
+ # :date_component_order,
97
+ # :format_time_hour_fields,
98
+ # :format_currency_fields_display_dollar_sign,
99
+ # :format_currency_fields_decimal_options,
100
+ # :format_currency_fields_negative_options,
101
+ # :format_number_fields,
102
+ # :format_float_fields,
103
+ # :format_float_fields_rounding,
104
+ # :format_footage_fields,
105
+ # :support_local_storage,
106
+ # :view_master_settings,
107
+ # :duration_units,
108
+ # :hours_per_day,
109
+ # :last_day_work_week]
110
+ ```
111
+
70
112
  ### Entities
71
113
 
72
114
  Querying entities is done by accessing the named method
@@ -108,9 +150,9 @@ assets.first.attributes.code # => "Buck"
108
150
  assets.first.code # => "Buck"
109
151
  ```
110
152
 
111
- #### Get
153
+ ### Search
112
154
 
113
- ##### all
155
+ #### all
114
156
 
115
157
  The all call will return all possible entities.
116
158
 
@@ -118,6 +160,20 @@ The all call will return all possible entities.
118
160
  client.assets.all
119
161
  ```
120
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 and then getting the first result)
170
+
171
+ ```
172
+ client.assets.first
173
+ ```
174
+
175
+ #### arguments
176
+
121
177
  ##### fields
122
178
 
123
179
  This attribute describe the wanted fields in the returned entity
@@ -147,9 +203,15 @@ Example:
147
203
  client.assets.all(fields: [:code, :description], sort: {code: :asc, description: :desc})
148
204
  ```
149
205
 
150
- ##### filter
206
+ ##### logical_operator
207
+
208
+ Default: "and"
151
209
 
152
- **Complex filters are not implemented yet**
210
+ This will be only used on complex queries. This is how we treat multiple first level conditions.
211
+
212
+ Accepted values: 'and', 'or'
213
+
214
+ ##### filter
153
215
 
154
216
  For simple filters, the filter field is waiting for a hash.
155
217
 
@@ -164,6 +226,36 @@ Example:
164
226
  client.assets.all(fields: [:code, :description], filter: {code: ['Buck', :Darcy], description: 'I LOVE SG'})
165
227
  ```
166
228
 
229
+ For complex filters, see the documentation [here](https://developer.shotgunsoftware.com/rest-api/#searching).
230
+
231
+ If the filters are complex there's many cases:
232
+
233
+ * If they are a hash containing logical_operator and conditions => we will use them
234
+ * If the filter is **not** a hash => we will use it without translation
235
+ * If the filter is a hash not containing "conditions". We will try to translate this to SG compatible query.
236
+
237
+ Example:
238
+ ```ruby
239
+ client.assets.all(
240
+ filter: {
241
+ project: { id: 2 },
242
+ sg_status_list: ["act", "hld", "omt"]
243
+ },
244
+ )
245
+ # Will be translated to:
246
+ {
247
+ "filters"=>{
248
+ "conditions"=> [
249
+ ["project.Project.id", "is", 2],
250
+ ["sg_status_list", "in", ["act", "hld", "omt"]]
251
+ ],
252
+ "logical_operator"=>"and"
253
+ }
254
+ }
255
+ ```
256
+
257
+ The complexity of calling a different route and passing different headers/body/params will be taken care of automatically.
258
+
167
259
  ##### page
168
260
 
169
261
  You can ask for any page size or page number.
@@ -195,6 +287,22 @@ client.assets.all(fields: [:code], retired: true)
195
287
  client.assets.all(fields: [:code], include_archived_projects: true)
196
288
  ```
197
289
 
290
+ ### Finding one element
291
+
292
+ `find` function on `entities` allow you to get one element in particular.
293
+
294
+ It accepts (all arguments are optional):
295
+
296
+ - fields: string, symbol or array of fields
297
+ - retired: boolean specifying if the record is retired
298
+ - include_archived_projects: boolean specifying if the entity is part of an archived project
299
+
300
+ Example:
301
+
302
+ ```ruby
303
+ client.assets.find(724, fields: [:code, 'description'], retired: false)
304
+ ```
305
+
198
306
  #### Create
199
307
 
200
308
  Not implemented yet
@@ -4,6 +4,14 @@
4
4
  require "bundler/setup"
5
5
  require "shotgun_api_ruby"
6
6
 
7
+ require 'dotenv/load'
8
+
9
+ if ENV['SITE_NAME'] && ENV['SCRIPT_NAME'] && ENV['SCRIPT_KEY']
10
+ $cl = ShotgunApiRuby.new(
11
+ shotgun_site: ENV['SITE_NAME'],
12
+ auth: { client_id: ENV['SCRIPT_NAME'], client_secret: ENV['SCRIPT_KEY'] }
13
+ )
14
+ end
7
15
  # You can add fixtures and/or initialization code here to make experimenting
8
16
  # with your gem easier. You can also use a different console, if you like.
9
17
 
@@ -16,11 +16,19 @@ module ShotgunApiRuby
16
16
  end
17
17
  end
18
18
 
19
+ def preferences
20
+ @preferences = Preferences.new(connection)
21
+ end
22
+
23
+ def server_info
24
+ @server_info || ServerInfo.new(connection)
25
+ end
26
+
19
27
  def entities(type)
20
28
  public_send(type)
21
29
  end
22
30
 
23
- def respond_to_missing?(_name, _include_private = false)
31
+ def respond_to_missing?(_name, _include_private = false) # rubocop:disable Lint/MissingSuper,Style/OptionalBooleanParameter
24
32
  true
25
33
  end
26
34
 
@@ -10,8 +10,51 @@ 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
+ logical_operator: 'and'
20
+ )
21
+ all(
22
+ fields: fields,
23
+ sort: sort,
24
+ filter: filter,
25
+ retired: retired,
26
+ logical_operator: logical_operator,
27
+ include_archived_projects: include_archived_projects,
28
+ page_size: 1
29
+ ).first
30
+ end
31
+
32
+ def find(id, fields: nil, retired: nil, include_archived_projects: nil)
33
+ params = Params.new
34
+
35
+ params.add_fields(fields)
36
+ params.add_options(retired, include_archived_projects)
37
+
38
+ resp = @connection.get(id.to_s, params)
39
+ resp_body = JSON.parse(resp.body)
40
+
41
+ if resp.status >= 300
42
+ raise "Error while getting #{type}: #{resp_body['errors']}"
43
+ end
44
+
45
+ entity = resp_body["data"]
46
+ Entity.new(
47
+ entity['type'],
48
+ OpenStruct.new(entity['attributes']),
49
+ entity['relationships'],
50
+ entity['id'],
51
+ entity['links']
52
+ )
53
+ end
54
+
13
55
  def all(
14
56
  fields: nil,
57
+ logical_operator: 'and',
15
58
  sort: nil,
16
59
  filter: nil,
17
60
  page: nil,
@@ -19,7 +62,18 @@ module ShotgunApiRuby
19
62
  retired: nil,
20
63
  include_archived_projects: nil
21
64
  )
22
- raise "Complex filters aren't supported yet" if filter && !filters_are_simple?(filter)
65
+ if filter && !filters_are_simple?(filter)
66
+ return search(
67
+ fields: fields,
68
+ logical_operator: logical_operator,
69
+ sort: sort,
70
+ filter: filter,
71
+ page: page,
72
+ page_size: page_size,
73
+ retired: retired,
74
+ include_archived_projects: include_archived_projects
75
+ )
76
+ end
23
77
 
24
78
  params = Params.new
25
79
 
@@ -47,60 +101,111 @@ module ShotgunApiRuby
47
101
  end
48
102
  end
49
103
 
50
- private
51
-
52
- def filters_are_simple?(filters)
53
- filters.values.all? do |filter_val|
54
- (filter_val.is_a?(String) || filter_val.is_a?(Symbol)) ||
55
- (filter_val.is_a?(Array) && filter_val.all?{ |val| val.is_a?(String) || val.is_a?(Symbol) })
104
+ def search(
105
+ fields: nil,
106
+ logical_operator: 'and',
107
+ sort: nil,
108
+ filter: nil,
109
+ page: nil,
110
+ page_size: nil,
111
+ retired: nil,
112
+ include_archived_projects: nil
113
+ )
114
+ if filter.nil? || filters_are_simple?(filter)
115
+ return all(
116
+ fields: fields,
117
+ logical_operator: logical_operator,
118
+ sort: sort,
119
+ filter: filter,
120
+ page: page,
121
+ page_size: page_size,
122
+ retired: retired,
123
+ include_archived_projects: include_archived_projects
124
+ )
56
125
  end
57
- end
126
+ params = Params.new
58
127
 
59
- class Params < Hash
60
- def add_sort(sort)
61
- return unless sort
128
+ params.add_fields(fields)
129
+ params.add_sort(sort)
130
+ params.add_page(page, page_size)
131
+ params.add_options(retired, include_archived_projects)
132
+ new_filter = {}
133
+ if filter.is_a?(Hash)
134
+ new_filter[:conditions] =
135
+ (filter[:conditions] || translate_complex_to_sg_filters(filter))
136
+ new_filter[:logical_operator] = filter[:logical_operator] || filter['logical_operator'] || logical_operator
137
+ else
138
+ new_filter[:conditions] = filter
139
+ new_filter[:logical_operator] = logical_operator
140
+ end
141
+ filter = new_filter
62
142
 
63
- self[:sort] =
64
- if sort.is_a?(Hash)
65
- sort.map{ |field, direction| "#{direction.to_s.start_with?('desc') ? '-' : ''}#{field}" }.join(',')
143
+ resp =
144
+ @connection.post('_search', params) do |req|
145
+ if filter.is_a? Array
146
+ req.headers["Content-Type"] = 'application/vnd+shotgun.api3_array+json'
66
147
  else
67
- [sort].flatten.join(',')
148
+ req.headers['Content-Type'] = 'application/vnd+shotgun.api3_hash+json'
68
149
  end
69
- end
70
-
71
- def add_page(page, page_size)
72
- return unless page || page_size
73
-
74
- page = page.to_i if page
75
- page_size = page_size.to_i if page_size
150
+ req.body = params.to_h.merge(filters: filter).to_json
151
+ pp JSON.parse(req.body)
152
+ end
153
+ resp_body = JSON.parse(resp.body)
76
154
 
77
- page = 1 if page && page < 1
78
- self[:page] = { size: page_size || 20, number: page || 1 }
155
+ if resp.status >= 300
156
+ raise "Error while getting #{type}: #{resp_body['errors']}"
79
157
  end
80
158
 
81
- def add_fields(fields)
82
- self[:fields] = [fields].flatten.join(',') if fields
159
+ resp_body["data"].map do |entity|
160
+ Entity.new(
161
+ entity['type'],
162
+ OpenStruct.new(entity['attributes']),
163
+ entity['relationships'],
164
+ entity['id'],
165
+ entity['links']
166
+ )
83
167
  end
168
+ end
84
169
 
85
- def add_options(return_only, include_archived_projects)
86
- return if return_only.nil? && include_archived_projects.nil?
170
+ private
87
171
 
88
- self[:options] = {
89
- return_only: return_only ? 'retired' : 'active',
90
- include_archived_projects: !!include_archived_projects,
91
- }
92
- end
172
+ def filters_are_simple?(filters)
173
+ return false if filters.is_a? Array
93
174
 
94
- def add_filter(filters)
95
- return unless filters
175
+ filters.values.all? do |filter_val|
176
+ (filter_val.is_a?(Integer) || filter_val.is_a?(String) || filter_val.is_a?(Symbol)) ||
177
+ (filter_val.is_a?(Array) && filter_val.all?{ |val|
178
+ val.is_a?(String) || val.is_a?(Symbol) || val.is_a?(Integer)
179
+ } )
180
+ end
181
+ end
96
182
 
97
- # filter
98
- self['filter'] = filters.map do |field, value|
99
- [
100
- field.to_s,
101
- value.is_a?(Array) ? value.map(&:to_s).join(',') : value.to_s,
102
- ]
103
- end.to_h
183
+ def translate_complex_to_sg_filters(filters)
184
+ # We don't know how to translate anything but hashes
185
+ return filters if !filters.is_a?(Hash)
186
+
187
+ filters.each.with_object([]) do |item, result|
188
+ field, value = item
189
+ case value
190
+ when String, Symbol, Integer, Float
191
+ result << [field, "is", value]
192
+ when Hash
193
+ value.each do |subfield, subvalue|
194
+ sanitized_subfield = "#{field.capitalize}.#{subfield}" unless subfield.to_s.include?(".")
195
+ case subvalue
196
+ when String, Symbol, Integer, Float
197
+ result << ["#{field}.#{sanitized_subfield}", "is", subvalue]
198
+ when Array
199
+ result << ["#{field}.#{sanitized_subfield}", "in", subvalue]
200
+ else
201
+ raise "This case is too complex to auto-translate. Please use shotgun query syntax."
202
+ end
203
+ end
204
+ when Array
205
+ result << [field, "in", value]
206
+ else
207
+ raise "This case is too complex to auto-translate. Please use shotgun query syntax."
208
+ end
104
209
  end
105
210
  end
106
211
  end
@@ -0,0 +1,64 @@
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] =
29
+ if fields
30
+ [fields].flatten.join(',')
31
+ else
32
+ "*"
33
+ end
34
+ end
35
+
36
+ def add_options(return_only, include_archived_projects)
37
+ return if return_only.nil? && include_archived_projects.nil?
38
+
39
+ self[:options] = {
40
+ return_only: return_only ? 'retired' : 'active',
41
+ include_archived_projects: !!include_archived_projects,
42
+ }
43
+ end
44
+
45
+ def add_filter(filters)
46
+ return unless filters
47
+
48
+ # filter
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|
56
+ [
57
+ field.to_s,
58
+ value.is_a?(Array) ? value.map(&:to_s).join(',') : value.to_s,
59
+ ]
60
+ end.to_h
61
+ end
62
+ end
63
+ end
64
+ end
@@ -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) # rubocop:disable Style/OptionalBooleanParameter
18
18
  attributes.respond_to?(name) || super
19
19
  end
20
20
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShotgunApiRuby
4
+ class Preferences
5
+ def initialize(connection)
6
+ @connection = connection.dup
7
+ @connection.url_prefix = "#{@connection.url_prefix}/preferences"
8
+ end
9
+
10
+ attr_reader :connection
11
+
12
+ def all
13
+ resp = @connection.get
14
+ resp_body = JSON.parse(resp.body)
15
+
16
+ if resp.status >= 300
17
+ raise "Error while getting server preferences: #{resp_body['errors']}"
18
+ end
19
+
20
+ data = resp_body["data"]
21
+ OpenStruct.new(data)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShotgunApiRuby
4
+ class ServerInfo
5
+ def initialize(connection)
6
+ @connection = connection
7
+ end
8
+
9
+ attr_reader :connection
10
+
11
+ def get
12
+ resp = @connection.get
13
+ resp_body = JSON.parse(resp.body)
14
+
15
+ if resp.status >= 300
16
+ raise "Error while getting server infos: #{resp_body['errors']}"
17
+ end
18
+
19
+ data = resp_body["data"]
20
+ OpenStruct.new(data)
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ShotgunApiRuby
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.5"
5
5
  end
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.description = "Gem to facilitate the interaction with Shotgun's REST API."
15
15
  spec.homepage = "https://github.com/shotgunsoftware/shotgun_api_ruby"
16
16
  spec.license = "MIT"
17
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
17
18
 
18
19
  spec.metadata["homepage_uri"] = spec.homepage
19
20
  spec.metadata["source_code_uri"] = "https://github.com/shotgunsoftware/shotgun_api_ruby"
@@ -21,23 +22,26 @@ Gem::Specification.new do |spec|
21
22
 
22
23
  # Specify which files should be added to the gem when it is released.
23
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
- end
25
+ spec.files =
26
+ Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
27
29
  spec.bindir = "exe"
28
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
31
  spec.require_paths = ["lib"]
30
32
 
31
33
  spec.add_dependency "activesupport"
32
- spec.add_dependency "faraday", "~> 0.17"
34
+ spec.add_dependency "faraday", "~> 1"
33
35
  spec.add_dependency "zeitwerk", "~> 2.2"
34
36
 
35
- spec.add_development_dependency "bundler", "~> 2.0"
37
+ spec.add_development_dependency "bundler"
36
38
  spec.add_development_dependency "bundler-audit"
39
+ spec.add_development_dependency "dotenv"
37
40
  spec.add_development_dependency "overcommit"
38
41
  spec.add_development_dependency "pry"
39
- spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "rake"
40
43
  spec.add_development_dependency "rspec", "~> 3.0"
41
- spec.add_development_dependency "rubocop", "~> 0.75"
42
- spec.add_development_dependency "rubocop-performance", "~> 1.5"
44
+ spec.add_development_dependency "rubocop"
45
+ spec.add_development_dependency "rubocop-performance"
46
+ spec.add_development_dependency "solargraph"
43
47
  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.1
4
+ version: 0.0.5
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: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2020-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.17'
33
+ version: '1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.17'
40
+ version: '1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: zeitwerk
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '2.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler-audit
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: dotenv
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: overcommit
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -112,16 +126,16 @@ dependencies:
112
126
  name: rake
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - "~>"
129
+ - - ">="
116
130
  - !ruby/object:Gem::Version
117
- version: '10.0'
131
+ version: '0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - "~>"
136
+ - - ">="
123
137
  - !ruby/object:Gem::Version
124
- version: '10.0'
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rspec
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -140,30 +154,44 @@ dependencies:
140
154
  name: rubocop
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - "~>"
157
+ - - ">="
144
158
  - !ruby/object:Gem::Version
145
- version: '0.75'
159
+ version: '0'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - "~>"
164
+ - - ">="
151
165
  - !ruby/object:Gem::Version
152
- version: '0.75'
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop-performance
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
- - - "~>"
171
+ - - ">="
158
172
  - !ruby/object:Gem::Version
159
- version: '1.5'
173
+ version: '0'
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
- - - "~>"
178
+ - - ">="
165
179
  - !ruby/object:Gem::Version
166
- version: '1.5'
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: solargraph
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
167
195
  description: Gem to facilitate the interaction with Shotgun's REST API.
168
196
  email:
169
197
  - denis.pasin@autodesk.com
@@ -190,7 +218,10 @@ files:
190
218
  - lib/shotgun_api_ruby/auth.rb
191
219
  - lib/shotgun_api_ruby/client.rb
192
220
  - lib/shotgun_api_ruby/entities.rb
221
+ - lib/shotgun_api_ruby/entities/params.rb
193
222
  - lib/shotgun_api_ruby/entity.rb
223
+ - lib/shotgun_api_ruby/preferences.rb
224
+ - lib/shotgun_api_ruby/server_info.rb
194
225
  - lib/shotgun_api_ruby/version.rb
195
226
  - shotgun_api_ruby.gemspec
196
227
  homepage: https://github.com/shotgunsoftware/shotgun_api_ruby
@@ -199,7 +230,7 @@ licenses:
199
230
  metadata:
200
231
  homepage_uri: https://github.com/shotgunsoftware/shotgun_api_ruby
201
232
  source_code_uri: https://github.com/shotgunsoftware/shotgun_api_ruby
202
- post_install_message:
233
+ post_install_message:
203
234
  rdoc_options: []
204
235
  require_paths:
205
236
  - lib
@@ -207,15 +238,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
238
  requirements:
208
239
  - - ">="
209
240
  - !ruby/object:Gem::Version
210
- version: '0'
241
+ version: 2.5.0
211
242
  required_rubygems_version: !ruby/object:Gem::Requirement
212
243
  requirements:
213
244
  - - ">="
214
245
  - !ruby/object:Gem::Version
215
246
  version: '0'
216
247
  requirements: []
217
- rubygems_version: 3.0.3
218
- signing_key:
248
+ rubygems_version: 3.0.8
249
+ signing_key:
219
250
  specification_version: 4
220
251
  summary: Gem to interact easily with Shotgun REST api.
221
252
  test_files: []