jpalumickas / mailerlite-ruby Goto Github PK
View Code? Open in Web Editor NEWRuby wrapper for MailerLite API v2
License: MIT License
Ruby wrapper for MailerLite API v2
License: MIT License
First, thank you so much for this gem. It's way better than my HTTParty-based client.
I've exchanged a few emails with MailerLite about their "Classic" API and several endpoints are broken. I know webhooks
and campaigns_by_status
specifically return 404. And subscriber_activities
is returning a 500 error.
Even though the "Classic" API has a V1 and V2, they say they are launching a V2 API and pointed me to new docs:
Here’s the documentation for the New version, some endpoints from the Classic are not available yet: https://mailerlite.github.io/reference/#mailerlite-api
They change the base URL to https://connect.mailerlite.com/api
and have only rolled out some of the endpoints, with no ETA for completion, even for specific milestones like webhooks
.
This is mostly just a heads-up that their current API is pretty broken and they don't seem to be maintaining it while they work on V2.
If you're still willing to maintain this repo, I'd love to help, maybe add in support for the new API with fallbacks to the old.
Faraday gem has finally released their v1 this year. Any plans to upgrade to it?
Hello,
Do you realy have a good reason to lock faraday to very old version? Faraday 0.10 was released 3 years ago.
Hi there,
Firstly, it's been really easy to work with with your gem - good documentation and examples and a clear API. Thanks!
I ran into a problem while removing a subscriber from a group. This endpoint/method:
client.delete_group_subscriber(group_id, email)
A subscriber with a google +
style email (e.g. [email protected]) can't be removed from a group. My guess is that the +
gets converted (at their end) into a space.
The solution that worked for me locally was to CGI::escape
the email before I pass it to delete_group_subscriber
, however it feels to me like this would be more nicely handled in the gem.
I had a look at the code, and while I'm confident I can make the change, I'm less confident that I'll catch all instances across the codebase where this is a problem and to know how to write a good spec that fits in with the style you already have.
Also, do you want this change in your gem, or would you rather a documentation change that recommends users escape their email before passing it in?
I'm happy to work on this, just would appreciate your thoughts before ploughing on!
Hi,
We've been using the Mailerlite gem for a while, but since 14-01-2021, we see quite some "Connection reset by peer - SSL_connect" errors.
The call is made from sidekiq, so they are retried automatically and most of the time succeed the second time.
Around 1 in 5 requests fails with this error.
ruby v2.7.1
mailerlite v1.12.0
See backtrace below:
/home/ubuntu/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/net/protocol.rb:44connect_nonblock |
/home/ubuntu/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/net/protocol.rb:44ssl_socket_connect |
/home/ubuntu/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/net/http.rb:1009connect |
lib/httplog/adapters/net_http.rb:37 connect |
/home/ubuntu/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/net/http.rb:943do_start |
/home/ubuntu/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/net/http.rb:932 start |
lib/faraday/adapter/net_http.rb:144 request_via_get_method |
lib/faraday/adapter/net_http.rb:135 request_with_wrapped_block |
lib/faraday/adapter/net_http.rb:128 perform_request |
lib/faraday/adapter/net_http.rb:70 block in call |
lib/faraday/adapter.rb:60 connection |
lib/faraday/adapter/net_http.rb:68 call |
lib/faraday/response.rb:11 call |
lib/faraday_middleware/response_middleware.rb:36 call |
lib/faraday/response.rb:11 call |
lib/faraday/response.rb:11 call |
lib/faraday/response.rb:11 call |
lib/faraday_middleware/response/follow_redirects.rb:79perform_with_redirection |
lib/faraday_middleware/response/follow_redirects.rb:67 call |
lib/faraday_middleware/request/encode_json.rb:26 call |
lib/faraday/rack_builder.rb:153 build_response |
lib/faraday/connection.rb:492 run_request |
lib/faraday/connection.rb:198 get |
lib/mailerlite/connection.rb:40 request |
lib/mailerlite/connection.rb:22 get |
lib/mailerlite/clients/subscribers.rb:75 search_subscribers |
app/services/mailerlite_services/sync.rb:62 sync_save |
app/services/mailerlite_services/sync.rb:25 call |
app/services/sync_with_mailerlite_worker.rb:11 perform |
lib/sidekiq/processor.rb:196 execute_job |
lib/sidekiq/processor.rb:164 block (2 levels) in process |
lib/sidekiq/middleware/chain.rb:138 block in invoke |
lib/i18n.rb:313 with_locale |
lib/sidekiq/middleware/i18n.rb:22 call |
lib/sidekiq/middleware/chain.rb:140 block in invoke |
lib/appsignal/hooks/sidekiq.rb:46 block in call |
lib/appsignal/helpers/instrumentation.rb:461 instrument |
lib/appsignal/hooks/sidekiq.rb:44 call |
lib/sidekiq/middleware/chain.rb:140 block in invoke |
request_store-sidekiq (0.1.0) lib/request_store/sidekiq/server_middleware.rb:5 call |
lib/sidekiq/middleware/chain.rb:140 block in invoke |
sidekiq-pro (5.2.0) lib/sidekiq/batch/middleware.rb:54 call |
lib/sidekiq/middleware/chain.rb:140 block in invoke |
lib/sidekiq/middleware/chain.rb:143 invoke |
lib/sidekiq/processor.rb:163 block in process |
lib/sidekiq/processor.rb:136 block (6 levels) in dispatch |
lib/sidekiq/job_retry.rb:111 local |
lib/sidekiq/processor.rb:135 block (5 levels) in dispatch |
lib/sidekiq/rails.rb:14 block in call |
lib/active_support/execution_wrapper.rb:88 wrap |
lib/active_support/reloader.rb:72 block in wrap |
lib/active_support/execution_wrapper.rb:88 wrap |
lib/active_support/reloader.rb:71 wrap |
lib/sidekiq/rails.rb:13 call |
lib/sidekiq/processor.rb:131 block (4 levels) in dispatch |
lib/sidekiq/processor.rb:257 stats |
lib/sidekiq/processor.rb:126 block (3 levels) in dispatch |
lib/sidekiq/job_logger.rb:13 call |
lib/sidekiq/processor.rb:125 block (2 levels) in dispatch |
lib/sidekiq/job_retry.rb:78 global |
lib/sidekiq/processor.rb:124 block in dispatch |
lib/sidekiq/logger.rb:10 with |
lib/sidekiq/job_logger.rb:33 prepare |
lib/sidekiq/processor.rb:123 dispatch |
lib/sidekiq/processor.rb:162 process |
lib/sidekiq/processor.rb:78 process_one |
lib/sidekiq/processor.rb:68 run |
lib/sidekiq/util.rb:15 watchdog |
lib/sidekiq/util.rb:24 block in safe_thread
It would be nice to configure the client with a timeout value that is passed through to Faraday as a request option
Hi!
I'm trying this gem for the first time and got it working instantly!
I'm now trying to figure out how to pass custom fields to the API so I can segment on them inside of mailerlite.
The documentation doesn't really show a complete example on how to do this and I tried several way on passing data to the create_subscriber
.
Attempt 1:
MailerLite.create_subscriber(email: "[email protected]", fields: ["locale" => "en"])
Attempt 2:
MailerLite.create_subscriber(email: "[email protected]", fields: [{ key: "locale", value: "en" }])
Attempt 3:
MailerLite.create_subscriber(email: user.email)
MailerLite.update_subscriber(user.email, {
fields: [{key: "locale", value: "en"}]
})
None of these examples updates the fields of the subscribers.
Am I passing these values in wrong or just missing something?
Kind regards
Jens
--- EDIT ---
For anyone stumbling on the same issue as me.
The documentation talks about fields being an array, but this is not the case. I cross referenced mailerlite's api and they send in an object
/hash
where the key
is the field name
and the value is just passed as a value of that specific key.
Correct usage:
MailerLite.create_subscriber(email: "[email protected]", fields: { locale: "en" })
Although the docs indicate Groups are supported
https://github.com/jpalumickas/mailerlite-ruby/blob/main/examples/groups.md
api_instance = MailerLite::Client.new
api_instance.groups
(irb):2:in `<main>': undefined method `groups' for #<MailerLite::Client:0x000055716b6ac458 @api_token="ey..."> (NoMethodError)
Hi,
First off thanks for the gem, it's better than the official one (since I can actually make requests).
I'm wondering if there are plans to switch to the V2 API? I'm worried MailerLite will phase out V1, and the naming scheme & docs seems better for V2 anyway.
Hi there,
I was experiencing some cases where an email address was not added to a list. Checking the logs I saw the error MailerLite::BadRequest: Missing a required parameter or calling invalid method
On further digging (and contact with MailerLite) I discovered the cause was that the email I was subscribing had already been added to the (double opt-in) list previously but hadn't yet been confirmed.
You can recreate using the following options in your call to create_group_subscriber
:
{
"email": "[email protected]",
"type": "unconfirmed"
}
Then repeating the process with:
{
"email": "[email protected]"
}
Looking at the code ( https://github.com/jpalumickas/mailerlite-ruby/blob/master/lib/mailerlite/error.rb#L19 ) it seems as though we try to set the message but something happens stopping it, so the user of the library is shown the default message instead.
I'll dig into this a little more when I get some time (unless someone beats me to it), but I just thought I'd share!
Also, I was having difficulty getting raw request/responses out of Faraday (through your gem). Do you have an approach that you use to expose that? It'd make debugging the request/responses in a live application a lot easier!
Hello
Recently I've started to get this error on all gem methods, I've updated to newest gem version 1.10.0 and also tried to increase request timeout, but it's still the same response:
Faraday::ParsingError: 785: unexpected token at ' <title>Error 400 (Bad Request)!!1</title>
Mailerlite API works when calling from CURL
/groups
api endpoint supports passing in limit, offset and filters. One of our users has more than 100 groups and there's no way to currently go through pagination.
This might be a normal behaviour, but it is not documented.
is it an API bug or gem bug?
client.campaign_action(campaign.id, 'send')
MailerLite::InternalServerError: The server encountered an unexpected condition
from /home/ali/projects/ruby/mailerlite-ruby/lib/mailerlite/middleware/raise_error.rb:11:in `on_complete'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/response.rb:9:in `block in call'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/response.rb:61:in `on_complete'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/response.rb:8:in `call'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/response.rb:8:in `call'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday_middleware-0.10.1/lib/faraday_middleware/response_middleware.rb:30:in `call'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/response.rb:8:in `call'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/response.rb:8:in `call'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday_middleware-0.10.1/lib/faraday_middleware/response/follow_redirects.rb:76:in `perform_with_redirection'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday_middleware-0.10.1/lib/faraday_middleware/response/follow_redirects.rb:64:in `call'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday_middleware-0.10.1/lib/faraday_middleware/request/encode_json.rb:23:in `call'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/rack_builder.rb:139:in `build_response'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/connection.rb:377:in `run_request'
from /home/ali/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/connection.rb:177:in `post'
from /home/ali/projects/ruby/mailerlite-ruby/lib/mailerlite/connection.rb:37:in `request'
from /home/ali/projects/ruby/mailerlite-ruby/lib/mailerlite/connection.rb:27:in `post'
from /home/ali/projects/ruby/mailerlite-ruby/lib/mailerlite/clients/campaigns.rb:50:in `campaign_action'
from (irb):47
from ./bin/console:14:in `<main>'
Calling MailerLite.webhooks
gives the following error:
MailerLite::NotFound: Endpoint not found
from <my_user_path>/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/mailerlite-1.16.0/lib/mailerlite/middleware/raise_error.rb:11:in `on_complete'
Steps to reproduce:
MailerLite.webhooks
Environment details:
I've set MailerLite up correctly, ie: I've provided the API key in the config file, and running MailerLite.subscriber('[email protected]')
returns a result without error
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.