当前位置: 首页>>代码示例>>Python>>正文


Python api.Client类代码示例

本文整理汇总了Python中spreedly.pyspreedly.api.Client的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: spreedly_listener

def spreedly_listener(request):
    if request.method == 'POST':
        # Try to extract customers' IDs
        if request.POST.has_key('subscriber_ids'):
            subscriber_ids = request.POST['subscriber_ids'].split(',')
            if len(subscriber_ids):
                client = Client(settings.SPREEDLY_AUTH_TOKEN, settings.SPREEDLY_SITE_NAME)
                for id in subscriber_ids:
                    # Now let's query Spreedly API for the actual changes
                    data = client.get_info(int(id))
                    try:
                        user = User.objects.get(pk=id)


                        subscription, created = Subscription.objects.get_or_create(user=user)
                            
                        for k, v in data.items():
                            if hasattr(subscription, k):
                                setattr(subscription, k, v)
                        subscription.save()
                        
                        signals.subscription_update.send(sender=subscription, user=User.objects.get(id=id))
                    except User.DoesNotExist:
                        # TODO not sure what exactly to do here. Delete the subscripton on spreedly?
                        pass
                #handle gifts
                for gift in Gift.objects.filter(to_user__pk__in=subscriber_ids):
                    gift.send_activation_email()
    return HttpResponse() #200 OK
开发者ID:atkinson,项目名称:django-spreedly,代码行数:29,代码来源:views.py

示例2: spreedly_listener

def spreedly_listener(request):
    if request.method == 'POST':
        # Try to extract customers' IDs
        if request.POST.has_key('subscriber_ids'):
            subscriber_ids = request.POST['subscriber_ids'].split(',')
            failed_ids = []
            if len(subscriber_ids):
                client = Client(settings.SPREEDLY_AUTH_TOKEN_SECRET, settings.SPREEDLY_SITE_NAME)
                for id in subscriber_ids:
                    # Now let's query Spreedly API for the actual changes
                    data = client.get_info(int(id))
                    
                    try:
                        user = User.objects.get(pk=id)                    
                        subscription, created = Subscription.objects.get_or_create(user=user)
                        for k, v in data.items():
                            if hasattr(subscription, k):
                                setattr(subscription, k, v)
                        subscription.save()
                    except User.DoesNotExist, e:
                        failed_ids.append(id)
                        
                if failed_ids:
                    links = "\n".join([subscriber_url(id) for id in failed_ids])
                    
                    mail_admins(
                        subject="Could not update Spreedly Subscriptions",
                        message="The following subscribers changed on Spreedly, but there's no corresponding User:\n%s" % links
                    )
                    
                return HttpResponse("OK")
开发者ID:robot-republic,项目名称:django-spreedly,代码行数:31,代码来源:views.py

示例3: start_free_trial

def start_free_trial(plan, user):
    if check_trial_eligibility(plan, user):
        client = Client(settings.SPREEDLY_AUTH_TOKEN, settings.SPREEDLY_SITE_NAME)
        client.get_or_create_subscriber(user.id, user.username)
        client.subscribe(user.id, plan.pk, trial=True)
        get_subscription(user)
        return True
    else:
        return False
开发者ID:ccg,项目名称:django-spreedly,代码行数:9,代码来源:functions.py

示例4: start_free_trial

def start_free_trial(plan, user, site=DEFAULT_SITE_ALIAS):
    site=get_site(site)

    if check_trial_eligibility(plan, user):
        client = Client(site['SPREEDLY_AUTH_TOKEN_SECRET'], site['SPREEDLY_SITE_NAME'])
        client.get_or_create_subscriber(user.id, user.username)
        client.subscribe(user.id, plan.pk, trial=True)
        get_subscription(user)
        return True
    else:
        return False
开发者ID:,项目名称:,代码行数:11,代码来源:

示例5: get_or_create_subscription

