Class: Google::Cloud::Vision::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/vision/service.rb

Overview

Represents the service to Vision, exposing the API calls.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, credentials, host: nil, timeout: nil, client_config: nil) ⇒ Service

Creates a new Service instance.



32
33
34
35
36
37
38
39
# File 'lib/google/cloud/vision/service.rb', line 32

def initialize project, credentials, host: nil, timeout: nil,
               client_config: nil
  @project = project
  @credentials = credentials
  @host = host || V1::ImageAnnotatorApi::SERVICE_ADDRESS
  @timeout = timeout
  @client_config = client_config || {}
end

Instance Attribute Details

#client_configObject

Returns the value of attribute client_config.



28
29
30
# File 'lib/google/cloud/vision/service.rb', line 28

def client_config
  @client_config
end

#credentialsObject

Returns the value of attribute credentials.



28
29
30
# File 'lib/google/cloud/vision/service.rb', line 28

def credentials
  @credentials
end

#hostObject

Returns the value of attribute host.



28
29
30
# File 'lib/google/cloud/vision/service.rb', line 28

def host
  @host
end

#mocked_serviceObject

Returns the value of attribute mocked_service.



64
65
66
# File 'lib/google/cloud/vision/service.rb', line 64

def mocked_service
  @mocked_service
end

#projectObject

Returns the value of attribute project.



28
29
30
# File 'lib/google/cloud/vision/service.rb', line 28

def project
  @project
end

#timeoutObject

Returns the value of attribute timeout.



28
29
30
# File 'lib/google/cloud/vision/service.rb', line 28

def timeout
  @timeout
end

Instance Method Details

#annotate(requests) ⇒ Object

Returns API::BatchAnnotateImagesResponse



72
73
74
75
76
# File 'lib/google/cloud/vision/service.rb', line 72

def annotate requests
  execute do
    service.batch_annotate_images requests, options: default_options
  end
end

#chan_credsObject



46
47
48
49
50
51
# File 'lib/google/cloud/vision/service.rb', line 46

def chan_creds
  return credentials if insecure?
  require "grpc"
  GRPC::Core::ChannelCredentials.new.compose \
    GRPC::Core::CallCredentials.new credentials.client.updater_proc
end

#channelObject



41
42
43
44
# File 'lib/google/cloud/vision/service.rb', line 41

def channel
  require "grpc"
  GRPC::Core::Channel.new host, nil, chan_creds
end

#insecure?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/google/cloud/vision/service.rb', line 66

def insecure?
  credentials == :this_channel_is_insecure
end

#inspectObject



78
79
80
# File 'lib/google/cloud/vision/service.rb', line 78

def inspect
  "#{self.class}(#{@project})"
end

#serviceObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/google/cloud/vision/service.rb', line 53

def service
  return mocked_service if mocked_service
  @service ||= \
    V1::ImageAnnotatorApi.new(
      service_path: host,
      channel: channel,
      timeout: timeout,
      client_config: client_config,
      app_name: "gcloud-ruby",
      app_version: Google::Cloud::Vision::VERSION)
end