class Jekyll::Fridge::Client

Attributes

client[R]
config[R]

Public Class Methods

new(config) click to toggle source
# File lib/jekyll-fridge.rb, line 63
def initialize(config)
  @client = FridgeApi.client({
    :client_id => config['client_id'],
    :client_secret => config['client_secret']
  })
  @config = config.delete_if { |k, v| k.to_s.match(/secret/) || v.to_s.match(/sk/) }
  reset!()
end

Public Instance Methods

before_method(method) click to toggle source
# File lib/jekyll-fridge.rb, line 81
def before_method(method)
  # try content type
  type = get("types/#{method}")
  if type && type.kind_of?(FridgeApi::Model)
    return Jekyll::Fridge.stringify_keys_deep(type.attrs.merge({
      'content' => ContentDrop.new(self, "content", "type=#{type.slug}")
    }))
  end

  # try user role
  role = get("roles/#{method}")
  if role && role.kind_of?(FridgeApi::Model)
    return Jekyll::Fridge.stringify_keys_deep(role.attrs.merge({
      'users' => ContentDrop.new(self, "users", "role=#{role.slug}")
    }))
  end

  nil
end
collections() click to toggle source
# File lib/jekyll-fridge.rb, line 105
def collections
  ContentDrop.new(self, "collections")
end
content() click to toggle source
# File lib/jekyll-fridge.rb, line 101
def content
  ContentDrop.new(self, "content")
end
get(path) click to toggle source
# File lib/jekyll-fridge.rb, line 72
def get(path)
  return @cache[path] if @cache.has_key?(path)
  @cache[path] = @client.get(path)
end
reset!() click to toggle source
# File lib/jekyll-fridge.rb, line 77
def reset!
  @cache = Hash.new
end
settings() click to toggle source
# File lib/jekyll-fridge.rb, line 109
def settings
  ContentDrop.new(self, "settings")
end
types() click to toggle source
# File lib/jekyll-fridge.rb, line 113
def types
  ContentDrop.new(self, "types")
end
users() click to toggle source
# File lib/jekyll-fridge.rb, line 117
def users
  ContentDrop.new(self, "users")
end