Class: ShotgunApiRuby::Client
- Inherits:
-
Object
- Object
- ShotgunApiRuby::Client
- Defined in:
- lib/shotgun_api_ruby/client.rb
Overview
Main class for connection.
This should be only instanciated once to re-use tokens
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Faraday connection.
Instance Method Summary collapse
-
#entities(type) ⇒ Object
Access entities related APIs.
-
#initialize(auth:, site_url: nil, shotgun_site: nil) ⇒ Client
constructor
A new instance of Client.
- #method_missing(name, *args, &block) ⇒ Object
-
#preferences ⇒ Object
Access preferences APIs.
- #respond_to_missing?(_name, _include_private = false) ⇒ Boolean
-
#server_info ⇒ Object
Access server_info APIs.
Constructor Details
#initialize(auth:, site_url: nil, shotgun_site: nil) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/shotgun_api_ruby/client.rb', line 11 def initialize(auth:, site_url: nil, shotgun_site: nil) raise 'No site given' unless site_url || shotgun_site raise 'auth param not valid' unless auth && Auth::Validator.valid?(**auth) site_url ||= "https://#{shotgun_site}.shotgunstudio.com/api/v1" @connection = Faraday.new(url: site_url) do |faraday| faraday.use(ShotgunApiRuby::Auth, auth: auth, site_url: site_url) faraday.adapter Faraday.default_adapter end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/shotgun_api_ruby/client.rb', line 42 def method_missing(name, *args, &block) if args.empty? fname = formated_name(name) self .class .define_method(fname) do if entities_client = instance_variable_get("@#{fname}") entities_client else entities_client = entities_aux(fname) instance_variable_set("@#{fname}", entities_client) end end self.class.instance_eval { alias_method name, fname } send(fname) else super end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Faraday connection
9 10 11 |
# File 'lib/shotgun_api_ruby/client.rb', line 9 def connection @connection end |
Instance Method Details
#entities(type) ⇒ Object
Access entities related APIs
34 35 36 |
# File 'lib/shotgun_api_ruby/client.rb', line 34 def entities(type) public_send(type) end |
#preferences ⇒ Object
Access preferences APIs
24 25 26 |
# File 'lib/shotgun_api_ruby/client.rb', line 24 def preferences @preferences = Preferences.new(connection) end |
#respond_to_missing?(_name, _include_private = false) ⇒ Boolean
38 39 40 |
# File 'lib/shotgun_api_ruby/client.rb', line 38 def respond_to_missing?(_name, _include_private = false) true end |
#server_info ⇒ Object
Access server_info APIs
29 30 31 |
# File 'lib/shotgun_api_ruby/client.rb', line 29 def server_info @server_info || ServerInfo.new(connection) end |