def get_or_create_subscription(user):
    client = Client(settings.SPREEDLY_AUTH_TOKEN_SECRET, settings.SPREEDLY_SITE_NAME)
    data = client.get_or_create_subscriber(user.id, user.username)

    subscription, created = Subscription.objects.get_or_create(
        user=user
    )
    for k, v in data.items():
        if hasattr(subscription, k):
            setattr(subscription, k, v)
    subscription.save()
    return subscription
开发者ID:robot-republic,项目名称:django-spreedly,代码行数:12,代码来源:functions.py

示例6: get_subscription

def get_subscription(user):
    client = Client(settings.SPREEDLY_AUTH_TOKEN, settings.SPREEDLY_SITE_NAME)
    data = client.get_info(user.id)
    
    subscription, created = Subscription.objects.get_or_create(
        user=user
    )
    for k, v in data.items():
        if hasattr(subscription, k):
            setattr(subscription, k, v)
    subscription.save()
    signals.subscription_update.send(sender=subscription, user=user)
    return subscription
开发者ID:ccg,项目名称:django-spreedly,代码行数:13,代码来源:functions.py

示例7: get_or_create_subscription

def get_or_create_subscription(user, site=DEFAULT_SITE_ALIAS):
    site=get_site(site)

    client = Client(site['SPREEDLY_AUTH_TOKEN_SECRET'], site['SPREEDLY_SITE_NAME'])
    data = client.get_or_create_subscriber(user.id, user.username)
    
    subscription, created = Subscription.objects.get_or_create(
        user=user,
        spreedly_site_name=site['SPREEDLY_SITE_NAME']
    )
    for k, v in data.items():
        if hasattr(subscription, k):
            setattr(subscription, k, v)
    subscription.save()
    return subscription
开发者ID:,项目名称:,代码行数:15,代码来源:

示例8: TestSubscription

class TestSubscription(TestCase):
    def setUp(self):
        user = User.objects.create(username='test')
        self.sclient = Client(settings.SPREEDLY_AUTH_TOKEN_SECRET, settings.SPREEDLY_SITE_NAME)
    
    def tearDown(self):
        # Remove all subscribers
        self.sclient.cleanup()
    
    def test_sync_plans(self):
        # Initial sync
        spreedly_count = len(self.sclient.get_plans())
        sync_plans()
        qs = Plan.objects.all()
        self.assertEquals(qs.count(), spreedly_count)
开发者ID:guitarparty,项目名称:django-spreedly,代码行数:15,代码来源:tests.py

示例9: sync_plans

def sync_plans():
    '''
    Sync subscription plans with Spreedly API
    '''
    client = Client(settings.SPREEDLY_AUTH_TOKEN, settings.SPREEDLY_SITE_NAME)
    
    for plan in client.get_plans():
        p, created = Plan.objects.get_or_create(spreedly_id=plan['spreedly_id'])
        
        changed = False
        for k, v in plan.items():
            if hasattr(p, k) and not getattr(p, k) == v:
                setattr(p, k, v)
                changed = True
        if changed:
            p.save()
开发者ID:ccg,项目名称:django-spreedly,代码行数:16,代码来源:functions.py

示例10: save

 def save(self):
     # remove any inactive users with this same username
     try:
         old_user = User.objects.get(username=self.cleaned_data['username'], is_active=False)
         old_user.delete()
     except User.DoesNotExist:
         pass
     gift = Gift.objects.get(uuid=self.cleaned_data["gift_key"])
     user = gift.to_user
     user.username = self.cleaned_data['username']
     user.email = self.cleaned_data['email']
     user.set_password(self.cleaned_data['password1'])
     user.is_active=True
     user.save()
     #update spreedly info
     client = Client(settings.SPREEDLY_AUTH_TOKEN, settings.SPREEDLY_SITE_NAME)
     client.set_info(user.pk, email=user.email, screen_name=user.username)
     gift.delete()
     return user
开发者ID:atkinson,项目名称:django-spreedly,代码行数:19,代码来源:forms.py

