jsboulanger / streak-ruby

Ruby bindings for the Streak API (streak.com)
MIT License
10 stars 21 forks source link

Keep the API key in memory #6

Closed cimm closed 6 years ago

cimm commented 9 years ago

I can assign the API key as shown in the documentation:

Streak.api_key = 'secret_key'
# do something with the API

problem is this seems to be scoped per method. If I set the key in an initializer it will be lost by the time I call the save method below.

class Something
  def initializer
    Streak.api_key = 'secret_key'
  end

  def save
    # do something with the API, API key no longer set
  end
end

Is there a way to set the API key without assigning the key in each method separately, in an environment variable or configuration file for example?

tmartin8080 commented 8 years ago

@cimm Try adding the key to an ENV variable. I used figaro and it works perfectly.

lancecarlson commented 6 years ago

@cimm You need to change initializer to initialize.