class ClientTests(unittest.TestCase): """ Client tests using example. """ def setUp(self): """ Runs before each test. """ self.c = HttpClient('http://localhost:8000/api','sharrock_example','1.0') def tearDown(self): """ Runs after each test. """ self.c = None def test_hello_world(self): """ Tests the hello world app. """ result = self.c.helloworld() self.assertEquals(result,'Hello world!') new_result = self.c.helloworld(name='Loren') self.assertEquals(new_result,'Hello Loren!') def test_post_data(self): """ Tests the post data service. """ result = self.c.postdata(data={'foo':'bar'}) self.assertEquals(result['grommit'],'bar')
class ClientTests(unittest.TestCase): """ Client tests using example. """ def setUp(self): """ Runs before each test. """ self.c = HttpClient('http://localhost:8000/api', 'sharrock_example', '1.0') def tearDown(self): """ Runs after each test. """ self.c = None def test_hello_world(self): """ Tests the hello world app. """ result = self.c.helloworld() self.assertEquals(result, 'Hello world!') new_result = self.c.helloworld(name='Loren') self.assertEquals(new_result, 'Hello Loren!') def test_post_data(self): """ Tests the post data service. """ result = self.c.postdata(data={'foo': 'bar'}) self.assertEquals(result['grommit'], 'bar')
def _get_client(app,library=True): """ Gets a regular API client. """ cfg = get_cfg() apikey_setting = 'library_key' if library else 'api_key' return HttpClient('%s/api' % cfg.get('Connection','endpoint'),app,'beta3',auth_user=cfg.get('Connection',apikey_setting))
from sharrock.client import HttpClient, ResourceClient from django.shortcuts import render_to_response from django.template import RequestContext from sharrock.client import HttpClient, ResourceClient from django.conf import settings from django.http import HttpResponseRedirect axl = HttpClient('%s/api' % settings.AXILENT_ENDPOINT, 'axilent.content', 'beta3', auth_user=settings.AXILENT_API_KEY) content_resource = ResourceClient('%s/api/resource' % settings.AXILENT_ENDPOINT, 'axilent.content', 'beta3', 'content', auth_user=settings.AXILENT_API_KEY) triggers = HttpClient('%s/api' % settings.AXILENT_ENDPOINT, 'axilent.triggers', 'beta3', auth_user=settings.AXILENT_API_KEY) def home(request, whiskey_slug=None): """ Mobile home page. """ featured_whiskey = None if whiskey_slug: featured_whiskey = axl.getcontentbyuniquefield( content_type='Whiskey',
from django import forms from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ import uuid from django.contrib import auth from whiskeyengine.models import Drinker, Review from django.conf import settings from sharrock.client import HttpClient c = HttpClient(settings.SAASPIRE_API, 'saaspire.triggers', '0.1dev', auth_user=settings.SAASPIRE_API_KEY) class UseMobileForm(forms.Form): use_mobile = forms.ChoiceField(choices=(('y', 'y'), ('n', 'n'))) class UserProfileForm(forms.ModelForm): class Meta: model = Drinker exclude = ('user', 'shelf', 'registered', 'wishlist', 'pic', 'saaspire_profile') class UserProfileWithPicForm(forms.ModelForm): class Meta: model = Drinker exclude = ('user', 'registered', 'shelf', 'wishlist', 'saaspire_profile')
def client(axilent_app): """ Gets a basic http client. """ return HttpClient('%s%s' % (end_point,api_path),axilent_app,api_version,auth_user=api_key)
""" Saspire integration. """ from django.conf import settings from whiskeyengine.models import Whiskey from sharrock.client import HttpClient c = HttpClient(settings.SAASPIRE_API,'saaspire.content','0.1dev',auth_user=settings.SAASPIRE_API_KEY) def profile(request): """ Attempts to retrieve the profile from the request. """ return request.COOKIES.get('saaspire.profile',None) def load_whiskies(policy): """ Loads the whiskies from the policy result. """ loaded_whiskey = [] results = policy['default'] # only using default group for result in results: content_key = result['content']['key'] loaded_whiskey.append(Whiskey.objects.get(saaspire_key=content_key)) return loaded_whiskey def get_related_whiskies(basekey,profile=None): """ Gets whiskies related to the basekey whiskey. """
def setUp(self): """ Runs before each test. """ self.c = HttpClient('http://localhost:8000/api','sharrock_example','1.0')
def setUp(self): """ Runs before each test. """ self.c = HttpClient('http://localhost:8000/api', 'sharrock_example', '1.0')
# from the whiskey engine example # uses the Sharrock RPC client (https://github.com/Axilent/sharrock). Created by us, but open source, not specific to the Axilent API. from sharrock.client import HttpClient, ResourceClient # some things in the API are modeled as RESTful resources and use the ResourceClient, others are straight RPC and use the HttpClient axl = HttpClient('%s/api' % settings.AXILENT_ENDPOINT,'axilent.content','beta3',auth_user=settings.AXILENT_API_KEY) content_resource = ResourceClient('%s/api/resource' % settings.AXILENT_ENDPOINT,'axilent.content','beta3','content',auth_user=settings.AXILENT_API_KEY) # Featured Whiskey featured_whiskey = None if whiskey_slug: # In this case the name of the whiskey has been specified featured_whiskey = axl.getcontentbyuniquefield(content_type='Whiskey',field_name='slug',field_value=whiskey_slug) else: # In this case we're pulling from a content channel - it's set to random, but can be changed in Axilent at any time # without any reprogramming here. featured_whiskey = axl.contentchannel(channel='random-whiskey')['default'][0]['content'] # Search results = axl.search(content_types='Whiskey',query=request.GET['q']) # 'q' is the query