Skip to content

Commit

Permalink
fix(ruby): add helper to add segment to user agent (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3972

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
  • Loading branch information
algolia-bot committed Oct 15, 2024
1 parent 54334b9 commit 0f80670
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/algolia/api/abtesting_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def self.create_with_config(config)
# @return [void]
def set_client_api_key(api_key)
@api_client.set_client_api_key(api_key)

self
end

def add_user_agent_segment(segment, version = nil)
@api_client.config.add_user_agent_segment(segment, version)

self
end

# Creates a new A/B test.
Expand Down
8 changes: 8 additions & 0 deletions lib/algolia/api/analytics_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def self.create_with_config(config)
# @return [void]
def set_client_api_key(api_key)
@api_client.set_client_api_key(api_key)

self
end

def add_user_agent_segment(segment, version = nil)
@api_client.config.add_user_agent_segment(segment, version)

self
end

# This method allow you to send requests to the Algolia REST API.
Expand Down
8 changes: 8 additions & 0 deletions lib/algolia/api/ingestion_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def self.create_with_config(config)
# @return [void]
def set_client_api_key(api_key)
@api_client.set_client_api_key(api_key)

self
end

def add_user_agent_segment(segment, version = nil)
@api_client.config.add_user_agent_segment(segment, version)

self
end

# Creates a new authentication resource.
Expand Down
8 changes: 8 additions & 0 deletions lib/algolia/api/insights_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def self.create_with_config(config)
# @return [void]
def set_client_api_key(api_key)
@api_client.set_client_api_key(api_key)

self
end

def add_user_agent_segment(segment, version = nil)
@api_client.config.add_user_agent_segment(segment, version)

self
end

# This method allow you to send requests to the Algolia REST API.
Expand Down
8 changes: 8 additions & 0 deletions lib/algolia/api/monitoring_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def self.create_with_config(config)
# @return [void]
def set_client_api_key(api_key)
@api_client.set_client_api_key(api_key)

self
end

def add_user_agent_segment(segment, version = nil)
@api_client.config.add_user_agent_segment(segment, version)

self
end

# This method allow you to send requests to the Algolia REST API.
Expand Down
8 changes: 8 additions & 0 deletions lib/algolia/api/personalization_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def self.create_with_config(config)
# @return [void]
def set_client_api_key(api_key)
@api_client.set_client_api_key(api_key)

self
end

def add_user_agent_segment(segment, version = nil)
@api_client.config.add_user_agent_segment(segment, version)

self
end

# This method allow you to send requests to the Algolia REST API.
Expand Down
8 changes: 8 additions & 0 deletions lib/algolia/api/query_suggestions_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def self.create_with_config(config)
# @return [void]
def set_client_api_key(api_key)
@api_client.set_client_api_key(api_key)

self
end

def add_user_agent_segment(segment, version = nil)
@api_client.config.add_user_agent_segment(segment, version)

self
end

# Creates a new Query Suggestions configuration. You can have up to 100 configurations per Algolia application.
Expand Down
8 changes: 8 additions & 0 deletions lib/algolia/api/recommend_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def self.create_with_config(config)
# @return [void]
def set_client_api_key(api_key)
@api_client.set_client_api_key(api_key)

self
end

def add_user_agent_segment(segment, version = nil)
@api_client.config.add_user_agent_segment(segment, version)

self
end

# 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).
Expand Down
8 changes: 8 additions & 0 deletions lib/algolia/api/search_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ def self.create_with_config(config)
# @return [void]
def set_client_api_key(api_key)
@api_client.set_client_api_key(api_key)

self
end

def add_user_agent_segment(segment, version = nil)
@api_client.config.add_user_agent_segment(segment, version)

self
end

# Creates a new API key with specific permissions and restrictions.
Expand Down
17 changes: 16 additions & 1 deletion lib/algolia/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ def initialize(app_id, api_key, hosts, client_name, opts = {})

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

if opts[:user_agent_segments]
opts[:user_agent_segments].each do |segment|
@user_agent.add(segment)
end
end

@header_params = {
"X-Algolia-Application-Id" => app_id,
"X-Algolia-API-Key" => api_key,
"Content-Type" => "application/json",
"User-Agent" => @user_agent
"User-Agent" => @user_agent.value
}
@header_params.transform_keys!(&:downcase)

Expand All @@ -47,11 +53,20 @@ def initialize(app_id, api_key, hosts, client_name, opts = {})
def set_client_api_key(api_key)
@api_key = api_key
@header_params["X-Algolia-API-Key"] = api_key

self
end

# The default Configuration object.
def self.default
@@default ||= Configuration.new
end

def add_user_agent_segment(segment, version = nil)
@user_agent.add(segment, version)
@header_params["user-agent"] = @user_agent.value

self
end
end
end
10 changes: 8 additions & 2 deletions lib/algolia/user_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ def initialize

# Adds a segment to the UserAgent
#
def add(segment, version)
@value += format("; %<segment>s (%<version>s)", segment: segment, version: version)
def add(segment, version = nil)
if version.nil?
@value += format("; %<segment>s", segment: segment)
else
@value += format("; %<segment>s (%<version>s)", segment: segment, version: version)
end

self
end
end
end

0 comments on commit 0f80670

Please sign in to comment.