Class: StabilitySDK::DashboardClient

Inherits:
Object
  • Object
show all
Defined in:
lib/stability_sdk/dashboard_client.rb

Constant Summary collapse

DEFAULT_API_HOST =
"grpc.stability.ai:443"

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DashboardClient

Returns a new instance of DashboardClient.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/stability_sdk/dashboard_client.rb', line 8

def initialize(options={})
  host = options[:api_host] || DEFAULT_API_HOST
  channel_creds = options.has_key?(:ca_cert) ? GRPC::Core::ChannelCredentials.new(options[:ca_cert]) : GRPC::Core::ChannelCredentials.new
  call_creds = GRPC::Core::CallCredentials.new(proc { { "authorization" => "Bearer #{options[:api_key]}" } })
  creds = channel_creds.compose(call_creds)

  stub_params = {}
  [:channel_override, :timeout, :propagate_mask, :channel_args, :interceptors].each do |kw|
    stub_params[kw] = options[kw] if options.has_key?(kw)
  end

  @stub = Gooseai::DashboardService::Stub.new(host, creds, **stub_params)
end

Instance Method Details

#get_meObject



22
23
24
# File 'lib/stability_sdk/dashboard_client.rb', line 22

def get_me
  @stub.get_me(Gooseai::EmptyRequest.new)
end

#get_organizationObject



26
27
28
29
# File 'lib/stability_sdk/dashboard_client.rb', line 26

def get_organization
  me = self.get_me
  @stub.get_organization(Gooseai::GetChargesRequest.new(organization_id: me.organizations[0].organization.id))
end