Class: Jekyll::Fridge::Client

Inherits:
Liquid::Drop
  • Object
show all
Defined in:
lib/jekyll-fridge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



63
64
65
66
67
68
69
70
# 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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



61
62
63
# File 'lib/jekyll-fridge.rb', line 61

def client
  @client
end

#configObject (readonly)

Returns the value of attribute config.



61
62
63
# File 'lib/jekyll-fridge.rb', line 61

def config
  @config
end

Instance Method Details

#before_method(method) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 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

#collectionsObject



105
106
107
# File 'lib/jekyll-fridge.rb', line 105

def collections
  ContentDrop.new(self, "collections")
end

#contentObject



101
102
103
# File 'lib/jekyll-fridge.rb', line 101

def content
  ContentDrop.new(self, "content")
end

#get(path) ⇒ Object



72
73
74
75
# 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!Object



77
78
79
# File 'lib/jekyll-fridge.rb', line 77

def reset!
  @cache = Hash.new
end

#settingsObject



109
110
111
# File 'lib/jekyll-fridge.rb', line 109

def settings
  ContentDrop.new(self, "settings")
end

#typesObject



113
114
115
# File 'lib/jekyll-fridge.rb', line 113

def types
  ContentDrop.new(self, "types")
end

#usersObject



117
118
119
# File 'lib/jekyll-fridge.rb', line 117

def users
  ContentDrop.new(self, "users")
end