Skip to content

Commit

Permalink
feat: make dotenv optional
Browse files Browse the repository at this point in the history
  • Loading branch information
dinomh committed Dec 11, 2024
1 parent 48d59a7 commit cb9d97c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [2.0.0] - 2024-12-11
- *BREAKING CHANGE* - Please check the README file, dotenv is now optional

## [1.0.6] - 2024-12-06
- Page parameter to cursor pagination fix

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ You will have to initalize it in your Ruby file with `require "mailerlite-ruby"`

# Usage

This SDK requires that you either have `.env` file with `MAILERLITE_API_TOKEN` env variable or that your variable is enabled system wide (useful for Docker/Kubernetes). The example of how `MAILERLITE_API_TOKEN` should look like is in `.env.example`.
This SDK requires that you have the `MAILERLITE_API_TOKEN` environment variable set. You can set this variable in a `.env` file or enable it system-wide (useful for Docker/Kubernetes). The example of how `MAILERLITE_API_TOKEN` should look like is in `.env.example`.

If you want to use `dotenv` to manage your environment variables, you can configure the `mailerlite` gem to load `dotenv`:

```ruby
MailerLite.configure do |config|
config.use_dotenv = true
end
```

## Subscribers

Expand Down
20 changes: 15 additions & 5 deletions lib/mailerlite/client.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
# frozen_string_literal: true

require 'http'
require 'dotenv/load'

MAILERLITE_API_URL = 'https://connect.mailerlite.com/api'

Dotenv.require_keys('MAILERLITE_API_TOKEN')

# mailerlite-ruby is a gem that integrates all endpoints from MailerLite API
module MailerLite
attr_reader :api_token

class << self
attr_accessor :use_dotenv

def configure
yield self
end
end

# Inits the client.
class Client
def initialize(api_token = ENV.fetch('MAILERLITE_API_TOKEN', nil))
@api_token = api_token
def initialize
if MailerLite.use_dotenv
require 'dotenv'
Dotenv.load
Dotenv.require_keys('MAILERLITE_API_TOKEN')
end
@api_token = ENV.fetch('MAILERLITE_API_TOKEN', nil)
end

def headers
Expand Down
2 changes: 1 addition & 1 deletion lib/mailerlite/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module MailerLite
VERSION = '1.0.6'
VERSION = '2.0.0'
end
12 changes: 6 additions & 6 deletions mailerlite-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '~> 2.4.1'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.7'
spec.add_development_dependency 'bundler', '~> 2.5'
spec.add_development_dependency 'rake', '~> 13.2'
spec.add_development_dependency 'rubocop', '~> 1.69'
spec.add_dependency 'dotenv', '~> 2.7'
spec.add_dependency 'http', '~> 5.0'
spec.add_dependency 'json', '~> 2.5'
spec.add_dependency 'uri', '~> 0.13.0'
spec.add_dependency 'http', '~> 5.2'
spec.add_dependency 'json', '~> 2.9'
spec.add_dependency 'uri', '~> 1.0'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'vcr'
Expand Down

0 comments on commit cb9d97c

Please sign in to comment.