示例11: spreedly_listener

def spreedly_listener(request):
    if request.method == 'POST':
        # Try to extract customers' IDs
        if request.POST.has_key('subscriber_ids'):
            subscriber_ids = request.POST['subscriber_ids'].split(',')
            
            if len(subscriber_ids):
                client = Client(settings.SPREEDLY_AUTH_TOKEN_SECRET, settings.SPREEDLY_SITE_NAME)
                for id in subscriber_ids:
                    # Now let's query Spreedly API for the actual changes
                    data = client.get_info(int(id))
                    subscription, created = Subscription.objects.get_or_create(
                        user__pk=id
                    )
                    for k, v in data.items():
                        if hasattr(subscription, k):
                            setattr(subscription, k, v)
                    subscription.save()
                return HttpResponse("OK")
    raise Http404
开发者ID:jsmelquist,项目名称:django-spreedly,代码行数:20,代码来源:views.py

示例12: sync_plans

def sync_plans():
    '''
    Sync subscription plans with Spreedly API
    '''

    for key, site in settings.SPREEDLY_SITES.items():

        client = Client(site['SPREEDLY_AUTH_TOKEN_SECRET'], site['SPREEDLY_SITE_NAME'])
        
        for plan in client.get_plans():
            print plan['speedly_id'], site['SPREEDLY_SITE_NAME']
            p, created = Plan.objects.get_or_create(speedly_id=plan['speedly_id'], spreedly_site_name=site['SPREEDLY_SITE_NAME'])
            
            changed = False
            for k, v in plan.items():
                if hasattr(p, k) and not getattr(p, k) == v:
                    setattr(p, k, v)
                    changed = True
            if changed:
                p.save()
开发者ID:,项目名称:,代码行数:20,代码来源:

示例13: admin_gift

def admin_gift(request):
    if request.method == 'POST':
        form = AdminGiftForm(request.POST)
        if form.is_valid():
            user = form.save(request)
            
            client = Client(settings.SPREEDLY_AUTH_TOKEN, settings.SPREEDLY_SITE_NAME)
            client.create_subscriber(user.pk, user.email)
            client.create_complimentary_subscription(user.pk, form.cleaned_data['time'], form.cleaned_data['units'], form.cleaned_data['feature_level'])
            user.gifts_received.latest('id').send_activation_email()
            get_subscription(user)
    else:
        form = AdminGiftForm()
    
    
    return render_to_response(
        spreedly_settings.SPREEDLY_ADMIN_GIFT_TEMPLATE,
        {'form': form},
        context_instance=RequestContext(request),
    )
开发者ID:atkinson,项目名称:django-spreedly,代码行数:20,代码来源:views.py

示例14: get_subscription

def get_subscription(user, site=DEFAULT_SITE_ALIAS):

    site=get_site(site)

    cache_key = 'spreedly-subscription-%d' % user.id

    subscription = cache.get(cache_key)

    if not subscription:
        client = Client(site['SPREEDLY_AUTH_TOKEN_SECRET'], site['SPREEDLY_SITE_NAME'])
        data = client.get_info(user.id)
    
        subscription, created = Subscription.objects.get_or_create(
            user=user,
            spreedly_site_name=site['SPREEDLY_SITE_NAME']
        )
        for k, v in data.items():
            if hasattr(subscription, k):
                setattr(subscription, k, v)
        subscription.save()
        cache.set(cache_key, subscription, 60 * 60)

    return subscription
开发者ID:,项目名称:,代码行数:23,代码来源:

示例15: stop_auto_renew

def stop_auto_renew(user):
    client = Client(settings.SPREEDLY_AUTH_TOKEN_SECRET, settings.SPREEDLY_SITE_NAME)
    client.stop_auto_renew(user.id)
    return get_subscription(user)
开发者ID:robot-republic,项目名称:django-spreedly,代码行数:4,代码来源:functions.py


注:本文中的spreedly.pyspreedly.api.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。