woocommerce / wc-api-ruby

A Ruby wrapper for the WooCommerce API.
MIT License
69 stars 74 forks source link

URI.encode is obsoleted and not available in the latest Ruby versions #57

Open tannakartikey opened 2 years ago

tannakartikey commented 2 years ago

The obsolete method URI.encode is used in the code which is throwing the error while using the gem with the latest Ruby versions e.g. ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux].

https://github.com/woocommerce/wc-api-ruby/blob/64336712a87ed81269ef68bde5dcdfcfc5ec4b78/lib/woocommerce_api.rb#L100

The method was marked as obsolete many years back in 2009 with https://github.com/ruby/ruby/commit/238b979f1789f95262a267d8df6239806f2859cc

It can be replaced with the CGI.escape method.

More details: https://bugs.ruby-lang.org/issues/17309

There are many more discussions around the topic on https://bugs.ruby-lang.org/

I have monkeypatched the method in my Rails app until the patch is available on this gem.

# config/initalizers/woo_commerce.rb

module WooCommerce
  class API
    # URI.encode (alias of URI.escape) method used in the gem's implementation
    # is obsolete since 10 years and removed in Ruby 3.
    # https://github.com/ruby/ruby/commit/238b979f1789f95262a267d8df6239806f2859cc
    def add_query_params endpoint, data
      return endpoint if data.nil? || data.empty?

      endpoint += "?" unless endpoint.include? "?"
      endpoint += "&" unless endpoint.end_with? "?"
      endpoint + CGI.escape(flatten_hash(data).join("&"))
    end
  end
end
lucas-proto commented 1 year ago

URI.escape is also obsolete and it is used in lib/woocommerce_api.rb:100

ricvillagrana commented 8 months ago

I have the same problem.

@tannakartikey are you working on a PR?

tannakartikey commented 8 months ago

No, I'm not. Feel free to handle if you want. Thanks.

On Sat, 17 Feb, 2024, 03:42 Ricardo Villagrana, @.***> wrote:

I have the same problem.

@tannakartikey https://github.com/tannakartikey are you working on a PR?

— Reply to this email directly, view it on GitHub https://github.com/woocommerce/wc-api-ruby/issues/57#issuecomment-1949408038, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADHFEB5WUQQ7JRIB3TK24LYT7KT3AVCNFSM53RNDMHKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJUHE2DAOBQGM4A . You are receiving this because you were mentioned.Message ID: @.***>

bond commented 8 months ago

I have this problem as well. This module is broken as long as arguments are beeing passed to endpoint (which is set in querystring).

See https://github.com/woocommerce/wc-api-ruby/pull/61, this uses the updated method in URI module. Both solutions work, but please include and release, as this module is not usable anymore due to depreciation in Ruby (since 2020).