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

undefined method `first' for nil:NilClass when reading the MessageID of the response #97

Closed
aalbagarcia opened this issue May 25, 2017 · 7 comments

Comments

@aalbagarcia
Copy link

Hi @arnaud-mailjet

As a follow up of #91, I'm trying to upgrade to version 1.5.0 of the gem so I can use different subaccounts. After the ugrade, I've found that all my tests are failing.

This piece of code works with version 1.4.10:

          response = ::Mailjet::Send.create(payload)
          @gateway_message_id = response.attributes['Sent'].first['MessageID']

Using version 1.5.0:

response = ::Mailjet::Send.create(payload, api_key: ENV["MAILJET_KEY"], api_secret: ENV["MAILJET_SECRET"])
          @gateway_message_id = response.attributes['Sent'].first['MessageID']

I get this error:

NoMethodError:
       undefined method `first' for nil:NilClass

...apparently the response is not being properly parsed somehow.

I'm stubbing requests using WebMock like this:

        stub_request(:post, %r[https?://.*api\.mailjet\.com.*]).with(
            body: {...the payload...},
          headers: {
             'Authorization'=>'Basic MzY3Y2FiYzM5YmIzZD...SADFA='
          }).to_return(
             body: {
                  "Sent" => [
                      {
                          "Email" => "passenger@mailjet.com",
                          "MessageID" => 111111111111111
                      }
                  ]
             }.to_json,
             status: 200,
             headers: {"Content-Type" => 'application/json'})

Version 1.4.10 parses the response body and returns the correct hash while version 1.5.0 doesn't.

@aalbagarcia
Copy link
Author

...sorry, I mentioned the wrong guy @arnaudbreton

@Zhivko-Mailjet
Copy link
Contributor

@aalbagarcia

Thanks for spotting and reporting the issue. We will investigate further and will come back to you as soon as we have any news

Lorel added a commit that referenced this issue May 26, 2017
Lorel added a commit that referenced this issue May 26, 2017
Lorel added a commit that referenced this issue May 26, 2017
Lorel added a commit that referenced this issue May 26, 2017
@Lorel
Copy link
Contributor

Lorel commented May 26, 2017

Hi @aalbagarcia

I think I've been able to find a quick fix for this issue
could you try this by using in your Gemfile

gem 'mailjet', git: 'https://github.com/mailjet/mailjet-gem.git', ref: 'a65aa5b1ab07b69e4b1ba29c34ee15ba76b2678e'

and tell me if it works?

@arnaudbreton
Copy link
Contributor

@aalbagarcia commit 5c75df16bffbdb0f15cd668aa00b5a60679320fc should fix the issue here.

Do you have time to confirm on your end?
We'll push a 1.5.1 release by the end of the day.

Apologies for the trouble and thanks a lot for reporting this regression.

arnaudbreton pushed a commit that referenced this issue May 26, 2017
@arnaudbreton
Copy link
Contributor

@aalbagarcia as promised, I've just published v1.5.1 which contains the fix I mentioned before. It's available on Rubygems.

Hope it works for you, please let us know.
One more time, apologies for the issue.

@aalbagarcia
Copy link
Author

@arnaudbreton I've just tested version 1.5.1 in our test environment and all my tests are passing. Next week I will try it again in production. Thanks for the fast response!

@arnaudbreton
Copy link
Contributor

@aalbagarcia awesome, glad to hear. Thanks a lot for your feedback and patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants