示例#1
0
 def test_subexample_sub(self):
     assert endpoint_for('http://sub.example.com/sub') == (
         'subdomained',
         {
             'subdomain': 'sub'
         },
     )
示例#2
0
def oembed(url):
    """
    Endpoint to support oEmbed (see https://oembed.com/). Example request::

        https://hasjob.co/api/1/oembed?url=https://hasjob.co/

    Required for services like embed.ly, which need a registered oEmbed API handler.
    """

    endpoint, view_args = endpoint_for(url)
    if endpoint not in embed_index_views:
        return jsonify({})

    board = Board.get(view_args.get('subdomain', 'www'))
    iframeid = 'hasjob-iframe-' + str(uuid4())

    parsed_url = urlsplit(url)
    embed_url = SplitResult(
        parsed_url.scheme,
        parsed_url.netloc,
        parsed_url.path,
        parsed_url.query + ('&' if parsed_url.query else '') +
        'embed=1&iframeid=' + iframeid,
        parsed_url.fragment,
    ).geturl()

    return jsonify({
        'provider_url':
        url_for('index', subdomain=None, _external=True),
        'provider_name':
        app.config['SITE_TITLE'],
        'thumbnail_width':
        200,
        'thumbnail_height':
        200,
        'thumbnail_url':
        url_for('static',
                filename='img/hasjob-logo-200x200.png',
                _external=True),
        'author_name':
        board.title if board else app.config['SITE_TITLE'],
        'author_url':
        board.url_for(_external=True)
        if board else url_for('index', subdomain=None, _external=True),
        'title':
        ' | '.join([board.title, board.caption])
        if board else app.config['SITE_TITLE'],
        'html':
        ('<iframe id="{iframeid}" src="{url}" '
         'width="100%" height="724" frameborder="0" scrolling="no">'.format(
             url=embed_url, iframeid=iframeid)),
        'version':
        '1.0',
        'type':
        'rich',
    })

    return jsonify({})
示例#3
0
文件: index.py 项目: hasgeek/hasjob
def oembed(url):
    """
    Endpoint to support oEmbed (see https://oembed.com/). Example request::

        https://hasjob.co/api/1/oembed?url=https://hasjob.co/

    Required for services like embed.ly, which need a registered oEmbed API handler.
    """

    endpoint, view_args = endpoint_for(url)
    if endpoint not in embed_index_views:
        return jsonify({})

    board = Board.get(view_args.get('subdomain', u'www'))
    iframeid = 'hasjob-iframe-' + unicode(uuid4())

    parsed_url = urlsplit(url)
    embed_url = SplitResult(
        parsed_url.scheme,
        parsed_url.netloc,
        parsed_url.path,
        parsed_url.query + ('&' if parsed_url.query else '') + 'embed=1&iframeid=' + iframeid,
        parsed_url.fragment
        ).geturl()

    return jsonify({
        'provider_url': url_for('index', subdomain=None, _external=True),
        'provider_name': app.config['SITE_TITLE'],
        'thumbnail_width': 200,
        'thumbnail_height': 200,
        'thumbnail_url': url_for('static', filename='img/hasjob-logo-200x200.png', _external=True),
        'author_name': board.title if board else app.config['SITE_TITLE'],
        'author_url': board.url_for(_external=True) if board else url_for('index', subdomain=None, _external=True),
        'title': ' | '.join([board.title, board.caption]) if board else app.config['SITE_TITLE'],
        'html': ('<iframe id="{iframeid}" src="{url}" '
            'width="100%" height="724" frameborder="0" scrolling="no">'.format(
                url=embed_url, iframeid=iframeid)),
        'version': '1.0',
        'type': 'rich'
        })

    return jsonify({})
示例#4
0
 def test_localhost_sub(self):
     assert endpoint_for('http://localhost/sub') == (None, {})
示例#5
0
 def test_subexample_slashed(self):
     assert endpoint_for('http://sub.example.com/slashed/') == (None, {})
示例#6
0
 def test_subexample_unslashed_noredirect(self):
     assert endpoint_for('http://sub.example.com/slashed',
                         follow_redirects=False) == (None, {})
示例#7
0
 def test_localhost_sub(self):
     assert endpoint_for('http://localhost/sub') == ('un_subdomained', {})
示例#8
0
 def test_example_slashed(self):
     assert endpoint_for('http://example.com/slashed/') == ('slashed', {})
示例#9
0
 def test_subexample_index(self):
     assert endpoint_for('http://sub.example.com/') == ('index', {})
示例#10
0
 def test_localhost_unslashed_noredirect(self):
     assert endpoint_for('http://localhost/slashed', follow_redirects=False) == (None, {})
示例#11
0
 def test_localhost_unslashed_noredirect(self):
     assert endpoint_for('http://localhost/slashed',
                         follow_redirects=False) == (
                             None,
                             {},
                         )
示例#12
0
 def test_localhost_index(self):
     assert endpoint_for('http://localhost/') == (None, {})
示例#13
0
 def test_localhost_unslashed(self):
     assert endpoint_for('http://localhost/slashed') == (None, {})
示例#14
0
 def test_subexample_sub(self):
     assert endpoint_for('http://sub.example.com/sub') == ('un_subdomained', {})
示例#15
0
 def test_subexample_unslashed_noredirect(self):
     assert endpoint_for('http://sub.example.com/slashed', follow_redirects=False) == (None, {})
示例#16
0
 def test_subexample_unslashed(self):
     assert endpoint_for('http://sub.example.com/slashed') == ('slashed', {})
示例#17
0
 def test_subexample_slashed(self):
     assert endpoint_for('http://sub.example.com/slashed/') == (None, {})
示例#18
0
 def test_localhost_sub(self):
     assert endpoint_for('http://localhost/sub') == (None, {})
示例#19
0
 def test_localhost_unslashed(self):
     assert endpoint_for('http://localhost/slashed') == ('slashed', {})
示例#20
0
 def test_example_index(self):
     assert endpoint_for('http://example.com/') == ('index', {})
示例#21
0
 def test_localhost_sub(self):
     assert endpoint_for('http://localhost/sub') == ('un_subdomained', {})
示例#22
0
 def test_example_slashed(self):
     assert endpoint_for('http://example.com/slashed/') == ('slashed', {})
示例#23
0
 def test_example_sub(self):
     assert endpoint_for('http://example.com/sub') == ('un_subdomained', {})
示例#24
0
 def test_subexample_index(self):
     assert endpoint_for('http://sub.example.com/') == (None, {})
示例#25
0
 def test_subexample_unslashed(self):
     assert endpoint_for('http://sub.example.com/slashed') == ('slashed',
                                                               {})
示例#26
0
 def test_localhost_slashed(self):
     assert endpoint_for('http://localhost/slashed/') == (None, {})
示例#27
0
 def test_localhost_index(self):
     assert endpoint_for('http://localhost/') == (None, {})
示例#28
0
 def test_localhost_slashed(self):
     assert endpoint_for('http://localhost/slashed/') == ('slashed', {})