Retrieve HTTP resources, return related objects (with pagination)
338047
def _retrieve_resources(self, url, class_, full):
        ''''''
        objects_to_return = []
        response = self.session.get(url)
        if response.status_code == 200:
            result = response.json()
            resources = result['results']
            objects_to_return.extend([class_(session=self.session, **resource)
                                      for resource in resources])
            while full and result['next'] is not None:
                response = self.session.get(result['next'])
                if response.status_code == 200:
                    result = response.json()
                    resources = result['results']
                    objects_to_return.extend([class_(session=self.session,
                                                     **resource)
                                              for resource in resources])
                else:
                    raise RuntimeError("Failed downloading data with status {}"
                            ". The response was: '{}'"
                            .format(response.status_code, response.text))
            return objects_to_return
        else:
            raise RuntimeError("Failed downloading data with status {}"
                    ". The response was: '{}'"
                    .format(response.status_code, response.text))
467403
def get_items(self, paginator, current_page):
        """"""
        fields = self.get_model_config().get_list_fields()

        page = paginator.page(current_page)

        items = []
        for item in page:
            items.append({
                'id': item.id,
                'url': item.get_absolute_url(),
                'row_data': [
                    fields[field]['renderer'](item, field)
                    for field in self.get_current_fields()
                ]
            })
        return items
823291
def get_paginated_response(self, data):
        
        metadata = {
            'next': self.get_next_link(),
            'previous': self.get_previous_link(),
            'count': self.get_result_count(),
            'num_pages': self.get_num_pages(),
        }
        if isinstance(data, dict):
            if 'results' not in data:
                raise TypeError(u'Malformed result dict')
            data['pagination'] = metadata
        else:
            data = {
                'results': data,
                'pagination': metadata,
            }
        return Response(data)
788268
def resource_list(cls):
        
        items = cls.list({'items_per_page': 500})
        ret = [str(ip['id']) for ip in items]
        ret.extend([ip['ip'] for ip in items])
        return ret
322919
def _get_resource(self, resource, obj, params=None, **kwargs):
        """"""
        r = self._http_resource('GET', resource, params=params)
        item = self._resource_deserialize(r.content.decode("utf-8"))

        return obj.new_from_dict(item, h=self, **kwargs)
426493
def get(self, resource_id):
        
        response = self.requester.get(
            '/{endpoint}/{entity}/{id}',
            endpoint=self.endpoint, entity=self.entity, id=resource_id,
            paginate=False
        )
        return response.json()
1226124
def fetch_pages(url, referer = nil, depth = nil, user_data = nil)
      url = URI(url)
      pages = []
      get(url, referer) do |response, code, location, redirect_to, response_time|
        handle_compression response
        page = Page.new(location, body: response.body,
                                  code: code,
                                  headers: response.to_hash,
                                  referer: referer,
                                  depth: depth,
                                  redirect_to: redirect_to,
                                  response_time: response_time,
                                  fetched_at: Time.now.to_i)
        page.user_data = user_data unless user_data.nil?
        pages << page
      end
      pages
    rescue *RESCUABLE_ERRORS => e
      if verbose?
        puts e.inspect
        puts e.backtrace
      end
      page = Page.new(url, error: e, referer: referer, depth: depth)
      page.user_data = user_data unless user_data.nil?
      [page]
    end
586491
def get(path, params = {})
      uri = path
      if params.count > 0
        uri += "?#{URI.encode_www_form(params)}"
      end

      headers = {}

      request('GET', uri, nil, headers) do |resp|
        if params[:fetch_all] == true &&
            resp.body.has_key?('pagination') &&
            resp.body['pagination']['next_uri'] != nil
          params[:starting_after] = resp.body['data'].last['id']
          get(path, params) do |page|
            body = resp.body
            body['data'] += page.data
            resp.body = body
            yield(resp) if block_given?
          end
        else
          yield(resp) if block_given?
        end
      end
    end
984736
def paginate(self, request, collection):
        
        p = Paginator(request, self, collection)
        return p.paginator and p or UpdatedList(collection)
171625
def get_next(self):
        """"""
        url = self._get_link('next')
        resource = self.object_type.get_resource_class(self.client)
        resp = resource.perform_api_call(resource.REST_READ, url)
        return List(resp, self.object_type, self.client)
1045877
def get_resource_links(self, item):
        """"""
        if self.opts.self_url:
            ret = self.dict_class()
            kwargs = resolve_params(item, self.opts.self_url_kwargs or {})
            ret['self'] = self.generate_url(self.opts.self_url, **kwargs)
            return ret
        return None
1143825
def get_resource(request):
    """"""
    hash = request.matchdict['hash']

    # Do the file lookup
    with db_connect() as db_connection:
        with db_connection.cursor() as cursor:
            args = dict(hash=hash)
            cursor.execute(SQL['get-resource'], args)
            try:
                mimetype, file = cursor.fetchone()
            except TypeError:  # None returned
                raise httpexceptions.HTTPNotFound()

    resp = request.response
    resp.status = "200 OK"
    resp.content_type = mimetype
    resp.body = file[:]
    return resp
466100
def paginate_response(self, queryset, serializers_kwargs={}):
        
        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True, **serializers_kwargs)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(queryset, many=True, **serializers_kwargs)
        return Response(serializer.data)
1049553
def fetch_pages(url, referer = nil, depth = nil)
      begin
        url = URI(url) unless url.is_a?(URI)
        pages = []
        get(url, referer) do |response, code, location, redirect_to, response_time|
          pages << Page.new(location, :body => response.body.dup,
                                      :code => code,
                                      :headers => response.to_hash,
                                      :referer => referer,
                                      :depth => depth,
                                      :redirect_to => redirect_to,
                                      :response_time => response_time)
        end

        return pages
      rescue Exception => e
        if verbose?
          puts e.inspect
          puts e.backtrace
        end
        return [Page.new(url, :error => e)]
      end
    end
852328
def get(query_url,
            headers: {})
      HttpRequest.new(HttpMethodEnum::GET,
                      query_url,
                      headers: headers)
    end
16085
def resource_list(cls):
        
        items = cls.list({'items_per_page': 500})
        ret = [paas['name'] for paas in items]
        ret.extend([str(paas['id']) for paas in items])
        for paas in items:
            paas = cls.info(paas['id'])
            ret.extend([vhost['name'] for vhost in paas['vhosts']])

        return ret
760088
def _paginate(url, topkey, *args, **kwargs):
    '''
    
    '''

    ret = salt.utils.http.query(url, **kwargs)
    if 'errors' in ret['dict']:
        return ret['dict']

    lim = int(ret['dict']['page']['limit'])
    total = int(ret['dict']['page']['total'])

    if total == 0:
        return {}

    numpages = (total / lim) + 1

    # If the count returned is less than the page size, just return the dict
    if numpages == 1:
        return ret['dict'][topkey]

    aggregate_ret = ret['dict'][topkey]
    url = args[0]
    for p in range(2, numpages):
        param_url = url + '?offset={0}'.format(lim * (p - 1))
        next_ret = salt.utils.http.query(param_url, kwargs)
        aggregate_ret[topkey].extend(next_ret['dict'][topkey])

    return aggregate_ret