Пример #1
0
 def fetch_page_of_pledges(self, campaign_id, page_size, cursor=None, includes=None, fields=None):
     url = "campaigns/{0}/pledges".format(campaign_id)
     params = {"page[count]": page_size}
     if cursor:
         try:
             cursor = self.__as_utc(cursor).isoformat()
         except AttributeError:
             pass
         params.update({"page[cursor]": cursor})
     url += "?" + urlencode(params)
     return self.__get_json(build_url(url, includes=includes, fields=fields))
Пример #2
0
 def fetch_page_of_pledges(
         self, campaign_id, page_size, cursor=None, includes=None,
         fields=None
 ):
     url = 'campaigns/{0}/pledges'.format(campaign_id)
     params = {'page[count]': page_size}
     if cursor:
         try:
             cursor = self.__as_utc(cursor).isoformat()
         except AttributeError:
             pass
         params.update({'page[cursor]': cursor})
     url += "?" + urlencode(params)
     return self.__get_jsonapi_doc(
         build_url(url, includes=includes, fields=fields)
     )
Пример #3
0
def build_url(path, includes=None, fields=None):
    def joined_or_null(arr):
        return "null" if len(arr) == 0 else ','.join(arr)

    connector = '&' if '?' in path else '?'
    params = {}
    if includes:
        params.update({'include': joined_or_null(includes)})
    if fields:
        params.update({
            "fields[{resource_type}]".format(resource_type=resource_type):
            joined_or_null(attributes)
            for resource_type, attributes in fields.items()
        })
    return "{path}{connector}{encoded_params}".format(
        path=path, connector=connector, encoded_params=urlencode(params))
Пример #4
0
def build_url(path, includes=None, fields=None):
    def joined_or_null(arr):
        return "null" if len(arr) == 0 else ','.join(arr)

    connector = '&' if '?' in path else '?'
    params = {}
    if includes:
        params.update({'include': joined_or_null(includes)})
    if fields:
        params.update({
            "fields[{resource_type}]"
            .format(resource_type=resource_type): joined_or_null(attributes)
            for resource_type, attributes in fields.items()
        })
    return "{path}{connector}{encoded_params}".format(
        path=path,
        connector=connector,
        encoded_params=urlencode(params)
    )
Пример #5
0
def build_url(path, includes=None, fields=None):
    connector = '&' if '?' in path else '?'
    params = {}

    if includes:
        params.update({'include': joined_or_null(includes)})

    if fields:
        params.update({
            "fields[{resource_type}]".format(resource_type=resource_type):
            joined_or_null(attributes)
            for resource_type, attributes in fields.items()
        })

    if not params:
        return path

    sorted_params = OrderedDict(sorted(params.items(), key=lambda t: t[0]))
    return path + connector + urlencode(sorted_params)
Пример #6
0
def api_url(*segments, **query):
    path = '/'.join(map(str, segments))

    fields = query.get('fields', None)
    includes = query.get('includes', None)

    if fields:
        del query['fields']

    if includes:
        del query['includes']

    if query:
        path += '?' + urllib_parse.urlencode(query)

    return url_util.build_url(
        API_ROOT_ENDPOINT + path,
        fields=fields,
        includes=includes,
    )