Create a new instance using the given registry
 to record stats for the requests performed
 Send a JSON payload to a given endpoing
973672
def post_json(endpoint, payload)
      s = payload.to_json
      uri = URI(endpoint)
      http = Net::HTTP.new(uri.host, uri.port)
      req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
      req.body = s
      begin
        res = http.request(req)
      rescue StandardError => e
        Spectator.logger.info("Cause #{e.cause} - msg=#{e.message}")
        return 400
      end

      res.value
    end
967328
function createBidCacheRegistry() {
  let registry = {};

  function setupRegistrySlot(auctionId) {
    registry[auctionId] = {};
    registry[auctionId].bidStorage = new Set();
    registry[auctionId].queueDispatcher = createDispatcher(queueTimeDelay);
    registry[auctionId].initialCacheKey = utils.generateUUID();
  }

  return {
    addBid: function (bid) {
      // create parent level object based on auction ID (in case there are concurrent auctions running) to store objects for that auction
      if (!registry[bid.auctionId]) {
        setupRegistrySlot(bid.auctionId);
      }
      registry[bid.auctionId].bidStorage.add(bid);
    },
    removeBid: function (bid) {
      registry[bid.auctionId].bidStorage.delete(bid);
    },
    getBids: function (bid) {
      return registry[bid.auctionId] && registry[bid.auctionId].bidStorage.values();
    },
    getQueueDispatcher: function(bid) {
      return registry[bid.auctionId] && registry[bid.auctionId].queueDispatcher;
    },
    setupInitialCacheKey: function(bid) {
      if (!registry[bid.auctionId]) {
        registry[bid.auctionId] = {};
        registry[bid.auctionId].initialCacheKey = utils.generateUUID();
      }
    },
    getInitialCacheKey: function(bid) {
      return registry[bid.auctionId] && registry[bid.auctionId].initialCacheKey;
    }
  }
}
56883
private ServiceHandle<S> doRegister(ServiceEndPoint endPoint) {
        checkNotNull(endPoint);

        ServiceHandle<S> toDelete = null;
        ServiceHandle<S> toReturn;

        synchronized (this) {
            HeavyServiceHandle<S> existingServiceHandle = _instancesPerEndpoint.get(endPoint);
            if (existingServiceHandle == null || existingServiceHandle.hasBeenFlaggedForEviction() || existingServiceHandle.isOld()) {

                // If there was not an existingServiceHandle, then make a new one.
                //
                // If existingServiceHandle.hasBeenFlaggedForEviction() is true, that means this EndPoint
                //  has been "evicted" for being "bad" but has recovered before the Eviction timeout
                //  process has gotten around to cleaning up this serviceHandle.  In this case, we assume
                //  the "safest" thing to do is to create a new Client for that EndPoint, in case the
                //  problem was with the "old" client.
                //
                // If the existingServiceHandle is "new" don't create a new client object due to the
                //  race condition in HostDiscovery and ServicePool, which can cause a checkOut() to
                //  occur before its associated ServiceCache.register().
                // Thus we want have a short period of time where duplicate "checkouts" and a register
                //  will not thrash the system creating a series of Client instances.
                //
                // _serviceFactory.create(endPoint) is a potentially expensive operation, memory, file handles, etc.
                // hence we really only want to do it when we have to, preferably via the out-of-band
                // ServiceCache.register() method, instead of the high traffic checkOut method.
                S service = _serviceFactory.create(endPoint);
                _serviceCounter.inc();

                HeavyServiceHandle<S> newServiceHandle = new HeavyServiceHandle<>(service, endPoint);

                // add the newServiceHandle to a new copy of the _instancesPerEndpoint map
                Map<ServiceEndPoint, HeavyServiceHandle<S>> sourceCopy = Maps.newHashMap(_instancesPerEndpoint);
                sourceCopy.put(endPoint, newServiceHandle);
                _instancesPerEndpoint = sourceCopy;

                toDelete = existingServiceHandle;
                toReturn = newServiceHandle;
            } else {
                // The existingServiceHandle was not null, not evicted, and not old, thus we did not recreate it.
                toReturn = existingServiceHandle;
            }
        }

        // Destroy instances outside the synchronization, with the idea being it may be an expensive operation
        if (toDelete != null) {
            destroyService(toDelete);
            _serviceCounter.dec();
        }

        return toReturn;
    }
