Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make dotenv optional #29

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
ruby-version: 3.1

- name: Install Bundler
run: gem install bundler -v 2.4.22
run: gem install bundler -v 2.5.23

- name: Install dependencies
run: bundle _2.4.22_ install
run: bundle _2.5.23_ install

- name: Run tests
run: export MAILERLITE_API_TOKEN=dummy_token && bundle exec rspec spec/*rspec.rb
6 changes: 3 additions & 3 deletions .github/workflows/publish_gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
- name: Set up Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 3.0
ruby-version: 3.1

- name: Install Bundler
run: gem install bundler -v 2.4.22
run: gem install bundler -v 2.5.23

- name: Install dependencies
run: bundle _2.4.22_ install
run: bundle _2.5.23_ install

- name: Release Gem
if: contains(github.ref, 'refs/tags/v')
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 3.1
SuggestExtensions: false
NewCops: enable

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.0.0] - 2024-12-11
- *BREAKING CHANGE* - Please check the README file, dotenv is now optional
- *BREAKING CHANGE* - Updated the minimal required Ruby version from 2.5 to 3.1

## [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
16 changes: 8 additions & 8 deletions mailerlite-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
spec.description = "MailerLite's official Ruby SDK. Interacts with all endpoints at MailerLite API."
spec.homepage = 'https://www.MailerLite.com'
spec.license = 'MIT'
spec.required_ruby_version = '>= 2.5.0'
spec.required_ruby_version = '>= 3.1'

spec.metadata['allowed_push_host'] = 'https://rubygems.org'

Expand All @@ -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_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_development_dependency 'bundler', '~> 2.5'
spec.add_development_dependency 'rake', '~> 13.2'
spec.add_development_dependency 'rubocop', '~> 1.69'
spec.add_dependency 'dotenv', '~> 3.1'
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
Loading