Class: Anvil::Configuration
- Inherits:
-
Object
- Object
- Anvil::Configuration
- Defined in:
- lib/anvil/configuration.rb
Constant Summary collapse
- ENVIRONMENTS =
i[development production].freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#graphql_url ⇒ Object
Returns the value of attribute graphql_url.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
- #webhook_token ⇒ Object
Instance Method Summary collapse
- #development? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #production? ⇒ Boolean
-
#rate_limit ⇒ Object
Rate limits based on environment and plan.
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
11 12 13 14 15 16 17 18 19 |
# File 'lib/anvil/configuration.rb', line 11 def initialize @environment = default_environment @base_url = 'https://app.useanvil.com/api/v1' @graphql_url = 'https://graphql.useanvil.com/' # GraphQL endpoint @timeout = 120 # Read timeout in seconds @open_timeout = 30 # Connection open timeout @api_key = ENV.fetch('ANVIL_API_KEY', nil) @webhook_token = ENV.fetch('ANVIL_WEBHOOK_TOKEN', nil) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/anvil/configuration.rb', line 7 def api_key @api_key end |
#base_url ⇒ Object
Returns the value of attribute base_url.
7 8 9 |
# File 'lib/anvil/configuration.rb', line 7 def base_url @base_url end |
#environment ⇒ Object
Returns the value of attribute environment.
8 9 10 |
# File 'lib/anvil/configuration.rb', line 8 def environment @environment end |
#graphql_url ⇒ Object
Returns the value of attribute graphql_url.
7 8 9 |
# File 'lib/anvil/configuration.rb', line 7 def graphql_url @graphql_url end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
7 8 9 |
# File 'lib/anvil/configuration.rb', line 7 def open_timeout @open_timeout end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/anvil/configuration.rb', line 7 def timeout @timeout end |
#webhook_token ⇒ Object
38 39 40 |
# File 'lib/anvil/configuration.rb', line 38 def webhook_token @webhook_token || ENV.fetch('ANVIL_WEBHOOK_TOKEN', nil) end |
Instance Method Details
#development? ⇒ Boolean
30 31 32 |
# File 'lib/anvil/configuration.rb', line 30 def development? environment == :development end |
#production? ⇒ Boolean
34 35 36 |
# File 'lib/anvil/configuration.rb', line 34 def production? environment == :production end |
#rate_limit ⇒ Object
Rate limits based on environment and plan
43 44 45 46 47 48 49 |
# File 'lib/anvil/configuration.rb', line 43 def rate_limit return 4 if development? # Default production rate limit # Can be overridden if needed for custom plans 4 end |
#validate! ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/anvil/configuration.rb', line 51 def validate! return unless api_key.nil? || api_key.empty? raise Anvil::ConfigurationError, " No API key configured. Please set your API key using one of these methods:\n\n 1. Rails initializer (config/initializers/anvil.rb):\n Anvil.configure do |config|\n config.api_key = Rails.application.credentials.anvil[:api_key]\n end\n\n 2. Environment variable:\n export ANVIL_API_KEY=\"your_api_key_here\"\n\n 3. Direct assignment:\n Anvil.api_key = \"your_api_key_here\"\n\n Get your API keys at: https://app.useanvil.com/organizations/settings/api\n ERROR\nend\n" |