Skip to content

Commit 0f80670

Browse files
committed
fix(ruby): add helper to add segment to user agent (generated)
algolia/api-clients-automation#3972 Co-authored-by: algolia-bot <[email protected]>
1 parent 54334b9 commit 0f80670

11 files changed

+96
-3
lines changed

lib/algolia/api/abtesting_client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ def self.create_with_config(config)
4545
# @return [void]
4646
def set_client_api_key(api_key)
4747
@api_client.set_client_api_key(api_key)
48+
49+
self
50+
end
51+
52+
def add_user_agent_segment(segment, version = nil)
53+
@api_client.config.add_user_agent_segment(segment, version)
54+
55+
self
4856
end
4957

5058
# Creates a new A/B test.

lib/algolia/api/analytics_client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ def self.create_with_config(config)
4545
# @return [void]
4646
def set_client_api_key(api_key)
4747
@api_client.set_client_api_key(api_key)
48+
49+
self
50+
end
51+
52+
def add_user_agent_segment(segment, version = nil)
53+
@api_client.config.add_user_agent_segment(segment, version)
54+
55+
self
4856
end
4957

5058
# This method allow you to send requests to the Algolia REST API.

lib/algolia/api/ingestion_client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ def self.create_with_config(config)
4545
# @return [void]
4646
def set_client_api_key(api_key)
4747
@api_client.set_client_api_key(api_key)
48+
49+
self
50+
end
51+
52+
def add_user_agent_segment(segment, version = nil)
53+
@api_client.config.add_user_agent_segment(segment, version)
54+
55+
self
4856
end
4957

5058
# Creates a new authentication resource.

lib/algolia/api/insights_client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ def self.create_with_config(config)
4545
# @return [void]
4646
def set_client_api_key(api_key)
4747
@api_client.set_client_api_key(api_key)
48+
49+
self
50+
end
51+
52+
def add_user_agent_segment(segment, version = nil)
53+
@api_client.config.add_user_agent_segment(segment, version)
54+
55+
self
4856
end
4957

5058
# This method allow you to send requests to the Algolia REST API.

lib/algolia/api/monitoring_client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ def self.create_with_config(config)
3030
# @return [void]
3131
def set_client_api_key(api_key)
3232
@api_client.set_client_api_key(api_key)
33+
34+
self
35+
end
36+
37+
def add_user_agent_segment(segment, version = nil)
38+
@api_client.config.add_user_agent_segment(segment, version)
39+
40+
self
3341
end
3442

3543
# This method allow you to send requests to the Algolia REST API.

lib/algolia/api/personalization_client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ def self.create_with_config(config)
4545
# @return [void]
4646
def set_client_api_key(api_key)
4747
@api_client.set_client_api_key(api_key)
48+
49+
self
50+
end
51+
52+
def add_user_agent_segment(segment, version = nil)
53+
@api_client.config.add_user_agent_segment(segment, version)
54+
55+
self
4856
end
4957

5058
# This method allow you to send requests to the Algolia REST API.

lib/algolia/api/query_suggestions_client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ def self.create_with_config(config)
4545
# @return [void]
4646
def set_client_api_key(api_key)
4747
@api_client.set_client_api_key(api_key)
48+
49+
self
50+
end
51+
52+
def add_user_agent_segment(segment, version = nil)
53+
@api_client.config.add_user_agent_segment(segment, version)
54+
55+
self
4856
end
4957

5058
# Creates a new Query Suggestions configuration. You can have up to 100 configurations per Algolia application.

lib/algolia/api/recommend_client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ def self.create_with_config(config)
3838
# @return [void]
3939
def set_client_api_key(api_key)
4040
@api_client.set_client_api_key(api_key)
41+
42+
self
43+
end
44+
45+
def add_user_agent_segment(segment, version = nil)
46+
@api_client.config.add_user_agent_segment(segment, version)
47+
48+
self
4149
end
4250

4351
# Create or update a batch of Recommend Rules Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same &#x60;objectID&#x60; already exists. You may also specify &#x60;true&#x60; for &#x60;clearExistingRules&#x60;, in which case the batch will atomically replace all the existing Recommend Rules. Recommend Rules are similar to Search Rules, except that the conditions and consequences apply to a [source item](/doc/guides/algolia-recommend/overview/#recommend-models) instead of a query. The main differences are the following: - Conditions &#x60;pattern&#x60; and &#x60;anchoring&#x60; are unavailable. - Condition &#x60;filters&#x60; triggers if the source item matches the specified filters. - Condition &#x60;filters&#x60; accepts numeric filters. - Consequence &#x60;params&#x60; only covers filtering parameters. - Consequence &#x60;automaticFacetFilters&#x60; doesn&#39;t require a facet value placeholder (it tries to match the data source item&#39;s attributes instead).

lib/algolia/api/search_client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ def self.create_with_config(config)
4141
# @return [void]
4242
def set_client_api_key(api_key)
4343
@api_client.set_client_api_key(api_key)
44+
45+
self
46+
end
47+
48+
def add_user_agent_segment(segment, version = nil)
49+
@api_client.config.add_user_agent_segment(segment, version)
50+
51+
self
4452
end
4553

4654
# Creates a new API key with specific permissions and restrictions.

lib/algolia/configuration.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ def initialize(app_id, api_key, hosts, client_name, opts = {})
3333

3434
@user_agent = UserAgent.new.add(client_name, VERSION)
3535

36+
if opts[:user_agent_segments]
37+
opts[:user_agent_segments].each do |segment|
38+
@user_agent.add(segment)
39+
end
40+
end
41+
3642
@header_params = {
3743
"X-Algolia-Application-Id" => app_id,
3844
"X-Algolia-API-Key" => api_key,
3945
"Content-Type" => "application/json",
40-
"User-Agent" => @user_agent
46+
"User-Agent" => @user_agent.value
4147
}
4248
@header_params.transform_keys!(&:downcase)
4349

@@ -47,11 +53,20 @@ def initialize(app_id, api_key, hosts, client_name, opts = {})
4753
def set_client_api_key(api_key)
4854
@api_key = api_key
4955
@header_params["X-Algolia-API-Key"] = api_key
56+
57+
self
5058
end
5159

5260
# The default Configuration object.
5361
def self.default
5462
@@default ||= Configuration.new
5563
end
64+
65+
def add_user_agent_segment(segment, version = nil)
66+
@user_agent.add(segment, version)
67+
@header_params["user-agent"] = @user_agent.value
68+
69+
self
70+
end
5671
end
5772
end

0 commit comments

Comments
 (0)