0

I use Grape to create an API in rails. Now I want to use Shopify's Active Shipping gem but when I try to use this in my custom_helper within Grape I get a uninitialized constant ActiveShipping error message. In addition I also get the following message:

Cannot render console with content type application/jsonAllowed content types: [#<Mime::Type:0x007f8bea21b4e8 @synonyms=["application/xhtml+xml"], @symbol=:html, @string="text/html">, #<Mime::Type:0x007f8bea21b038 @synonyms=[], @symbol=:text, @string="text/plain">, #<Mime::Type:0x007f8bec0fe950 @synonyms=[], @symbol=:url_encoded_form, @string="application/x-www-form-urlencoded">]

my helper file looks like:

require 'active_shipping'
module API
    module V1
        module Helpers
            module ShippingHelpers
                extend Grape::API::Helpers

                def ups_tracking_info(tracking_number)
                    ups = ActiveShipping::UPS.new(login, password, key) #this is where it throws an error
                    ups.find_tracking_info(tracking_number)
                end
            end
        end
    end
end

and I include it in my grape shippings file like:

module API
  module V1
    class Shippings < Grape::API
        helpers API::V1::Helpers::ShippingHelpers 
       ...
        #some endpoint:
          ups_tracking_info(tracking_info)
       ...
    end
  end
end

Why do I get the uninitialized constant error message? I do require the gem in my helper file.. requireing it in my config/application.rb file doesn't work either...

Hope someone will have an idea, that can help me further. Thanks in Advance!

Note I have all my grape files in app/api/api folder so that is not the problem..

PSR
  • 513
  • 6
  • 16
  • Try `::ActiveShipping::UPS` so that it looks for the class at the root level, not within `API::V1::Shippings`. – Philip Hallstrom Apr 28 '15 at 16:15
  • Thanks for the answer @Philip. Unfortunately it didn't help.. Please see my answer below. It turned out the documentation was incorrect and I needed to use ``include ActiveMerchant::Shipping`` in my class. – PSR Apr 28 '15 at 20:22

1 Answers1

0

Turned out the documentation with the gem on github is incorrect. The correct information is written here. I had to include ActiveMerchant::Shipping in my class and drop the use of ActiveMerchant::Shipping within the code. So use UPS.new() or FedEx.new() etc. instead.

PSR
  • 513
  • 6
  • 16