Recursively builds entity instances
 out of all hashes in the response object
517944
def create_instance(res)
      response = res.parsed_response

      # if there was an error, throw it
      raise_error(response['error'], res.code) if response.nil? || response.key?('error')

      # There must be a top level entity
      # This is either one of payment, refund, or collection at present
      begin
        class_name = response['entity'].split('_').collect(&:capitalize).join

        klass = Razorpay.const_get class_name
      rescue NameError
        # Use Entity class if we don't find any
        klass = Razorpay::Entity
      end
      klass.new(response)
    end
1279023
def each_pair(type, default = nil)
			real_hash.each_key() { |key|
				value = fetch(key, type, default)
				if (!value.nil?)
					yield(key, value)
				end
			}
		end
505927
def build_json_resource_obj(cls, fields, resource, resource_instance, resource_name,
                                force_type_resolution=False):
        
        # Determine type from the instance if the underlying model is polymorphic
        if force_type_resolution:
            resource_name = utils.get_resource_type_from_instance(resource_instance)
        resource_data = [
            ('type', resource_name),
            ('id', encoding.force_text(resource_instance.pk) if resource_instance else None),
            ('attributes', cls.extract_attributes(fields, resource)),
        ]
        relationships = cls.extract_relationships(fields, resource, resource_instance)
        if relationships:
            resource_data.append(('relationships', relationships))
        # Add 'self' link if field is present and valid
        if api_settings.URL_FIELD_NAME in resource and \
                isinstance(fields[api_settings.URL_FIELD_NAME], relations.RelatedField):
            resource_data.append(('links', {'self': resource[api_settings.URL_FIELD_NAME]}))
        return OrderedDict(resource_data)
95894
def from_dict(cls, entity_cls, adict):
        """"""
        invalid_req = InvalidRequestObject()

        # Extract the pagination parameters from the input
        page = int(adict.pop('page', 1))
        per_page = int(adict.pop(
            'per_page', getattr(active_config, 'PER_PAGE', 10)))
        order_by = adict.pop('order_by', ())

        # Check for invalid request conditions
        if page < 0:
            invalid_req.add_error('page', 'is invalid')

        if invalid_req.has_errors:
            return invalid_req

        # Do we need to pop out random?
        # adict.pop('random', None)

        return cls(entity_cls, page, per_page, order_by, adict)
511015
def list(self, entityid=None):
		
		params = {}
		if entityid:
			params['name'] = entityid
		data = self._http_req('connections',params=params)
		entities = data['decoded']['connections']

		# hash key will be string (damned json), so convert to integer
		entities = {int(k): v for k, v in entities.items()}
		entities_list = sorted(entities.items(), key=lambda x: x[0])
		entities = OrderedDict(entities_list)
		return entities
71711
def from_response(cls, response, attrs):
        
        proj = response['Projection']
        hash_key = attrs.get(response['KeySchema'][0]['AttributeName'])
        range_key = None
        if len(response['KeySchema']) > 1:
            range_key = attrs[response['KeySchema'][1]['AttributeName']]
        throughput = Throughput.from_response(
            response['ProvisionedThroughput'])
        index = cls(proj['ProjectionType'], response['IndexName'], hash_key,
                    range_key, proj.get('NonKeyAttributes'), throughput)
        index.response = response
        return index
496425
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'input' in _dict:
            args['input'] = MessageInput._from_dict(_dict.get('input'))
        if 'intents' in _dict:
            args['intents'] = [
                RuntimeIntent._from_dict(x) for x in (_dict.get('intents'))
            ]
        if 'entities' in _dict:
            args['entities'] = [
                RuntimeEntity._from_dict(x) for x in (_dict.get('entities'))
            ]
        return cls(**args)
1133543
def build_response(body, status = 200, headers = {})
      @template = { body: body, status: status, headers: headers }
    end
410510
def create_response response
      json = JSON.parse(response.body_str)
      if json.is_a?(Array)
        result = json.map {|result| Fulfil::Base.new(result)}
      else
        result = Fulfil::Base.new(json)
        if result.type == "UserError"
          raise Fulfil::UserError, result.message
        end
      end
      result
    end
786632
def to_hash
      methods = instance_variables.map { |i| i.to_s.gsub('@', '') }
      Hash[*methods.map { |m| [m, send(m.to_sym)] }.flatten]
    end
360272
function parseAnnotations(response) {
  let entities = {};
  Object.keys(response).forEach(key => {
    entities[key] = parseAnnotation(response[key]);
  });
  return entities;
}
93391
def to_hash
        h = {}
        keys.each { |k| h[ k ] = self.fetch( k ) }
        h
    end
546790
def all
      response = request(:get_all)
      handles = response.values.flatten.collect { |handle| Entity::Handle.build(handle) }
      get_data_for_handles(handles)

      self
    end
578721
def to_hash
      result = @response[:magic_response][:magic_result][:diffgram]
      result = strip_attributes(result)
      result = convert_dates_to_utc(result)

      if result.nil?
        return []
      end

      # All magic responses wrap their result in an ActionResponse element
      result = result.values.first

      # Often the first element in ActionResponse is an element
      # called ActionInfo, but in some cases it has a different name
      # so we just get the first element.
      result.values.first
    end
1358903
def map(cls, dict_entity):
        
        for key, value in dict_entity.items():
            if hasattr(cls, key):
                if isinstance(value, list):
                    _list = getattr(cls, key)
                    if isinstance(_list.expected_type, list):
                        for _dict in value:
                            _list.append(cls.map(_list.typeof(), _dict))
                elif isinstance(value, dict):
                    attr = getattr(cls, key)
                    instance = attr.expected_type()
                    Entity.map(instance, value)
                    setattr(cls, key, instance)
                else:
                    setattr(cls, key, value)
            else:
                setattr(cls, key, value)
1054915
def xml_to_hash(element, child_with_children = "", unique_children = true)
      properties = {}
      element.each_element_with_text do |e|
        if e.name.eql?(child_with_children)
          if unique_children
            e.each_element_with_text do |t|
              properties[t.name] = to_type(t.text)
            end
          else
            children = []
            e.each_element_with_text do |t|
              properties[t.name] = children.push(to_type(t.text))
            end
          end
        else
          properties[e.name] = to_type(e.text)
        end
      end
      properties
    end
681337
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'entities' in _dict:
            args['entities'] = [
                QueryEntitiesEntity._from_dict(x)
                for x in (_dict.get('entities'))
            ]
        return cls(**args)