Create a gist now

Instantly share code, notes, and snippets.

@feministy /configuration.rb Secret
Last active Oct 28, 2016

Creating configuration blocks for Ruby gems. Full post: http://lizabinante.com/blog/creating-a-configurable-ruby-gem/
# lib/ravelry/configuration.rb
module Ravelry
class Configuration
attr_accessor :access_key, :secret_key, :personal_key
def initialize
@access_key = nil
@secret_key = nil
@personal_key = nil
end
end
end

API keys

API keys must be configured in the gem setup. You can do this anywhere in your application before you make API calls using the gem.

Ravelry.configure do |config|
  config.access_key = ''
  config.secret_key = ''
  config.personal_key = ''
end
  • config.access_key - your Ravelry access key
  • config.secret_key - your Ravelry secret key
  • config.personal_key - wait for it! Your Ravelry personal key; primarily used for OAuth (not yet implemented in the gem)

Getting these keys requires a (free) Ravelry account and that you agree to the terms of use for the API.

The keys are available to you throughout your application as:

Ravelry.configuration.access_key
Ravelry.configuration.secret_key
Ravelry.configuration.personal_key
# lib/ravelry.rb
require 'ravelry/configuration'
module Ravelry
class << self
attr_accessor :configuration
end
def self.configuration
@configuration ||= Configuration.new
end
def self.reset
@configuration = Configuration.new
end
def self.configure
yield(configuration)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment