Class: ShotgunApiRuby::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#connectionObject (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

#preferencesObject

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

Returns:

  • (Boolean)


38
39
40
# File 'lib/shotgun_api_ruby/client.rb', line 38

def respond_to_missing?(_name, _include_private = false)
  true
end

#server_infoObject

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