564771
def create_for(self, ref_type, ref_id, attributes, silent=False, hook=True):
        
        # if not isinstance(attributes, dict):
        #    raise TypeError('Must be of type dict')
        attributes = json.dumps(attributes)
        return self.transport.POST(body=attributes,
                                   type='application/json',
                                   url='/task/%s/%s/%s' % (ref_type, ref_id,
                                                           self.get_options(silent=silent,
                                                                            hook=hook)))
74294
def create_detector(self, detector):
        
        resp = self._post(self._u(self._DETECTOR_ENDPOINT_SUFFIX),
                          data=detector)
        resp.raise_for_status()
        return resp.json()
211194
def _create_json(self):
        
        data_json = {
            "name": self.name,
            "description": self.description,
            "autoJoin": self.autoJoin,
            "realm": self.realm,
        }
        return data_json
644174
def post(self, json=None):
        
        return self._call('post', url=self.endpoint, json=json)
47206
def jsonify_log_record(self, log_record):
        """"""
        return self.json_serializer(log_record,
                                    default=self.json_default,
                                    cls=self.json_encoder,
                                    indent=self.json_indent,
                                    ensure_ascii=self.json_ensure_ascii)
1320985
def get_endpoint_obj(client, endpoint, object_id):
    '''  '''
    endpoint = '/'.join([endpoint, str(object_id)])
    return client.authenticated_request(endpoint).json()
290823
def json_request(endpoint, verb='GET', session_options=None, **options):
    
    req = functools.partial(_request, endpoint, verb, session_options,
                            json=True, **options)
    return _run_in_fresh_loop(req)
1194459
def make_payload(base, method, params):
    
    payload = {
        'jsonrpc': '2.0',
        'method': '{base}APING/v1.0/{method}'.format(**locals()),
        'params': utils.serialize_dict(params),
        'id': 1,
    }
    return payload
289997
def _create_json(self):
        
        data_json = {
            "rclass": "local",
            "key": self.name,
            "description": self.description,
            "packageType": self.packageType,
            "notes": "",
            "includesPattern": "**/*",
            "excludesPattern": "",
            "repoLayoutRef": self.repoLayoutRef,
            "dockerApiVersion": self.dockerApiVersion,
            "checksumPolicyType": "client-checksums",
            "handleReleases": True,
            "handleSnapshots": True,
            "maxUniqueSnapshots": 0,
            "snapshotVersionBehavior": "unique",
            "suppressPomConsistencyChecks": True,
            "blackedOut": False,
            "propertySets": [],
            "archiveBrowsingEnabled": self.archiveBrowsingEnabled,
            "yumRootDepth": 0,
        }
        return data_json
274662
def _prepPayload(self, record):
        
        payload = self._getPayload(record)
        json_data = json.dumps(payload, default=serialize)

        return {
            'json': (json_data, 'application/json')
        }.get(self.content_type, (json_data, 'text/plain'))
537567
def create(self, service_name, json, **kwargs):
        """"""
        return self._send(requests.post, service_name, json, **kwargs)
1368783
def stats_send(template = nil, start_date = nil, end_date = nil, options = {})
      data = options
      if template != nil
        data[:template] = template
      end
      if start_date != nil
        data[:start_date] = start_date
      end
      if end_date != nil
        data[:end_date] = end_date
      end
      data[:stat] = 'send'
      api_get(:stats, data)
    end
735533
public static RegistrationRequest fromJson(Map<String, Object> raw) throws JsonException {
    // If we could, we'd just get Json to coerce this for us, but that would lead to endless
    // recursion as the first thing it would do would be to call this very method. *sigh*
    Json json = new Json();
    RegistrationRequest request = new RegistrationRequest();

    if (raw.get("name") instanceof String) {
      request.name = (String) raw.get("name");
    }

    if (raw.get("description") instanceof String) {
      request.description = (String) raw.get("description");
    }

    if (raw.get("configuration") instanceof Map) {
      // This is nasty. Look away now!
      String converted = json.toJson(raw.get("configuration"));
      request.configuration = GridConfiguredJson.toType(converted, GridNodeConfiguration.class);
    }
    
    if (raw.get("configuration") instanceof GridNodeConfiguration) {
      request.configuration = (GridNodeConfiguration)raw.get("configuration");
    }

    return request;
  }
796267
def create(cls, api, default_name=None, description=None):
        
        path = 'group'

        data = {}
        if default_name:
            data['default_group_name'] = default_name
        if description:
            data['description'] = description
        if api.domain:
            data['domain'] = api.domain

        response_data = api.request(path, data=data)

        id = response_data['group_id']
        group = cls(api, id)
        group.default_name = response_data['default_group_name']

        return group