Merge lp:~elachuni/ubuntu-recommender/client-uuid-recommend-me into lp:~canonical-ca-hackers/ubuntu-recommender/ubuntu-recommender-client

Proposed by Anthony Lenton on 2012-03-28
Status: Merged
Approved by: Łukasz Czyżykowski on 2012-03-30
Approved revision: 6
Merged at revision: 6
Proposed branch: lp:~elachuni/ubuntu-recommender/client-uuid-recommend-me
Merge into: lp:~canonical-ca-hackers/ubuntu-recommender/ubuntu-recommender-client
Diff against target: 21 lines (+9/-2) 1 file modified
To merge this branch: bzr merge lp:~elachuni/ubuntu-recommender/client-uuid-recommend-me
Reviewer Review Type Date Requested Status
Łukasz Czyżykowski 2012-03-28 Approve on 2012-03-30
Review via email: mp+99812@code.launchpad.net

Description of the Change

One way of providing a version of recommend_me that only requires a uuid. I could think of two other alternatives for this:
 - A single method with an "authenticated" bool argument, but if you (the caller) would need to have instantiated the client with an OAuth authorizer already (or set it as an instance variable just before calling the method)
 - A single method that receives an optional "authorizer" argument, so that you could pass in an OAuth authorizer when you go to make the call. I think this would be nicer, but completely inconsistent with other client code out there (and with other authenticated methods on this same class).

The current approach has the downside that it provides two different methods for what translates to a single API call, but I think we'd need to have two call sites already. I imagine the client code will be something like:

    if self.has_a_token:
        authorizer = OAuthAuthorizer(token, secret, bitties, ...)
        api = SoftwareCenterRecommenderAPI(auth=authorizer)
        recommendations = api.recommend_me(self.my_uuid)
    else:
        api = SoftwareCenterRecommenderAPI()
        recommendations = api.anon_recommend_me(self.my_uuid)

Let me know if you think some other alternative would be better!

To post a comment you must log in.

LGTM

review: Approve

Preview Diff

1=== modified file 'sreclient.py'
2--- sreclient.py 2012-02-14 13:15:07 +0000
3+++ sreclient.py 2012-03-28 20:05:22 +0000
4@@ -40,8 +40,15 @@
5 scheme=PUBLIC_API_SCHEME)
6
7 @oauth_protected
8- def recommend_me(self):
9- return self._get('recommend_me/', scheme=AUTHENTICATED_API_SCHEME)
10+ @validate_pattern('uuid', r'[\dabcdef]{32}')
11+ def recommend_me(self, uuid):
12+ return self._get('recommend_me/%s/' % uuid,
13+ scheme=AUTHENTICATED_API_SCHEME)
14+
15+ @validate_pattern('uuid', r'[\dabcdef]{32}')
16+ def anon_recommend_me(self, uuid):
17+ return self._get('recommend_me/%s/' % uuid,
18+ scheme=AUTHENTICATED_API_SCHEME)
19
20 @validate_pattern('pkgname', '[^/]+')
21 @returns_json

Subscribers

People subscribed via source and target branches