shotgun_api_ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e2163b85f62993d2674a47792d3370ebcbf1a6c283e915c781bc27801868a172
4
+ data.tar.gz: e26ff2d7d7beae08aaa041f893bbb0f46eb44bd305313d576c2407a99a5e4123
5
+ SHA512:
6
+ metadata.gz: 5956601d851995c92204f03541b5c5e7e07a428df8170884d976b01388b1acfe4022d5781cea92510d6ef83e99ef25c5caa983b02a7d602267970afa3caf889f
7
+ data.tar.gz: 33c191b51f8ea193eedb15f5655b51d453173c41e86c0da1f8540e5d08c396e04522aa89fd8f66ea286ccf3d6df6bf3a28df4ddff6e5f77264cb1038bc6f1278
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.overcommit.yml ADDED
@@ -0,0 +1,12 @@
1
+ PreCommit:
2
+ RuboCop:
3
+ enabled: true
4
+ command: ['bundle', 'exec', 'rubocop'] # Invoke within Bundler context
5
+ BundleOutdated:
6
+ enabled: true
7
+ BundleAudit:
8
+ enabled: true
9
+ PrePush:
10
+ RSpec:
11
+ enabled: true
12
+ command: ['bundle', 'exec', 'rspec', '-f', 'p'] # Invoke within Bundler context
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,174 @@
1
+ # Relaxed.Ruby.Style
2
+ ## Version 2.4
3
+
4
+ Style/Alias:
5
+ Enabled: false
6
+ StyleGuide: https://relaxed.ruby.style/#stylealias
7
+
8
+ Style/AsciiComments:
9
+ Enabled: false
10
+ StyleGuide: https://relaxed.ruby.style/#styleasciicomments
11
+
12
+ Style/BeginBlock:
13
+ Enabled: false
14
+ StyleGuide: https://relaxed.ruby.style/#stylebeginblock
15
+
16
+ Style/BlockDelimiters:
17
+ Enabled: false
18
+ StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters
19
+
20
+ Style/CommentAnnotation:
21
+ Enabled: false
22
+ StyleGuide: https://relaxed.ruby.style/#stylecommentannotation
23
+
24
+ Style/Documentation:
25
+ Enabled: false
26
+ StyleGuide: https://relaxed.ruby.style/#styledocumentation
27
+
28
+ Layout/DotPosition:
29
+ Enabled: false
30
+ StyleGuide: https://relaxed.ruby.style/#layoutdotposition
31
+
32
+ Style/DoubleNegation:
33
+ Enabled: false
34
+ StyleGuide: https://relaxed.ruby.style/#styledoublenegation
35
+
36
+ Style/EndBlock:
37
+ Enabled: false
38
+ StyleGuide: https://relaxed.ruby.style/#styleendblock
39
+
40
+ Style/FormatString:
41
+ Enabled: false
42
+ StyleGuide: https://relaxed.ruby.style/#styleformatstring
43
+
44
+ Style/IfUnlessModifier:
45
+ Enabled: false
46
+ StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier
47
+
48
+ Style/Lambda:
49
+ Enabled: false
50
+ StyleGuide: https://relaxed.ruby.style/#stylelambda
51
+
52
+ Style/ModuleFunction:
53
+ Enabled: false
54
+ StyleGuide: https://relaxed.ruby.style/#stylemodulefunction
55
+
56
+ Style/MultilineBlockChain:
57
+ Enabled: false
58
+ StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain
59
+
60
+ Style/NegatedIf:
61
+ Enabled: false
62
+ StyleGuide: https://relaxed.ruby.style/#stylenegatedif
63
+
64
+ Style/NegatedWhile:
65
+ Enabled: false
66
+ StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile
67
+
68
+ Style/NumericPredicate:
69
+ Enabled: false
70
+ StyleGuide: https://relaxed.ruby.style/#stylenumericpredicate
71
+
72
+ Style/ParallelAssignment:
73
+ Enabled: false
74
+ StyleGuide: https://relaxed.ruby.style/#styleparallelassignment
75
+
76
+ Style/PercentLiteralDelimiters:
77
+ Enabled: false
78
+ StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters
79
+
80
+ Style/PerlBackrefs:
81
+ Enabled: false
82
+ StyleGuide: https://relaxed.ruby.style/#styleperlbackrefs
83
+
84
+ Style/Semicolon:
85
+ Enabled: false
86
+ StyleGuide: https://relaxed.ruby.style/#stylesemicolon
87
+
88
+ Style/SignalException:
89
+ Enabled: false
90
+ StyleGuide: https://relaxed.ruby.style/#stylesignalexception
91
+
92
+ Style/SingleLineBlockParams:
93
+ Enabled: false
94
+ StyleGuide: https://relaxed.ruby.style/#stylesinglelineblockparams
95
+
96
+ Style/SingleLineMethods:
97
+ Enabled: false
98
+ StyleGuide: https://relaxed.ruby.style/#stylesinglelinemethods
99
+
100
+ Layout/SpaceBeforeBlockBraces:
101
+ Enabled: false
102
+ StyleGuide: https://relaxed.ruby.style/#layoutspacebeforeblockbraces
103
+
104
+ Layout/SpaceInsideParens:
105
+ Enabled: false
106
+ StyleGuide: https://relaxed.ruby.style/#layoutspaceinsideparens
107
+
108
+ Style/SpecialGlobalVars:
109
+ Enabled: false
110
+ StyleGuide: https://relaxed.ruby.style/#stylespecialglobalvars
111
+
112
+ Style/StringLiterals:
113
+ Enabled: false
114
+ StyleGuide: https://relaxed.ruby.style/#stylestringliterals
115
+
116
+ Style/TrailingCommaInArguments:
117
+ Enabled: false
118
+ StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarguments
119
+
120
+ Style/TrailingCommaInArrayLiteral:
121
+ Enabled: false
122
+ StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarrayliteral
123
+
124
+ Style/TrailingCommaInHashLiteral:
125
+ Enabled: false
126
+ StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral
127
+
128
+ Style/SymbolArray:
129
+ Enabled: false
130
+ StyleGuide: http://relaxed.ruby.style/#stylesymbolarray
131
+
132
+ Style/WhileUntilModifier:
133
+ Enabled: false
134
+ StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier
135
+
136
+ Style/WordArray:
137
+ Enabled: false
138
+ StyleGuide: https://relaxed.ruby.style/#stylewordarray
139
+
140
+ Lint/AmbiguousRegexpLiteral:
141
+ Enabled: false
142
+ StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral
143
+
144
+ Lint/AssignmentInCondition:
145
+ Enabled: false
146
+ StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition
147
+
148
+ Metrics/AbcSize:
149
+ Enabled: false
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:
173
+ Enabled: false
174
+
data/.rubocop.yml ADDED
@@ -0,0 +1,64 @@
1
+ inherit_from:
2
+ - http://relaxed.ruby.style/rubocop.yml
3
+
4
+ require:
5
+ - rubocop-performance
6
+
7
+ AllCops:
8
+ DisplayStyleGuide: true
9
+ DisplayCopNames: true
10
+ Exclude:
11
+ - 'db/schema.rb'
12
+
13
+ Style/GlobalVars:
14
+ Enabled: false
15
+
16
+ Layout/DotPosition:
17
+ Enabled: true
18
+ EnforcedStyle: trailing
19
+
20
+ Style/TrailingCommaInArrayLiteral:
21
+ Enabled: true
22
+ EnforcedStyleForMultiline: comma
23
+
24
+ Style/TrailingCommaInHashLiteral:
25
+ Enabled: true
26
+ EnforcedStyleForMultiline: comma
27
+
28
+ Layout/MultilineArrayLineBreaks:
29
+ Enabled: true
30
+
31
+ Layout/MultilineHashKeyLineBreaks:
32
+ Enabled: true
33
+
34
+ Layout/MultilineMethodArgumentLineBreaks:
35
+ Enabled: true
36
+
37
+ Layout/FirstArrayElementLineBreak:
38
+ Enabled: true
39
+
40
+ Layout/FirstHashElementLineBreak:
41
+ Enabled: true
42
+
43
+ Layout/FirstMethodArgumentLineBreak:
44
+ Enabled: true
45
+
46
+ Layout/MultilineAssignmentLayout:
47
+ Enabled: true
48
+
49
+ Metrics/LineLength:
50
+ Enabled: true
51
+ Max: 120
52
+ AutoCorrect: true
53
+ Exclude:
54
+ - Gemfile
55
+ - Guardfile
56
+ - spec/interactors/send_gdpr_response_spec.rb
57
+
58
+ Metrics/BlockLength:
59
+ Exclude:
60
+ - 'spec/**/*.rb'
61
+ - 'Guardfile'
62
+ - 'config/environments/*.rb'
63
+ - 'lib/tasks/*.rake'
64
+ - 'shotgun_api_ruby.gemspec'
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ shotgun-ruby
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.5
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in shotgun_api_ruby.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shotgun_api_ruby (0.0.1)
5
+ activesupport
6
+ faraday (~> 0.17)
7
+ zeitwerk (~> 2.2)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (6.0.0)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ zeitwerk (~> 2.1, >= 2.1.8)
18
+ ast (2.4.0)
19
+ bundler-audit (0.6.1)
20
+ 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)
27
+ multipart-post (>= 1.2, < 3)
28
+ i18n (1.7.0)
29
+ 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
+ multipart-post (2.1.1)
35
+ overcommit (0.51.0)
36
+ childprocess (>= 0.6.3, < 4)
37
+ 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)
44
+ rainbow (3.0.0)
45
+ rake (10.5.0)
46
+ rspec (3.9.0)
47
+ rspec-core (~> 3.9.0)
48
+ rspec-expectations (~> 3.9.0)
49
+ rspec-mocks (~> 3.9.0)
50
+ rspec-core (3.9.0)
51
+ rspec-support (~> 3.9.0)
52
+ rspec-expectations (3.9.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.9.0)
55
+ rspec-mocks (3.9.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.9.0)
58
+ rspec-support (3.9.0)
59
+ rubocop (0.75.1)
60
+ jaro_winkler (~> 1.5.1)
61
+ parallel (~> 1.10)
62
+ parser (>= 2.6)
63
+ rainbow (>= 2.2.2, < 4.0)
64
+ ruby-progressbar (~> 1.7)
65
+ unicode-display_width (>= 1.4.0, < 1.7)
66
+ rubocop-performance (1.5.0)
67
+ rubocop (>= 0.71.0)
68
+ ruby-progressbar (1.10.1)
69
+ thor (0.20.3)
70
+ thread_safe (0.3.6)
71
+ tzinfo (1.2.5)
72
+ thread_safe (~> 0.1)
73
+ unicode-display_width (1.6.0)
74
+ zeitwerk (2.2.0)
75
+
76
+ PLATFORMS
77
+ ruby
78
+
79
+ DEPENDENCIES
80
+ bundler (~> 2.0)
81
+ bundler-audit
82
+ overcommit
83
+ pry
84
+ rake (~> 10.0)
85
+ rspec (~> 3.0)
86
+ rubocop (~> 0.75)
87
+ rubocop-performance (~> 1.5)
88
+ shotgun_api_ruby!
89
+
90
+ BUNDLED WITH
91
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Denis <Zaratan> Pasin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,233 @@
1
+ # ShotgunApiRuby
2
+
3
+ A gem to integrate with shotgun REST API easily.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'shotgun_api_ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install shotgun_api_ruby
20
+
21
+ ## Usage
22
+
23
+ ### Client instantiation
24
+
25
+ For creating a new client you need to provide two values.
26
+
27
+ - One to identify the shotgun site:
28
+ - Can be `shotgun_site`: which is the `xxx` part in `https://xxx.shotgunstudio.com`
29
+ - Can be `site_url`: which is the full url to your site
30
+ - One to `auth` you see _Authentication_ lower in this guide.
31
+
32
+ Example:
33
+
34
+ ```ruby
35
+ client = ShotgunApiRuby.new(shotgun_site: 'i-love-shotgun', auth: {client_id: 'my_nice_script', client_secret: 'CantTouchThis'})
36
+ ```
37
+
38
+ ### Authentication
39
+
40
+ Any kind of authentication specified [here](https://developer.shotgunsoftware.com/rest-api/#authentication) is implemented
41
+
42
+ #### Client Credentials
43
+
44
+ ```ruby
45
+ client = ShotgunApiRuby.new(shotgun_site: 'xxx', auth: {client_id: 'script_name', client_secret: 'script_secret'})
46
+ ```
47
+
48
+ #### Password Credentials
49
+
50
+ ```ruby
51
+ client = ShotgunApiRuby.new(shotgun_site: 'xxx', auth: {username: 'login', password: 'password'})
52
+ ```
53
+
54
+ #### Session Token
55
+
56
+ **We highly advise not using this for a long term script as this won't be a stable value over time**
57
+
58
+ ```ruby
59
+ client = ShotgunApiRuby.new(shotgun_site: 'xxx', auth: {session_token: 'session_token'})
60
+ ```
61
+
62
+ #### Refresh Token
63
+
64
+ **We highly advise not using this for a long term script as this won't be a stable value over time**
65
+
66
+ ```ruby
67
+ client = ShotgunApiRuby.new(shotgun_site: 'xxx', auth: {refresh_token: 'refresh_token'})
68
+ ```
69
+
70
+ ### Entities
71
+
72
+ Querying entities is done by accessing the named method
73
+
74
+ ```ruby
75
+ client.assets # => ShotgunApiRuby::Entities …
76
+ ```
77
+
78
+ As entities can be user defined the client will try to answer to any unknown type with an entity call so any of those calls will returns the same thing:
79
+
80
+ ```ruby
81
+ client.assets
82
+ client.asset
83
+ client.entities("Asset")
84
+ client.entities(:Assets)
85
+ ```
86
+
87
+ Any not yet implemented call can be accessed through the connection: `client.assets.connection`
88
+
89
+ #### Entity
90
+
91
+ Returned entity will try to behave as nicely as possible.
92
+
93
+ An entity will always answer to:
94
+
95
+ - .type : the type of the entity
96
+ - .id : the id of the entity
97
+ - .relationships : a hash of relationships
98
+ - .links : a hash of links to other entities
99
+ - .attributes : An object answering to any available attributes
100
+
101
+ It will also answer to any method that is present in the attributes:
102
+
103
+ ```ruby
104
+ assets = client.assets.all(fields: 'code')
105
+ assets.first.type # => "Asset"
106
+ assets.first.id # => 726
107
+ assets.first.attributes.code # => "Buck"
108
+ assets.first.code # => "Buck"
109
+ ```
110
+
111
+ #### Get
112
+
113
+ ##### all
114
+
115
+ The all call will return all possible entities.
116
+
117
+ ```ruby
118
+ client.assets.all
119
+ ```
120
+
121
+ ##### fields
122
+
123
+ This attribute describe the wanted fields in the returned entity
124
+
125
+ Can be a string describing wanted fields: `'code'` or `'code,description'`
126
+ Or an array for better readability: `[:code, 'description']`
127
+
128
+ Example:
129
+
130
+ ```ruby
131
+ client.assets.all(fields: [:code, :description])
132
+ ```
133
+
134
+ ##### sort
135
+
136
+ Describe how you want your entities to be sorted.
137
+
138
+ Can be either:
139
+
140
+ - A string: `'code'` or `'code,-description'` (the `-` asking for a descending order)
141
+ - An array for better readability: `[:code, '-description']`
142
+ - A hash for ease of use: `{code: 'asc', description: :desc}`
143
+
144
+ Example:
145
+
146
+ ```ruby
147
+ client.assets.all(fields: [:code, :description], sort: {code: :asc, description: :desc})
148
+ ```
149
+
150
+ ##### filter
151
+
152
+ **Complex filters are not implemented yet**
153
+
154
+ For simple filters, the filter field is waiting for a hash.
155
+
156
+ Each value is:
157
+
158
+ - A string: then a `is` filter will be used
159
+ - An array: then a `in` filter will be used
160
+
161
+ Example:
162
+
163
+ ```ruby
164
+ client.assets.all(fields: [:code, :description], filter: {code: ['Buck', :Darcy], description: 'I LOVE SG'})
165
+ ```
166
+
167
+ ##### page
168
+
169
+ You can ask for any page size or page number.
170
+
171
+ - `page`: set the page number.
172
+ - `page_size`: set the size of each page.
173
+
174
+ Any of the two can be omited. Their type should be a number but it'll work with a string
175
+
176
+ Example:
177
+
178
+ ```ruby
179
+ client.assets.all(fields: [:code], page: 3, page_size: 10)
180
+ client.assets.all(fields: [:code], page: '3')
181
+ client.assets.all(fields: [:code], page_size: 10)
182
+ ```
183
+
184
+ ##### options
185
+
186
+ Special options can be added:
187
+
188
+ - retired: a flag telling if the returned entities should be retired or not
189
+ - include_archived_projects: a flag telling if the archived projets should be included int the search
190
+
191
+ Example:
192
+
193
+ ```ruby
194
+ client.assets.all(fields: [:code], retired: true)
195
+ client.assets.all(fields: [:code], include_archived_projects: true)
196
+ ```
197
+
198
+ #### Create
199
+
200
+ Not implemented yet
201
+
202
+ #### Update
203
+
204
+ Not implemented yet
205
+
206
+ #### Delete
207
+
208
+ Not implemented yet
209
+
210
+ ### Non implemented calls
211
+
212
+ All calls which are not yet implemented can be done through the `connection` method. This method will still take care of the authentication for you.
213
+
214
+ ```ruby
215
+ client = ShotgunApiRuby.new(…)
216
+ client.connection.get('/entity/assets') # => #<Faraday::Response:xxx @on_complete_callbacks=[], @env=#<Faraday::Env @method=:get @body="{\"data\":[{\"type\":\"Asset\",\"attributes\":{},\"relationships\":{},\"id\":726 …
217
+ ```
218
+
219
+ ## Development
220
+
221
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
222
+
223
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
224
+
225
+ Every commit/push is checked by overcommit.
226
+
227
+ ## Contributing
228
+
229
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shotgunsoftware/shotgun_api_ruby.
230
+
231
+ ## License
232
+
233
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "shotgun_api_ruby"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "pry"
15
+ Pry.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+ overcommit --install
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShotgunApiRuby
4
+ class Auth < Faraday::Middleware
5
+ module Validator
6
+ def self.valid?(auth)
7
+ (auth[:client_id] && auth[:client_secret]) ||
8
+ (auth[:password] && auth[:username]) ||
9
+ auth[:session_token] ||
10
+ auth[:refresh_token]
11
+ end
12
+ end
13
+
14
+ def initialize(app = nil, options = {})
15
+ raise "missing auth" unless options[:auth]
16
+ raise "missing site_url" unless options[:site_url]
17
+ raise "Auth not valid" unless Validator.valid?(options[:auth])
18
+
19
+ super(app)
20
+
21
+ @site_url = options[:site_url]
22
+ @client_id = options[:auth][:client_id]
23
+ @client_secret = options[:auth][:client_secret]
24
+ @username = options[:auth][:username]
25
+ @password = options[:auth][:password]
26
+ @session_token = options[:auth][:session_token]
27
+ @refresh_token = options[:auth][:refresh_token]
28
+ end
29
+
30
+ attr_reader :client_id, :client_secret, :site_url, :username, :password, :session_token, :refresh_token
31
+
32
+ def auth_type
33
+ @auth_type ||=
34
+ begin
35
+ if client_id
36
+ 'client_credentials'
37
+ elsif username
38
+ 'password'
39
+ elsif session_token
40
+ 'session_token'
41
+ elsif refresh_token
42
+ 'refresh_token'
43
+ end
44
+ end
45
+ end
46
+
47
+ def call(request_env)
48
+ request_env[:request_headers].merge!(std_headers)
49
+
50
+ @app.call(request_env)
51
+ end
52
+
53
+ private
54
+
55
+ def auth_params
56
+ @auth_params ||=
57
+ begin
58
+ case auth_type
59
+ when 'client_credentials'
60
+ "client_id=#{client_id}&client_secret=#{client_secret}&grant_type=client_credentials"
61
+ when 'password'
62
+ "username=#{username}&password=#{password}&grant_type=password"
63
+ when 'session_token'
64
+ "session_token=#{session_token}&grant_type=session_token"
65
+ when 'refresh_token'
66
+ "refresh_token=#{refresh_token}&grant_type=refresh_token"
67
+ else
68
+ raise "Not a valid/implemented auth type"
69
+ end
70
+ end
71
+ end
72
+
73
+ def auth_url
74
+ @auth_url ||= "#{site_url}/auth/access_token?#{auth_params}"
75
+ end
76
+
77
+ def access_token
78
+ ((@access_token && Time.now < @token_expiry) || sign_in) && @access_token
79
+ end
80
+
81
+ def sign_in
82
+ resp =
83
+ Faraday.post(auth_url) do |req|
84
+ req.headers["Content-Type"] = 'application/x-www-form-urlencoded'
85
+ req.headers["Accept"] = "application/json"
86
+ end
87
+ resp_body = JSON.parse(resp.body)
88
+
89
+ raise "Can't login: #{resp_body['errors']}" if resp.status >= 300
90
+
91
+ @access_token = resp_body['access_token']
92
+ @token_expiry = Time.now + resp_body['expires_in']
93
+ @refresh_token = resp_body['refresh_token']
94
+ end
95
+
96
+ def std_headers
97
+ {
98
+ "Accept" => "application/json",
99
+ "Authorization" => "Bearer #{access_token}",
100
+ }
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShotgunApiRuby
4
+ class Client
5
+ attr_reader :connection
6
+
7
+ def initialize(auth:, site_url: nil, shotgun_site: nil)
8
+ raise "No site given" unless site_url || shotgun_site
9
+ raise "auth param not valid" unless auth && Auth::Validator.valid?(auth)
10
+
11
+ site_url ||= "https://#{shotgun_site}.shotgunstudio.com/api/v1"
12
+ @connection =
13
+ Faraday.new(url: site_url) do |faraday|
14
+ faraday.use(ShotgunApiRuby::Auth, auth: auth, site_url: site_url)
15
+ faraday.adapter Faraday.default_adapter
16
+ end
17
+ end
18
+
19
+ def entities(type)
20
+ public_send(type)
21
+ end
22
+
23
+ def respond_to_missing?(_name, _include_private = false)
24
+ true
25
+ end
26
+
27
+ def method_missing(name, *args, &block)
28
+ if args.empty?
29
+ name = formated_name(name)
30
+ define_singleton_method(name) do
31
+ if entities_client = instance_variable_get("@#{name}")
32
+ entities_client
33
+ else
34
+ entities_client = entities_aux(name)
35
+ instance_variable_set("@#{name}", entities_client)
36
+ end
37
+ end
38
+ send(name)
39
+ else
40
+ super
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def formated_name(name)
47
+ name.to_s.camelize.singularize
48
+ end
49
+
50
+ def entities_aux(type)
51
+ type = formated_name(type)
52
+ @entity_caller = Entities.new(connection, type)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShotgunApiRuby
4
+ class Entities
5
+ def initialize(connection, type)
6
+ @connection = connection.dup
7
+ @type = type
8
+ @connection.url_prefix = "#{@connection.url_prefix}/entity/#{type}"
9
+ end
10
+
11
+ attr_reader :connection, :type
12
+
13
+ def all(
14
+ fields: nil,
15
+ sort: nil,
16
+ filter: nil,
17
+ page: nil,
18
+ page_size: nil,
19
+ retired: nil,
20
+ include_archived_projects: nil
21
+ )
22
+ raise "Complex filters aren't supported yet" if filter && !filters_are_simple?(filter)
23
+
24
+ params = Params.new
25
+
26
+ params.add_fields(fields)
27
+ params.add_sort(sort)
28
+ params.add_filter(filter)
29
+ params.add_page(page, page_size)
30
+ params.add_options(retired, include_archived_projects)
31
+
32
+ resp = @connection.get('', params)
33
+ resp_body = JSON.parse(resp.body)
34
+
35
+ if resp.status >= 300
36
+ raise "Error while getting #{type}: #{resp_body['errors']}"
37
+ end
38
+
39
+ resp_body["data"].map do |entity|
40
+ Entity.new(
41
+ entity['type'],
42
+ OpenStruct.new(entity['attributes']),
43
+ entity['relationships'],
44
+ entity['id'],
45
+ entity['links']
46
+ )
47
+ end
48
+ end
49
+
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) })
56
+ end
57
+ end
58
+
59
+ class Params < Hash
60
+ def add_sort(sort)
61
+ return unless sort
62
+
63
+ self[:sort] =
64
+ if sort.is_a?(Hash)
65
+ sort.map{ |field, direction| "#{direction.to_s.start_with?('desc') ? '-' : ''}#{field}" }.join(',')
66
+ else
67
+ [sort].flatten.join(',')
68
+ 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
76
+
77
+ page = 1 if page && page < 1
78
+ self[:page] = { size: page_size || 20, number: page || 1 }
79
+ end
80
+
81
+ def add_fields(fields)
82
+ self[:fields] = [fields].flatten.join(',') if fields
83
+ end
84
+
85
+ def add_options(return_only, include_archived_projects)
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
93
+
94
+ def add_filter(filters)
95
+ return unless filters
96
+
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
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShotgunApiRuby
4
+ Entity =
5
+ Struct.new(:type, :attributes, :relationships, :id, :links) do
6
+ def method_missing(name, *args, &block)
7
+ if attributes.respond_to?(name)
8
+ define_singleton_method(name) do
9
+ attributes.public_send(name)
10
+ end
11
+ public_send(name)
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ def respond_to_missing?(name, _private_methods = false)
18
+ attributes.respond_to?(name) || super
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShotgunApiRuby
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # zeitwerk will take care of auto loading files based on their name :)
4
+ require "zeitwerk"
5
+ require 'active_support/core_ext/string/inflections'
6
+ require 'ostruct'
7
+ require "faraday"
8
+ require 'json'
9
+
10
+ loader = Zeitwerk::Loader.for_gem
11
+ loader.setup # ready!
12
+
13
+ module ShotgunApiRuby
14
+ def self.new(**args)
15
+ Client.new(**args)
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "shotgun_api_ruby/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "shotgun_api_ruby"
9
+ spec.version = ShotgunApiRuby::VERSION
10
+ spec.authors = ["Denis <Zaratan> Pasin"]
11
+ spec.email = ["denis.pasin@autodesk.com"]
12
+
13
+ spec.summary = 'Gem to interact easily with Shotgun REST api.'
14
+ spec.description = "Gem to facilitate the interaction with Shotgun's REST API."
15
+ spec.homepage = "https://github.com/shotgunsoftware/shotgun_api_ruby"
16
+ spec.license = "MIT"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/shotgunsoftware/shotgun_api_ruby"
20
+ # spec.metadata["changelog_uri"] = "http://none.yet.com"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # 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
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "activesupport"
32
+ spec.add_dependency "faraday", "~> 0.17"
33
+ spec.add_dependency "zeitwerk", "~> 2.2"
34
+
35
+ spec.add_development_dependency "bundler", "~> 2.0"
36
+ spec.add_development_dependency "bundler-audit"
37
+ spec.add_development_dependency "overcommit"
38
+ spec.add_development_dependency "pry"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "rubocop", "~> 0.75"
42
+ spec.add_development_dependency "rubocop-performance", "~> 1.5"
43
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shotgun_api_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Denis <Zaratan> Pasin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.17'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: zeitwerk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler-audit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: overcommit
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'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.75'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.75'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-performance
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.5'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.5'
167
+ description: Gem to facilitate the interaction with Shotgun's REST API.
168
+ email:
169
+ - denis.pasin@autodesk.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".overcommit.yml"
176
+ - ".rspec"
177
+ - ".rubocop-http---relaxed-ruby-style-rubocop-yml"
178
+ - ".rubocop.yml"
179
+ - ".ruby-gemset"
180
+ - ".ruby-version"
181
+ - ".travis.yml"
182
+ - Gemfile
183
+ - Gemfile.lock
184
+ - LICENSE.txt
185
+ - README.md
186
+ - Rakefile
187
+ - bin/console
188
+ - bin/setup
189
+ - lib/shotgun_api_ruby.rb
190
+ - lib/shotgun_api_ruby/auth.rb
191
+ - lib/shotgun_api_ruby/client.rb
192
+ - lib/shotgun_api_ruby/entities.rb
193
+ - lib/shotgun_api_ruby/entity.rb
194
+ - lib/shotgun_api_ruby/version.rb
195
+ - shotgun_api_ruby.gemspec
196
+ homepage: https://github.com/shotgunsoftware/shotgun_api_ruby
197
+ licenses:
198
+ - MIT
199
+ metadata:
200
+ homepage_uri: https://github.com/shotgunsoftware/shotgun_api_ruby
201
+ source_code_uri: https://github.com/shotgunsoftware/shotgun_api_ruby
202
+ post_install_message:
203
+ rdoc_options: []
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ requirements: []
217
+ rubygems_version: 3.0.3
218
+ signing_key:
219
+ specification_version: 4
220
+ summary: Gem to interact easily with Shotgun REST api.
221
+ test_files: []