summaryrefslogtreecommitdiff
path: root/lib/chef_zero/endpoints/data_bag_item_endpoint.rb
blob: 0c6f3e2907c620721a312733bf9b841d7ad8a7ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require "ffi_yajl"
require_relative "rest_object_endpoint"
require_relative "data_bag_item_endpoint"
require_relative "../chef_data/data_normalizer"

module ChefZero
  module Endpoints
    # /data/NAME/NAME
    class DataBagItemEndpoint < RestObjectEndpoint
      def initialize(server)
        super(server, "id")
      end

      def populate_defaults(request, response_json)
        DataBagItemEndpoint.populate_defaults(request, response_json, request.rest_path[3], request.rest_path[4])
      end

      def self.populate_defaults(request, response_json, data_bag, data_bag_item)
        response = FFI_Yajl::Parser.parse(response_json)
        response = ChefData::DataNormalizer.normalize_data_bag_item(response, data_bag, data_bag_item, request.method)
        FFI_Yajl::Encoder.encode(response, pretty: true)
      end
    end
  end
end