Skip to content

feat: Allow to pass a custom User-Agent#99

Merged
teolemon merged 3 commits intoopenfoodfacts:mainfrom
clavat:feat/add-user-agent
Sep 16, 2025
Merged

feat: Allow to pass a custom User-Agent#99
teolemon merged 3 commits intoopenfoodfacts:mainfrom
clavat:feat/add-user-agent

Conversation

@clavat
Copy link
Copy Markdown
Contributor

@clavat clavat commented Jun 10, 2025

Give the possibility to pass a custom User-Agent to the API calls.

Resolving this issue #88

@clavat clavat changed the title Allow to pass a custom User-Agent feat:Allow to pass a custom User-Agent Jun 10, 2025
@clavat clavat changed the title feat:Allow to pass a custom User-Agent feat: Allow to pass a custom User-Agent Jun 10, 2025
@teolemon teolemon requested a review from Copilot June 10, 2025 14:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for a custom User-Agent header by centralizing HTTP requests and replacing direct URI.open calls.

  • Introduce http_get wrapper that reads OPENFOODFACTS_USER_AGENT from the environment
  • Replace all URI.open invocations with Openfoodfacts.http_get
  • Bump Ruby version to 3.3.6 in .tool-versions

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/openfoodfacts.rb Add http_get method with User-Agent header
lib/openfoodfacts/product.rb Replace URI.open with http_get for get, search, and page parsing
lib/openfoodfacts/press.rb Replace URI.open with http_get in items
lib/openfoodfacts/mission.rb Replace URI.open with http_get in all and fetch
lib/openfoodfacts/locale.rb Replace URI.open with http_get in all
lib/openfoodfacts/faq.rb Replace URI.open with http_get in items
.tool-versions Specify Ruby 3.3.6
Comments suppressed due to low confidence (3)

lib/openfoodfacts.rb:43

  • The new http_get method is not covered by tests. Please add unit or integration tests to verify both successful responses and custom User-Agent behavior.
def http_get(url)

lib/openfoodfacts.rb:43

  • [nitpick] Document the OPENFOODFACTS_USER_AGENT environment variable in the README or project docs so users know how to set a custom header.
def http_get(url)

lib/openfoodfacts.rb:44

  • Missing require 'open-uri' in this file: without requiring open-uri, URI.parse(url).open will be undefined at runtime.
URI.parse(url).open("User-Agent" => ENV.fetch('OPENFOODFACTS_USER_AGENT', nil))

Comment thread lib/openfoodfacts.rb
@sonarqubecloud
Copy link
Copy Markdown

@teolemon
Copy link
Copy Markdown
Member

@clavat @VictorGosse ok to merge ?

@teolemon teolemon merged commit e4e70f4 into openfoodfacts:main Sep 16, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants