Sha256: 0ddd7f04e5fe4ceeec24f76b068838388e00bc91bc93040cbb54e01c003e3d66

Contents?: true

Size: 1.61 KB

Versions: 8

Compression:

Stored size: 1.61 KB

Contents

libdir = ::File.dirname(__FILE__)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)

require 'siteleaf/version'
require 'siteleaf/git_hash'
require 'siteleaf/client'
require 'siteleaf/entity'
require 'siteleaf/file'
require 'siteleaf/job'
require 'siteleaf/content'
require 'siteleaf/page'
require 'siteleaf/collection'
require 'siteleaf/document'
require 'siteleaf/site'
require 'siteleaf/source_file'
require 'siteleaf/user'
require 'digest/sha1'
require 'rbconfig'
require 'uri'
require 'yaml'

module Siteleaf

  @api_key = ENV['SITELEAF_API_KEY']
  @api_secret = ENV['SITELEAF_API_SECRET']
  @api_base = 'https://api.siteleaf.com'
  @api_version = 'v2'

  class << self
    attr_accessor :api_key, :api_secret, :api_base, :api_version
  end

  def self.api_url(url = '')
    ::File.join(@api_base, @api_version, url)
  end

  def self.settings_file
    ::File.expand_path('~/.siteleaf.yml')
  end

  def self.load_settings(file = self.settings_file)
    if ::File.exist?(file)
      settings = ::File.open(file) { |f| YAML.load(f) }
      
      [:api_key, :api_secret, :api_base, :api_version].each do |key|
        self.send "#{key}=", settings[key.to_s] if settings.has_key?(key.to_s)
      end
        
      symbolized_settings = Hash.new
      settings.each{|k,v| symbolized_settings[k.to_sym] = v}
      
      symbolized_settings
    end
  rescue 
    nil
  end
  
  def self.save_settings(settings, file = self.settings_file)
    stringified_settings = Hash.new
    settings.each{|k,v| stringified_settings[k.to_s] = v}
    
    ::File.open(file, 'w') { |f| f.write stringified_settings.to_yaml }
    
    settings
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
siteleaf-2.2.0 lib/siteleaf.rb
siteleaf-2.1.2 lib/siteleaf.rb
siteleaf-2.1.1 lib/siteleaf.rb
siteleaf-2.1.0 lib/siteleaf.rb
siteleaf-2.0.2 lib/siteleaf.rb
siteleaf-2.0.1 lib/siteleaf.rb
siteleaf-2.0.0 lib/siteleaf.rb
siteleaf-2.0.0.pre.beta9 lib/siteleaf.rb