chalk_ruby 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4fd0a5371c88110f52a5c065272d227414d4b0e51dde2404ef25d4ade9ed1da
4
- data.tar.gz: ea5a203ada4c2f203bba64b8fe6329648b0ddd616358ee39e5fea8d0f4423c1e
3
+ metadata.gz: be35291268749664bfdee468de9a997bd421f3b16683ffb847e12f3089f22e46
4
+ data.tar.gz: 3670d6543e87f11cee499ed8477729364e57a2072437ed798f1a721d7823e93d
5
5
  SHA512:
6
- metadata.gz: 903bc4377ae97bc37417e3ffd510b2a0aae0259f5b5062039f38707dc3d8f6e01279872e5531a855423d7fbe233e1f2819a9c3d4b4368370c4425f4dc4d4d661
7
- data.tar.gz: 2fa0ef1c0c242e3074eff668c36a7f143bbdfff865441a55419ca486348622bcfac91a8742ed2bce3ff82b6fc4ce48ea58a5781ada24185207b9ecf3bc62dc74
6
+ metadata.gz: 87b9e3a20075fda23a00ba5e38dc91827afcc18922b6b664e1fb31676623ce2d67627cd0d1a56831740fa03eeeaf99439841151073bfd1413b33e9811aa45281
7
+ data.tar.gz: 908b81be15e3c99571a7195f9464496b0f52bb5447f96728d82e2ed57365b5828dfef48c911a42d850ed9262a1bfb4c26b496cd7649e8a1512605c28a10a4c4f
data/.rubocop_todo.yml CHANGED
@@ -1,14 +1,3 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2019-12-12 11:07:55 +0100 using RuboCop version 0.77.0.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 1
10
1
  Style/Documentation:
11
2
  Exclude:
12
- - 'spec/**/*'
13
3
  - 'test/**/*'
14
- - 'lib/rubybundle/search_config.rb'
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Ruby client for ChalkRuby
4
4
 
5
+ https://rubygems.org/gems/chalk_ruby
6
+
5
7
  ## Getting Started
6
8
 
