Jerome
Jerome

Reputation: 6217

setting google API in rails

The following gem suggests a method to provide google account API key. While this is usually set in an initializer, the suggestion is not specific in this regard.

The statement provided leads to a noMethodError. Preparing an initializer with

class MyGoogle < GoogleDistanceMatrix

  matrix.configure do |config|

generates superclass must be a Class (Module given) where, in fact, this gem is defined as a module

module GoogleDistanceMatrix
  VERSION = "0.4.0"
end

What is a proper Railsy way to address the API-key setting and correlated issue?

Upvotes: 0

Views: 90

Answers (1)

Igor Springer
Igor Springer

Reputation: 496

GoogleDistanceMatrix is a module, but Matrix is a class within it. A class cannot inherit from a module.

To set the API keys, according to the documentation, you should create a new instance of Matrix class and set config option there e.g:

matrix = GoogleDistanceMatrix::Matrix.new

matrix.configure do |config|
  config.google_api_key = "YOUR_API_KEY"
end

Than you can use matrix instance to do further usage of the gem. Have fun!

Upvotes: 2

Related Questions