mailgun icon indicating copy to clipboard operation
mailgun copied to clipboard

Route example in README broken?

Open fredrik opened this issue 9 years ago • 3 comments

Copy-pasting the example in the README yields a Mailgun::Error:

irb(main):013:0> @mailgun.routes.create "Description for the new route", 1,
irb(main):014:0*        [:match_recipient, "[email protected]"],
irb(main):015:0*        [[:forward, "http://my-site.com/incoming-mail-route"],
irb(main):016:1*           [:stop]]
Mailgun::Error: 'action' parameter is missing

fredrik avatar Mar 29 '15 21:03 fredrik

I get this as well. Either an error in the code or in the README.

ajsharp avatar May 12 '15 04:05 ajsharp

Looking at the relevant part of the code, there is a bug where the data['actions'] part of the params hash is built:

    def create(description, priority, filter, actions)
      data = ::Multimap.new

      data['priority']    = priority
      data['description'] = description
      data['expression']  = build_filter(filter)

      actions = build_actions(actions)

      actions.each do |action|
        data['action'] = action
      end

      # TODO: Raise an error or return false if unable to create route
      Mailgun.submit(:post, route_url, data)["route"]["id"]
    end

build_actions returns an array of strings, and then each one is iterated through, overwriting the data['actions'] param, only assigning the final action. So yea, the bug is in the code, as far as I can tell.

cc @HashNuke

ajsharp avatar May 12 '15 04:05 ajsharp

My fault, it seems this functionality is provided by the embedded Multimap library. Still, this functionality throws an error for me. Maybe mailgun changed their API signature?

ajsharp avatar May 12 '15 04:05 ajsharp