7
9
  First, install ChalkRuby Ruby API Client via the [RubyGems](https://rubygems.org/) package manager:
@@ -22,4 +24,4 @@ results = client.query(
22
24
 
23
25
  ## License
24
26
 
25
- The ChalkRuby Ruby API Client is an open-sourced software licensed under the [Apache 2 License](LICENSE.md).
27
+ The Chalk Ruby API Client is an open-sourced software licensed under the [Apache 2 License](LICENSE.md).
@@ -1,65 +1,51 @@
1
- require 'chalk_ruby/config/config'
1
+ require 'chalk_ruby/config'
2
2
  require 'chalk_ruby/logger_helper'
3
- require 'chalk_ruby/transport/transport'
3
+ require 'chalk_ruby/http/http_requester_chalk'
4
4
  require 'chalk_ruby/http/response'
5
+ require 'chalk_ruby/token'
5
6
 
6
7
  module ChalkRuby
7
- class Token
8
- attr_accessor :token, :expires_at, :environment, :engines
9
-
10
- # @param [Hash[String, untyped]] exchange_credentials_response
11
- def initialize(exchange_credentials_response)
12
- @token = exchange_credentials_response[:access_token]
13
- @expires_at = DateTime.parse(exchange_credentials_response[:expires_at])
14
- @environment = exchange_credentials_response[:primary_environment]
15
- @engines = exchange_credentials_response[:engines]
16
- end
17
-
18
- def expired?
19
- DateTime.now.advance({ seconds: 60 }) > @expires_at
20
- end
21
- end
22
-
23
8
  class Client
24
- # Initializes the Personalization client
9
+ # Create a new client.
25
10
  #
26
- # @param chalk_config [ChalkRuby::Config] a ChalkRuby::Config object which contains your APP_ID and API_KEY
27
- # @option adapter [Object] adapter object used for the connection
28
- # @option logger [Object]
29
- # @option http_requester [Object] http_requester object used for the connection
11
+ # @param client_id [String]
12
+ # Chalk client ID.
13
+ # If not provided, it will be read from the CHALK_CLIENT_ID environment variable.
30
14
  #
31
- def initialize(chalk_config, opts = {})
32
- @token = nil
33
- @config = chalk_config
34
- adapter = opts[:adapter] || Defaults::ADAPTER
35
- logger = opts[:logger] || LoggerHelper.create
36
- requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter: adapter, logger: logger)
37
- @transporter = Transport::Transport.new(requester: requester)
38
- end
39
-
40
- # Create a new client providing only app ID and API key
15
+ # @param client_secret [String]
16
+ # Chalk client secret.
17
+ # If not provided, it will be read from the CHALK_CLIENT_SECRET environment variable.
18
+ #
19
+ # @param environment [String]
20
+ # The Chalk environment id (not the name of the environment).
21
+ # If not provided, it will be read from the CHALK_ACTIVE_ENVIRONMENT environment variable.
41
22
  #
42
- # @param client_id [String] ChalkRuby application ID
43
- # @param client_secret [String] ChalkRuby API key
44
- # @param environment [String] ChalkRuby environment
45
- # @param query_server [String] ChalkRuby query server
46
- # @param api_server [String] ChalkRuby API server
23
+ # @param query_server [String]
24
+ # ChalkRuby query server
25
+ #
26
+ # @param api_server [String]
27
+ # ChalkRuby API server
28
+ #
29
+ # @param additional_headers [Hash[String, String]]
30
+ # Additional headers to be sent with every request. Typically not required.
47
31
  #
48
32
  # @return self
49
33
  #
50
34
  def self.create(
51
- client_id,
52
- client_secret,
35
+ client_id = nil,
36
+ client_secret = nil,
53
37
  environment = nil,
54
38
  query_server = nil,
55
- api_server = nil
39
+ api_server = nil,
40
+ additional_headers = {}
56
41
  )
57
42
  config = Config.new(
58
43
  client_id: client_id,
59
44
  client_secret: client_secret,
60
45
  environment: environment,
61
46
  query_server: query_server,
62
- api_server: api_server
47
+ api_server: api_server,
48
+ additional_headers: additional_headers
63
49
  )
64
50
  create_with_config(config)
65
51
  end
@@ -87,46 +73,137 @@ module ChalkRuby
87
73
  # is defined on the `User` namespace, and all features on the `User` namespace
88
74
  # (excluding has-one and has-many relationships) will be used as outputs.
89
75
  #
76
+ # @param now [DateTime?]
77
+ # The time at which to evaluate the query. If not specified, the current time will be used.
78
+ # This parameter is complex in the context of online_query since the online store
79
+ # only stores the most recent value of an entity's features. If `now` is in the past,
80
+ # it is extremely likely that `None` will be returned for cache-only features.
81
+ #
82
+ # This parameter is primarily provided to support:
83
+ # - controlling the time window for aggregations over cached has-many relationships
84
+ # - controlling the time window for aggregations over has-many relationships loaded from an
85
+ # external database
86
+ #
87
+ # If you are trying to perform an exploratory analysis of past feature values, prefer `offline_query`.
88
+ #
89
+ # @param staleness [Hash[String, String]?]
90
+ # Maximum staleness overrides for any output features or intermediate features.
91
+ # See https://docs.chalk.ai/docs/query-caching for more information.
92
+ #
93
+ # @param tags [Hash[String, String]?]
94
+ # The tags used to scope the resolvers.
95
+ # See https://docs.chalk.ai/docs/resolver-tags for more information.
96
+ #
97
+ # @param branch [String?]
98
+ # If specified, Chalk will route your request to the relevant branch.
99
+ #
100
+ # @param correlation_id [String?]
101
+ # You can specify a correlation ID to be used in logs and web interfaces.
102
+ # This should be globally unique, i.e. a `uuid` or similar. Logs generated
103
+ # during the execution of your query will be tagged with this correlation id.
104
+ #
105
+ # @param query_name [String?]
106
+ # The semantic name for the query you're making, for example, `"loan_application_model"`.
107
+ # Typically, each query that you make from your application should have a name.
108
+ # Chalk will present metrics and dashboard functionality grouped by 'query_name'.
109
+ #
110
+ # @param meta [Hash[String, String]?]
111
+ # Arbitrary `key:value` pairs to associate with a query.
112
+ #
113
+ # @param explain [Boolean?]
114
+ # Log the query execution plan. Requests using `explain=true` will be slower
115
+ # than requests using `explain=false`. If `"only"`, the query will not be executed,
116
+ # and only the query plan will be returned.
117
+ #
118
+ # If true, 'include_meta' will be set to true as well.
119
+ #
120
+ # @param include_meta [Boolean?]
121
+ # Whether to include metadata about the query execution.
122
+ #
123
+ # @param store_plan_stages [Boolean?]
124
+ # If `true`, the output of each of the query plan stages will be stored.
125
+ # This option dramatically impacts the performance of the query,
126
+ # so it should only be used for debugging.
90
127
  #
91
128
  # @return [Hash[Symbol, String]]
92
129
  #
93
130
  def query(
94
131
  input:,
95
132
  output:,
96
- # now,
97
- opts: {}
98
- # _staleness
133
+ now: nil,
134
+ staleness: nil,
135
+ tags: nil,
136
+ branch: nil,
137
+ correlation_id: nil,
138
+ query_name: nil,
139
+ meta: nil,
140
+ explain: nil,
141
+ include_meta: nil,
142
+ store_plan_stages: nil
99
143
  )
100
144
  query_server_request(
101
145
  method: :post,
102
146
  path: 'v1/query/online',
103
147
  body: {
104
148
  inputs: input,
105
- outputs: output
106
- # now: now
149
+ outputs: output,
150
+ now: now,
151
+ staleness: staleness,
152
+ context: tags && { tags: tags },
153
+ branch_id: branch,
154
+ correlation_id: correlation_id,
155
+ query_name: query_name,
156
+ meta: meta,
157
+ explain: explain || false,
158
+ include_meta: include_meta || false,
159
+ store_plan_stages: store_plan_stages || false
107
160
  },
108
- headers: get_authenticated_headers
161
+ headers: get_authenticated_engine_headers(branch: branch)
109
162
  )
110
163
  end
111
164
 
112
165
  def get_token
113
- response = api_server_request(
114
- method: :post,
115
- path: '/v1/oauth/token',
116
- body: {
117
- client_id: @config.client_id,
118
- client_secret: @config.client_secret,
119
- grant_type: 'client_credentials'
120
- },
121
- headers: get_unauthenticated_headers
166
+ Token.new(
167
+ api_server_request(
168
+ method: :post,
169
+ path: '/v1/oauth/token',
170
+ body: {
171
+ client_id: @config.client_id,
172
+ client_secret: @config.client_secret,
173
+ grant_type: 'client_credentials'
174
+ },
175
+ headers: get_unauthenticated_headers
176
+ )
122
177
  )
123
- Token.new(response)
178
+ end
179
+
180
+ # Initializes the ChalkRuby client. Generally, you should not need to call this directly.
181
+ # Instead, use ChalkRuby::Client.create or ChalkRuby::Client.create_with_config.
182
+ #
183
+ # @param chalk_config [ChalkRuby::Config]
184
+ # A ChalkRuby::Config object which contains your CLIENT_ID and CLIENT_SECRET
185
+ #
186
+ # @option adapter [Object]
187
+ # Adapter object used for the connection
188
+ #
189
+ # @option logger [Object]
190
+ #
191
+ # @option http_requester [Object]
192
+ # object used for the connection
193
+ #
194
+ def initialize(chalk_config, opts = {})
195
+ @token = nil
196
+ @config = chalk_config
197
+ adapter = opts[:adapter] || Defaults::ADAPTER
198
+ logger = opts[:logger] || LoggerHelper.create
199
+ requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter: adapter, logger: logger)
200
+ @transporter = Http::HttpRequesterChalk.new(requester: requester)
124
201
  end
125
202
 
126
203
  private
127
204
 
128
205
  def api_server_request(method:, path:, body:, headers:)
129
- @transporter.request_simple(
206
+ @transporter.send_request(
130
207
  method: method,
131
208
  host: @config.api_server,
132
209
  path: path,
@@ -138,7 +215,7 @@ module ChalkRuby
138
215
  end
139
216
 
140
217
  def query_server_request(method:, path:, body:, headers:)
141
- @transporter.request_simple(
218
+ @transporter.send_request(
142
219
  method: method,
143
220
  host: query_server_host,
144
221
  path: path,
@@ -149,22 +226,25 @@ module ChalkRuby
149
226
  )
150
227
  end
151
228
 
152
- def get_authenticated_headers
153
- t = valid_token
154
- {
229
+ def get_authenticated_engine_headers(branch:)
230
+ t = valid_token
231
+ tokens = {
155
232
  'Content-Type': 'application/json',
156
233
  'Accept': 'application/json',
157
234
  'Authorization': 'Bearer ' + t.token,
158
- 'X-ChalkRuby-Environment': @config.environment || t.environment
235
+ 'X-Chalk-Env-Id': @config.environment || t.environment,
236
+ 'X-Chalk-Branch-Id': branch,
237
+ 'X-Chalk-Deployment-Type': branch.nil? ? 'engine' : 'branch'
159
238
  }
239
+ tokens.merge(@config.additional_headers)
160
240
  end
161
241
 
162
242
  def get_unauthenticated_headers
163
243
  {
164
244
  'Content-Type': 'application/json',
165
245
  'Accept': 'application/json',
166
- 'X-ChalkRuby-Environment': @config.environment
167
- }
246
+ 'X-Chalk-Env-Id': @config.environment
247
+ }.merge(@config.additional_headers)
168
248
  end
169
249
 
170
250
  def query_server_host
@@ -187,6 +267,5 @@ module ChalkRuby
187
267
  @token
188
268
  end
189
269
  end
190
-
191
270
  end
192
271
  end
@@ -0,0 +1,61 @@
1
+ require 'faraday'
2
+ require 'chalk_ruby/defaults'
3
+
4
+ module ChalkRuby
5
+ class Config
6
+ attr_accessor :client_id,
7
+ :client_secret,
8
+ :query_server,
9
+ :api_server,
10
+ :environment,
11
+ :query_timeout,
12
+ :api_timeout,
13
+ :connect_timeout,
14
+ :additional_headers
15
+
16
+ # Creates a new ChalkRuby::Config object for use with ChalkRuby::Client.
17
+ #
18
+ # @option options [String?] :client_id
19
+ # The Chalk client ID.
20
+ # If not provided, it will be read from the CHALK_CLIENT_ID environment variable.
21
+ #
22
+ # @option options [String?] :client_secret
23
+ # Chalk client secret.
24
+ # If not provided, it will be read from the CHALK_CLIENT_SECRET environment variable.
25
+ #
26
+ # @option options [String?] :query_host
27
+ # The query server to use.
28
+ # If not provided, it will be read from the CHALK_QUERY_SERVER environment variable.
29
+ #
30
+ # @option options [String?] :api_host
31
+ # The API server to use.
32
+ # If not provided, it will be read from the CHALK_API_SERVER environment variable.
33
+ #
34
+ # @option options [Integer?] :read_timeout
35
+ # The timeout for read operations (in seconds).
36
+ #
37
+ # @option options [Integer?] :write_timeout
38
+ # The timeout for write operations (in seconds).
39
+ #
40
+ # @option options [Integer?] :connect_timeout
41
+ # The timeout for connect operations (in seconds).
42
+ #
43
+ # @option options [Hash<String, String>?] :additional_headers
44
+ # Additional headers to be sent with every request. Typically not required.
45
+ #
46
+ def initialize(opts = {})
47
+ @client_id = opts[:client_id] || ENV['CHALK_CLIENT_ID']
48
+ @client_secret = opts[:client_secret] || ENV['CHALK_CLIENT_SECRET']
49
+ @environment = opts[:environment] || ENV['CHALK_ACTIVE_ENVIRONMENT']
50
+ @query_server = opts[:query_server] || ENV['CHALK_QUERY_SERVER'] || Defaults::QUERY_SERVER
51
+ @api_server = opts[:api_server] || ENV['CHALK_API_SERVER'] || Defaults::API_SERVER
52
+ @query_timeout = opts[:query_timeout] || Defaults::API_TIMEOUT
53
+ @api_timeout = opts[:api_timeout] || Defaults::QUERY_TIMEOUT
54
+ @connect_timeout = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
55
+ @additional_headers = opts[:additional_headers] || {}
56
+
57
+ raise ChalkError, 'No Client ID provided, please set :client_id' if @client_id.nil?
58
+ raise ChalkError, 'No Client Secret provided, please set :client_secret' if @client_secret.nil?
59
+ end
60
+ end
61
+ end
@@ -2,14 +2,14 @@ require 'chalk_ruby/http/http_requester'
2
2
 
3
3
  module ChalkRuby
4
4
  module Defaults
5
- REQUESTER_CLASS = ChalkRuby::Http::HttpRequester
5
+ REQUESTER_CLASS = Http::HttpRequester
6
6
  ADAPTER = 'net_http_persistent'
7
7
 
8
8
  # HTTP Headers
9
9
  # ----------------------------------------
10
- HEADER_CLIENT_ID = 'X-ChalkRuby-Client-Id'.freeze
11
- HEADER_CLIENT_SECRET = 'X-ChalkRuby-Client-Secret'.freeze
12
- HEADER_ENVIRONMENT = 'X-ChalkRuby-Env-Id'.freeze
10
+ HEADER_CLIENT_ID = 'X-Chalk-Client-Id'.freeze
11
+ HEADER_CLIENT_SECRET = 'X-Chalk-Client-Secret'.freeze
12
+ HEADER_ENVIRONMENT = 'X-Chalk-Env-Id'.freeze
13
13
  AUTHORIZATION_HEADER = 'Authorization'.freeze
14
14
  USER_AGENT = "ChalkRuby Ruby (#{ChalkRuby::VERSION}), Ruby (#{RUBY_VERSION})"
15
15
 
@@ -27,9 +27,9 @@ module ChalkRuby
27
27
 
28
28
  # HTTP TIMEOUTS
29
29
  # ----------------------------------------
30
- CONNECT_TIMEOUT = 2
31
- API_TIMEOUT = 10
32
- QUERY_TIMEOUT = 120
30
+ CONNECT_TIMEOUT = 100
31
+ API_TIMEOUT = 300
32
+ QUERY_TIMEOUT = 1200
33
33
 
34
34
  WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY = 100
35
35
  end
@@ -40,6 +40,5 @@ module ChalkRuby
40
40
  def self.included(base)
41
41
  base.extend(Helpers)
42
42
  end
43
-
44
43
  end
45
44
  end
@@ -27,7 +27,7 @@ module ChalkRuby
27
27
  # @param timeout [Integer]
28
28
  # @param connect_timeout [Integer]
29
29
  #
30
- # @return [Http::Response]
30
+ # @return [Response]
31
31
  #
32
32
  def send_request(
33
33
  host:,
@@ -57,24 +57,23 @@ module ChalkRuby
57
57
  if ENV['CHALK_DEBUG']
58
58
  @logger.info("Request succeeded. Response status: #{response.status}, body: #{response.body}")
59
59
  end
60
- return Http::Response.new(status: response.status, body: response.body, headers: response.headers)
60
+ return Response.new(status: response.status, body: response.body, headers: response.headers)
61
61
  end
62
62
 
63
63
  if ENV['CHALK_DEBUG']
64
64
  @logger.info("Request failed. Response status: #{response.status}, error: #{response.body}")
65
65
  end
66
- Http::Response.new(status: response.status, error: response.body, headers: response.headers)
66
+ Response.new(status: response.status, error: response.body, headers: response.headers)
67
67
  rescue Faraday::TimeoutError => e
68
68
  if ENV['CHALK_DEBUG']
69
69
  @logger.info("Request timed out. Error: #{e.message}")
70
70
  end
71
- Http::Response.new(error: e.message, has_timed_out: true)
71
+ Response.new(error: e.message, has_timed_out: true)
72
72
  rescue ::StandardError => e
73
73
  if ENV['CHALK_DEBUG']
74
74
  @logger.info("Request failed. Error: #{e.message}")
75
75
  end
76
- Http::Response.new(error: e.message, network_failure: true)
77
-
76
+ Response.new(error: e.message, network_failure: true)
78
77
  end
79
78
 
80
79
  # Retrieve the connection from the @connections
@@ -88,7 +87,6 @@ module ChalkRuby
88
87
  f.adapter @adapter.to_sym
89
88
  end
90
89
  end
91
-
92
90
  end
93
91
  end
94
92
  end
@@ -4,8 +4,8 @@ require 'faraday/net_http_persistent' unless Faraday::VERSION < '1'
4
4
  require 'chalk_ruby/error'
5
5
 
6
6
  module ChalkRuby
7
- module Transport
8
- class Transport
7
+ module Http
8
+ class HttpRequesterChalk
9
9
  include Helpers
10
10
 
11
11
  # @param requester [ChalkRuby::Http::HttpRequester] requester used for sending requests.
@@ -14,7 +14,7 @@ module ChalkRuby
14
14
  @http_requester = requester
15
15
  end
16
16
 
17
- def request_simple(method:, host:, path:, timeout:, connect_timeout:, headers:, body:)
17
+ def send_request(method:, host:, path:, timeout:, connect_timeout:, headers:, body:)
18
18
  response = @http_requester.send_request(
19
19
  host: host,
20
20
  method: method,
@@ -48,7 +48,6 @@ module ChalkRuby
48
48
  def success?(http_response_code:)
49
49
  !http_response_code.nil? && (http_response_code.to_i / 100).floor == 2
50
50
  end
51
-
52
51
  end
53
52
  end
54
53
  end
@@ -0,0 +1,18 @@
1
+ module ChalkRuby
2
+ class Token
3
+ attr_accessor :token, :expires_at, :environment, :engines
4
+
5
+ # @param [Hash[String, untyped]] exchange_credentials_response
6
+ def initialize(exchange_credentials_response)
7
+ @token = exchange_credentials_response[:access_token]
8
+ @expires_at = DateTime.parse(exchange_credentials_response[:expires_at])
9
+ @environment = exchange_credentials_response[:primary_environment]
10
+ @engines = exchange_credentials_response[:engines]
11
+ end
12
+
13
+ def expired?
14
+ DateTime.now.advance({ seconds: 60 }) > @expires_at
15
+ end
16
+ end
17
+ end
18
+
@@ -1,3 +1,3 @@
1
1
  module ChalkRuby
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
data/lib/chalk_ruby.rb CHANGED
@@ -1,12 +1,11 @@
1
- # ChalkRuby module
2
1
  module ChalkRuby
3
2
  require 'chalk_ruby/version'
4
3
  require 'chalk_ruby/helpers'
5
4
  require 'chalk_ruby/http/http_requester'
6
5
  require 'chalk_ruby/defaults'
7
- require 'chalk_ruby/config/config'
6
+ require 'chalk_ruby/config'
8
7
  require 'chalk_ruby/http/response'
9
- require 'chalk_ruby/transport/transport'
8
+ require 'chalk_ruby/http/http_requester_chalk'
10
9
  require 'chalk_ruby/client'
11
10
  require 'chalk_ruby/error'
12
11
  require 'chalk_ruby/logger_helper'
@@ -2,24 +2,40 @@ module ChalkRuby
2
2
  class Client
3
3
  @config: Config
4
4
  @token: Token?
5
- @transporter: Transport::Transport
5
+ @transporter: Http::HttpRequesterChalk
6
6
 
7
- def self.create: -> Client
7
+ def self.create: (
8
+ String? client_id,
9
+ String? client_secret,
10
+ String? environment,
11
+ String? query_server,
12
+ String? api_server,
13
+ Hash[String, String]? additional_headers
14
+ ) -> Client
8
15
 
9
16
  def self.create_with_config: -> Client
10
17
 
11
18
  def get_token: -> Token
12
19
 
13
20
  def query: (
14
- ::Hash[Symbol|String, untyped] input,
21
+ Hash[Symbol | String, untyped] input,
15
22
  [String] output,
16
- Time? now,
17
- ?::Hash[String, String] staleness
23
+ now: Time?,
24
+ staleness: Hash[String, String],
25
+ tags: [String]?,
26
+ branch: String?,
27
+ correlation_id: String?,
28
+ query_name: String?,
29
+ meta: Hash[String, String]?,
30
+ explain: bool,
31
+ include_meta: bool,
32
+ store_plan_stages: bool
18
33
  ) -> Hash[Symbol, untyped]
19
34
 
20
35
  private
21
36
 
22
- def get_authenticated_headers: -> Hash[Symbol, String | nil]
37
+ def get_authenticated_engine_headers: (String? branch) -> Hash[Symbol, String | nil]
38
+
23
39
  def get_unauthenticated_headers: -> Hash[Symbol, String | nil]
24
40
 
25
41
  def query_server_host: -> String
@@ -1,5 +1,6 @@
1
1
  module ChalkRuby
2
2
  class Config
3
+ attr_accessor additional_headers: Hash[String, String]?
3
4
  attr_accessor client_id: String
4
5
  attr_accessor client_secret: String
5
6
 
@@ -14,15 +15,16 @@ module ChalkRuby
14
15
  attr_accessor connect_timeout: Integer
15
16
 
16
17
  type options = {
17
- client_id: String,
18
- client_secret: String,
19
- environment: String,
20
- api_server: String,
21
- query_server: String,
22
- query_timeout: Integer,
23
- api_timeout: Integer,
24
- connect_timeout: Integer,
25
- compression_type: String
18
+ client_id: String?,
19
+ client_secret: String?,
20
+ environment: String?,
21
+ api_server: String?,
22
+ query_server: String?,
23
+ query_timeout: Integer?,
24
+ api_timeout: Integer?,
25
+ connect_timeout: Integer?,
26
+ compression_type: String?,
27
+ additional_headers: Hash[String, String]?
26
28
  }
27
29
 
28
30
  def initialize: (options opts) -> void
@@ -1,6 +1,6 @@
1
1
  module ChalkRuby
2
2
  module Defaults
3
- REQUESTER_CLASS : Http::HttpRequester
3
+ REQUESTER_CLASS : untyped
4
4
  ADAPTER : String
5
5
 
6
6
  # HTTP Headers
@@ -1,9 +1,9 @@
1
1
  module ChalkRuby
2
- module Transport
3
- class Transport
2
+ module Http
3
+ class HttpRequesterChalk
4
4
  @http_requester: Http::HttpRequester
5
5
 
6
- def request_simple: (
6
+ def send_request: (
7
7
  Symbol method,
8
8
  String host,
9
9
  String path,
@@ -3,9 +3,8 @@ require 'rspec/autorun'
3
3
  require 'chalk_ruby/client'
4
4
  require 'chalk_ruby/error'
5
5
 
6
- CLIENT_ID = 'token-941b776a2245c2f5bb3bbdbcf582dce4'
7
- CLIENT_SECRET = 'ts-f76b5a517fce9a53d47bd91db5fbc31ac7718a27f0555d4ad9387557a9313a0b'
8
-
6
+ CLIENT_ID = ''
7
+ CLIENT_SECRET = ''
9
8
 
10
9
  RSpec.describe 'Online query' do
11
10
  it 'should accept valid queries' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chalk_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chalk AI, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-08 00:00:00.000000000 Z
11
+ date: 2024-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -214,26 +214,27 @@ files:
214
214
  - chalk_ruby.gemspec
215
215
  - lib/chalk_ruby.rb
216
216
  - lib/chalk_ruby/client.rb
217
- - lib/chalk_ruby/config/config.rb
217
+ - lib/chalk_ruby/config.rb
218
218
  - lib/chalk_ruby/defaults.rb
219
219
  - lib/chalk_ruby/error.rb
220
220
  - lib/chalk_ruby/helpers.rb
221
221
  - lib/chalk_ruby/http/http_requester.rb
222
+ - lib/chalk_ruby/http/http_requester_chalk.rb
222
223
  - lib/chalk_ruby/http/response.rb
223
224
  - lib/chalk_ruby/logger_helper.rb
224
- - lib/chalk_ruby/transport/transport.rb
225
+ - lib/chalk_ruby/token.rb
225
226
  - lib/chalk_ruby/version.rb
226
227
  - renovate.json
227
228
  - sig/chalk_ruby/client.rbs
228
- - sig/chalk_ruby/config/config.rbs
229
+ - sig/chalk_ruby/config.rbs
229
230
  - sig/chalk_ruby/defaults.rbs
230
231
  - sig/chalk_ruby/error.rbs
231
232
  - sig/chalk_ruby/helpers.rbs
233
+ - sig/chalk_ruby/http/_connection.rbs
232
234
  - sig/chalk_ruby/http/http_requester.rbs
235
+ - sig/chalk_ruby/http/http_requester_chalk.rbs
233
236
  - sig/chalk_ruby/http/response.rbs
234
- - sig/chalk_ruby/interfaces/_connection.rbs
235
237
  - sig/chalk_ruby/token.rbs
236
- - sig/chalk_ruby/transport/transport.rbs
237
238
  - sig/chalk_ruby/versions.rbs
238
239
  - test/chalk_ai/integration/client_test.rb
239
240
  - test/chalk_ai/test_helper.rb
@@ -1,39 +0,0 @@
1
- require 'faraday'
2
- require 'chalk_ruby/defaults'
3
-
4
- module ChalkRuby
5
- class Config
6
- attr_accessor :client_id,
7
- :client_secret,
8
- :query_server,
9
- :api_server,
10
- :environment,
11
- :query_timeout,
12
- :api_timeout,
13
- :connect_timeout
14
-
15
- #
16
- # @option options [String] :client_id
17
- # @option options [String] :client_secret
18
- # @option options [String] :query_host
19
- # @option options [String] :api_host
20
- # @option options [Integer] :read_timeout
21
- # @option options [Integer] :write_timeout
22
- # @option options [Integer] :connect_timeout
23
- #
24
- def initialize(opts = {})
25
- @client_id = opts[:client_id] || ENV['CHALK_CLIENT_ID']
26
- @client_secret = opts[:client_secret] || ENV['CHALK_CLIENT_SECRET']
27
- @environment = opts[:environment] || ENV['CHALK_ACTIVE_ENVIRONMENT']
28
- @query_server = opts[:query_server] || ENV['CHALK_QUERY_SERVER'] || Defaults::QUERY_SERVER
29
- @api_server = opts[:api_server] || ENV['CHALK_API_SERVER'] || Defaults::API_SERVER
30
- @query_timeout = opts[:query_timeout] || Defaults::API_TIMEOUT
31
- @api_timeout = opts[:api_timeout] || Defaults::QUERY_TIMEOUT
32
- @connect_timeout = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
33
-
34
- raise ChalkError, 'No Client ID provided, please set :client_id' if @client_id.nil?
35
- raise ChalkError, 'No Client Secret provided, please set :client_secret' if @client_secret.nil?
36
- end
37
-
38
- end
39
- end