Class: ChalkRuby::Client
- Inherits:
-
Object
- Object
- ChalkRuby::Client
- Defined in:
- lib/chalk_ruby/client.rb
Class Method Summary collapse
-
.create(client_id = nil, client_secret = nil, environment = nil, query_server = nil, api_server = nil, additional_headers = {}) ⇒ Object
Create a new client.
-
.create_with_config(config) ⇒ Object
Create a new client providing only a ChalkRuby::Config object.
Instance Method Summary collapse
- #get_token ⇒ Object
-
#initialize(chalk_config, opts = {}) ⇒ Client
constructor
Initializes the ChalkRuby client.
-
#query(input:, output:, now: nil, staleness: nil, tags: nil, branch: nil, correlation_id: nil, query_name: nil, query_name_version: nil, meta: nil, explain: nil, include_meta: nil, store_plan_stages: nil, timeout: nil, planner_options: nil) ⇒ Hash[Symbol, String]
Compute features values using online resolvers.
Constructor Details
#initialize(chalk_config, opts = {}) ⇒ Client
Initializes the ChalkRuby client. Generally, you should not need to call this directly. Instead, use ChalkRuby::Client.create or ChalkRuby::Client.create_with_config.
209 210 211 212 213 214 215 216 |
# File 'lib/chalk_ruby/client.rb', line 209 def initialize(chalk_config, opts = {}) @token = nil @config = chalk_config adapter = opts[:adapter] || Defaults::ADAPTER logger = opts[:logger] || LoggerHelper.create requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter: adapter, logger: logger) @transporter = Http::HttpRequesterChalk.new(requester: requester) end |
Class Method Details
.create(client_id = nil, client_secret = nil, environment = nil, query_server = nil, api_server = nil, additional_headers = {}) ⇒ Object
Create a new client.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/chalk_ruby/client.rb', line 34 def self.create( client_id = nil, client_secret = nil, environment = nil, query_server = nil, api_server = nil, additional_headers = {} ) config = Config.new( client_id: client_id, client_secret: client_secret, environment: environment, query_server: query_server, api_server: api_server, additional_headers: additional_headers ) create_with_config(config) end |
.create_with_config(config) ⇒ Object
Create a new client providing only a ChalkRuby::Config object
59 60 61 |
# File 'lib/chalk_ruby/client.rb', line 59 def self.create_with_config(config) new(config) end |
Instance Method Details
#get_token ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/chalk_ruby/client.rb', line 180 def get_token Token.new( api_server_request( method: :post, path: '/v1/oauth/token', body: { client_id: @config.client_id, client_secret: @config.client_secret, grant_type: 'client_credentials' }, headers: get_unauthenticated_headers ) ) end |
#query(input:, output:, now: nil, staleness: nil, tags: nil, branch: nil, correlation_id: nil, query_name: nil, query_name_version: nil, meta: nil, explain: nil, include_meta: nil, store_plan_stages: nil, timeout: nil, planner_options: nil) ⇒ Hash[Symbol, String]
Compute features values using online resolvers. See https://docs.chalk.ai/docs/query-basics for more information.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/chalk_ruby/client.rb', line 139 def query( input:, output:, now: nil, staleness: nil, tags: nil, branch: nil, correlation_id: nil, query_name: nil, query_name_version: nil, meta: nil, explain: nil, include_meta: nil, store_plan_stages: nil, timeout: nil, planner_options: nil ) query_server_request( method: :post, path: 'v1/query/online', body: { inputs: input, outputs: output, now: now, staleness: staleness, context: && { tags: }, branch_id: branch, correlation_id: correlation_id, query_name: query_name, query_name_version: query_name_version, meta: , explain: explain || false, include_meta: || false, store_plan_stages: store_plan_stages || false, planner_options: || {} }, headers: get_authenticated_engine_headers(branch: branch), timeout: timeout ) end |