carddb 0.2.2 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,9 +41,21 @@ module CardDB
41
41
  # Default retry settings
42
42
  DEFAULT_MAX_RETRIES = 3
43
43
 
44
- # @return [String, nil] API key for authentication
44
+ # @return [String, nil] Legacy API key for authentication
45
45
  attr_accessor :api_key
46
46
 
47
+ # @return [String, nil] Browser-safe publishable API key for public reads
48
+ attr_accessor :publishable_key
49
+
50
+ # @return [String, nil] Server-side secret API key for trusted workflows
51
+ attr_accessor :secret_key
52
+
53
+ # @return [String, nil] OAuth bearer token for user-authorized requests
54
+ attr_accessor :access_token
55
+
56
+ # @return [String, nil] Client environment hint (`TEST` or `LIVE`)
57
+ attr_accessor :environment
58
+
47
59
  # @return [String] GraphQL endpoint URL
48
60
  attr_accessor :endpoint
49
61
 
@@ -93,6 +105,10 @@ module CardDB
93
105
  @timeout = DEFAULT_TIMEOUT
94
106
  @open_timeout = DEFAULT_OPEN_TIMEOUT
95
107
  @api_key = nil
108
+ @publishable_key = nil
109
+ @secret_key = nil
110
+ @access_token = nil
111
+ @environment = nil
96
112
  @default_publisher = nil
97
113
  @default_game = nil
98
114
  @allowed_publishers = nil
@@ -154,6 +170,16 @@ module CardDB
154
170
  validate_game!(publisher_slug, game_key) if publisher_slug && game_key
155
171
  end
156
172
 
173
+ def effective_api_key
174
+ api_key || publishable_key || secret_key
175
+ end
176
+
177
+ def require_secret_credential!(operation)
178
+ return if !access_token && (api_key || (secret_key && !publishable_key))
179
+
180
+ raise RestrictedError, "#{operation} requires a server-side secret_key or legacy api_key credential"
181
+ end
182
+
157
183
  # Resolves the publisher slug, using the default if not provided.
158
184
  #
159
185
  # @param publisher_slug [String, nil] The provided publisher slug
@@ -71,8 +71,11 @@ module CardDB
71
71
  f.headers['Accept'] = 'application/json'
72
72
  f.headers['User-Agent'] = "CardDB-SDK/ruby/#{CardDB::VERSION} (ruby/#{RUBY_VERSION})"
73
73
 
74
- # Set API key header if configured
75
- f.headers['X-API-Key'] = config.api_key if config.api_key
74
+ if config.access_token
75
+ f.headers['Authorization'] = "Bearer #{config.access_token}"
76
+ elsif config.effective_api_key
77
+ f.headers['X-API-Key'] = config.effective_api_key
78
+ end
76
79
 
77
80
  f.options.timeout = config.timeout
78
81
  f.options.open_timeout = config.open_timeout