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

Proposed by Anthony Lenton
Status: Merged
Approved by: Łukasz Czyżykowski
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
sreclient.py (+9/-2)
To merge this branch: bzr merge lp:~elachuni/ubuntu-recommender/client-uuid-recommend-me
Reviewer Review Type Date Requested Status
Łukasz Czyżykowski (community) Approve
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.
Revision history for this message
Łukasz Czyżykowski (lukasz-czyzykowski) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'sreclient.py'
--- sreclient.py 2012-02-14 13:15:07 +0000
+++ sreclient.py 2012-03-28 20:05:22 +0000
@@ -40,8 +40,15 @@
40 scheme=PUBLIC_API_SCHEME)40 scheme=PUBLIC_API_SCHEME)
4141
42 @oauth_protected42 @oauth_protected
43 def recommend_me(self):43 @validate_pattern('uuid', r'[\dabcdef]{32}')
44 return self._get('recommend_me/', scheme=AUTHENTICATED_API_SCHEME)44 def recommend_me(self, uuid):
45 return self._get('recommend_me/%s/' % uuid,
46 scheme=AUTHENTICATED_API_SCHEME)
47
48 @validate_pattern('uuid', r'[\dabcdef]{32}')
49 def anon_recommend_me(self, uuid):
50 return self._get('recommend_me/%s/' % uuid,
51 scheme=AUTHENTICATED_API_SCHEME)
4552
46 @validate_pattern('pkgname', '[^/]+')53 @validate_pattern('pkgname', '[^/]+')
47 @returns_json54 @returns_json

Subscribers

People subscribed via source and target branches