Sha256: 51cea7b9dc4bee8f159db65646e6654c8592da42b03e9ca278b3940568479a3e

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

module StwEngine
  extend self

  # modes
  MODES = %w{production placehold dummy}
  IMAGE_URL = 'http://images.shrinktheweb.com/xino.php?'
  ACCOUNT_URL = 'http://images.shrinktheweb.com/account.php?'

  def config c = {}
    # mandatory
    self.api_key = c[:api_key]
    self.api_secret = c[:api_secret]

    # optional
    self.mode = c[:mode] if c[:mode]
    self.api_version = c[:api_version] if c[:api_version]
    self.api_url = c[:api_url] if c[:api_url]
  end

  def api_key=api_key
    @api_key=api_key
  end

  def api_key
    raise 'StwEngine error: No api_key defined!' if @api_key.nil?
    @api_key
  end

  def api_secret=api_secret
    @api_secret = api_secret
  end

  def api_secret
    raise 'StwEngine error: No api secret defined!' if @api_secret.nil?
    @api_secret
  end

  def mode=mode
    raise "StwEngine error: Invalid mode, only #{ MODES.join(', ') } are allowed" unless MODES.include?(mode.to_s)
    @mode = mode.to_s
  end

  def mode
    @mode ||= 'production' # default: production
  end

  def api_version=api_version
    @api_version = api_version || 'v6' # set default to latest open version
  end

  def api_version
    @api_version || 'v6' #default: v6
  end

  def image_url=image_url
    @image_url = image_url || IMAGE_URL
  end

  def image_url
    # reference => http://url2png.com/docs/
    # currently all versions suggest 'beta'
    @image_url || IMAGE_URL
  end
  
   def account_url
    @account_url = ACCOUNT_URL
  end
  
   def account_url=account_url
    @account_url = ACCOUNT_URL
  end



  def default_size=default_size
    @default_size = default_size || "400x400"
  end

  def default_size
    @default_size || "400x400"
  end

  def token param
    case self.api_version
    when 'v6'
      Digest::MD5.hexdigest("#{param}#{self.private_key}")
    when 'v4', 'v3'
      Digest::MD5.hexdigest("#{self.private_key}+#{param}")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stw_engine-0.0.2 lib/stw_engine/config.rb
stw_engine-0.0.1 lib/stw_engine/config.rb