Example #1
0
    def test_validate(self):
        service = Bitly(login=self.login, api_key=self.api_key)
        result = service.validate()
        self.assertEqual(True, result)

        result = service.validate(login=self.login+'x', api_key=self.api_key)
        self.assertEqual(False, result)
Example #2
0
    def test_validate(self):
        service = Bitly(login=self.login, api_key=self.api_key)
        result = service.validate()
        self.assertEqual(True, result)

        result = service.validate(login=self.login+'x', api_key=self.api_key)
        self.assertEqual(False, result)
Example #3
0
    def test_shorten_url_with_domain(self):
        service = Bitly(login=self.login, api_key=self.api_key)

        for domain in ('bit.ly', 'j.mp', 'bitly.com'):
            generated_short_url = service.shorten_url(self.test_long_url, domain=domain)
            expected_short_url = 'http://' + domain + '/' + self.test_short_url_hash
            self.assertEqual(expected_short_url, generated_short_url)
Example #4
0
    def test_shorten_url_with_domain(self):
        service = Bitly(login=self.login, api_key=self.api_key)

        for domain in ('bit.ly', 'j.mp', 'bitly.com'):
            generated_short_url = service.shorten_url(self.test_long_url, domain=domain)
            expected_short_url = 'http://' + domain + '/' + self.test_short_url_hash
            self.assertEqual(expected_short_url, generated_short_url)
Example #5
0
    def test_expand_url(self):
        service = Bitly(login=self.login, api_key=self.api_key)
        generated_long_url = service.expand_url(self.test_short_url)

        self.assertEqual(self.test_long_url, generated_long_url)
Example #6
0
	def bitly_link(self, link):
		from pyshorturl import Bitly, BitlyError
		bitly = Bitly(boto.config.get("bitly", "username"), boto.config.get('bitly', "api_key"))
		return bitly.shorten_url(link)
Example #7
0
            print 'Unsupported service %s. Supported services are %s.' \
                %(options.service, ', '.join(SUPPORTED_SERVICES))
            sys.exit(-1)
    else:
        options.service = 'goo.gl'

    # Now, instantiate the service object based upon user preference.
    service = None
    if 'goo.gl' == options.service:
        service = Googl(options.svc_api_key)
    elif 'bit.ly' == options.service:
        # bit.ly requires a login account and api key.
        if not options.login or not options.svc_api_key:
            print 'bit.ly requires a valid account and API key.'
            sys.exit(-1)
        service = Bitly(options.login, options.svc_api_key)
    if 'git.io' == options.service:
        service = Gitio()
    elif 'tinyurl.com' == options.service:
        service = TinyUrlcom()
    elif 'v.gd' == options.service:
        service = Vgd()
    elif 'is.gd' == options.service:
        service = Isgd()

    # Get QR code.
    if options.qr_img_path:
        if not options.short_url:
            print 'You need to specify a short url to get qr code.'
            print 'Usage: python %s -s <short_url> -q <image_path>' % (
                sys.argv[0])
Example #8
0
    def test_write_qr_image_v2(self):
        service = Bitly(login=self.login, api_key=self.api_key)
        service.write_qr_image(self.test_short_url, self.qr_image_path)

        self.assertEqual('png', imghdr.what(self.qr_image_path))
Example #9
0
    def test_expand_url(self):
        service = Bitly(login=self.login, api_key=self.api_key)
        generated_long_url = service.expand_url(self.test_short_url)

        self.assertEqual(self.test_long_url, generated_long_url)