File tree Expand file tree Collapse file tree 5 files changed +94
-0
lines changed Expand file tree Collapse file tree 5 files changed +94
-0
lines changed Original file line number Diff line number Diff line change 77# This is the patch to use slice in earler versions
88require 'flagsmith/hash_slice'
99
10+ require 'flagsmith/version'
11+
1012require 'flagsmith/sdk/analytics_processor'
1113require 'flagsmith/sdk/api_client'
1214require 'flagsmith/sdk/config'
1315require 'flagsmith/sdk/errors'
1416require 'flagsmith/sdk/intervals'
17+ require 'flagsmith/sdk/utils'
1518require 'flagsmith/sdk/pooling_manager'
1619require 'flagsmith/sdk/models/flags'
1720require 'flagsmith/sdk/models/segments'
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ def build_headers(faraday, config)
3131 faraday . headers [ 'Accept' ] = 'application/json'
3232 faraday . headers [ 'Content-Type' ] = 'application/json'
3333 faraday . headers [ 'X-Environment-Key' ] = config . environment_key
34+ faraday . headers [ 'User-Agent' ] = Flagsmith ::SDK ::Utils . user_agent
3435 faraday . headers . merge ( config . custom_headers )
3536 end
3637
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ module Flagsmith
4+ module SDK
5+ # Utility functions
6+ module Utils
7+ FLAGSMITH_USER_AGENT = 'flagsmith-ruby-sdk'
8+ FLAGSMITH_UNKNOWN_VERSION = 'unknown'
9+
10+ module_function
11+
12+ # Returns the user agent string for HTTP requests
13+ # @return [String] user agent in format "flagsmith-ruby-sdk/version"
14+ def user_agent
15+ "#{ FLAGSMITH_USER_AGENT } /#{ version } "
16+ end
17+
18+ # Returns the SDK version
19+ # @return [String] version string or 'unknown' if not available
20+ def version
21+ return Flagsmith ::VERSION if defined? ( Flagsmith ::VERSION )
22+
23+ FLAGSMITH_UNKNOWN_VERSION
24+ rescue StandardError
25+ FLAGSMITH_UNKNOWN_VERSION
26+ end
27+ end
28+ end
29+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require 'spec_helper'
4+
5+ RSpec . describe Flagsmith ::ApiClient do
6+ let ( :config ) do
7+ Flagsmith ::Config . new (
8+ environment_key : 'test-key' ,
9+ api_url : 'https://edge.api.flagsmith.com/api/v1/'
10+ )
11+ end
12+
13+ describe 'headers' do
14+ it 'sets User-Agent header with SDK version' do
15+ api_client = described_class . new ( config )
16+ connection = api_client . instance_variable_get ( :@conn )
17+
18+ expected_user_agent = "flagsmith-ruby-sdk/#{ Flagsmith ::VERSION } "
19+ expect ( connection . headers [ 'User-Agent' ] ) . to eq ( expected_user_agent )
20+ end
21+ end
22+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require 'spec_helper'
4+
5+ RSpec . describe Flagsmith ::SDK ::Utils do
6+ describe '.user_agent' do
7+ it 'returns user agent with version' do
8+ expected_user_agent = "flagsmith-ruby-sdk/#{ Flagsmith ::VERSION } "
9+ expect ( described_class . user_agent ) . to eq ( expected_user_agent )
10+ end
11+
12+ it 'includes the correct format' do
13+ user_agent = described_class . user_agent
14+ expect ( user_agent ) . to match ( /^flagsmith-ruby-sdk\/ \d +\. \d +\. \d +$/ )
15+ end
16+ end
17+
18+ describe '.version' do
19+ it 'returns the Flagsmith version' do
20+ expect ( described_class . version ) . to eq ( Flagsmith ::VERSION )
21+ end
22+
23+ it 'returns a non-empty string' do
24+ expect ( described_class . version ) . to be_a ( String )
25+ expect ( described_class . version ) . not_to be_empty
26+ end
27+
28+ context 'when VERSION constant is not available' do
29+ it 'returns unknown as fallback' do
30+ version_backup = Flagsmith ::VERSION
31+ Flagsmith . send ( :remove_const , :VERSION )
32+
33+ expect ( described_class . version ) . to eq ( 'unknown' )
34+
35+ Flagsmith . const_set ( :VERSION , version_backup )
36+ end
37+ end
38+ end
39+ end
You can’t perform that action at this time.
0 commit comments