Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Subscriptions api #3909

Merged
merged 6 commits into from
Feb 9, 2016
Merged

Subscriptions api #3909

merged 6 commits into from
Feb 9, 2016

Conversation

aandis
Copy link
Contributor

@aandis aandis commented Jan 30, 2016

Still WIP.

Added GET to show all subscriptions of a user along with filtering on team slug.
References #3460

@aandis
Copy link
Contributor Author

aandis commented Jan 30, 2016

From #3460 (comment)

One thing we had on the old tips.json was the ability to bulk update a bunch of tips in one POST. The Khan Academy setup used that, e.g.

payment_instruction.json doesn't support batch subscription creation and it also exposes some extra information not relevant to this endpoint. So, I thought I'd leave it alone and ditch the redirection thing and add all functionality directly to this.

@aandis
Copy link
Contributor Author

aandis commented Jan 30, 2016

So if that sounds good @rohitpaulk , @whit537, I'll go ahead and add POST to this to support batch updates.

@aandis aandis added the Review label Jan 30, 2016
@aandis
Copy link
Contributor Author

aandis commented Jan 30, 2016

Would appreciate a quick code review as well. :)

raise Response(403, _("Please sign in first."))

else:
participant = user.participant
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use get_participant here to make sure the user exists, and that the authenticated user has the necessary permissions to access the endpoint. The current way this is implemented, looks like hitting www/~/aandis/subscriptions.json.spt is not going to give me (logged in as rohitpaulk) a 403/404, it is going to return my own subscriptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah. I was yet to change that.

@aandis
Copy link
Contributor Author

aandis commented Jan 30, 2016

@rohitpaulk POST still doesn't work for me. Do you have any idea why? See #3460 (comment)

@aandis
Copy link
Contributor Author

aandis commented Jan 31, 2016

Added changes discussed. Yet to find a way around #3460 (comment)

@aandis
Copy link
Contributor Author

aandis commented Feb 1, 2016

Alright. Fixed #3460 (comment). 💃 Ended up modifying this after digging for a couple of hours. Looks correct to me. Not really sure if this will happen on prod too. If it does, we should fix this in aspen.
Anyway, I'll continue with POST later today! :)

@aandis
Copy link
Contributor Author

aandis commented Feb 1, 2016

POST added. 💃 Review needed.

btw Fixing #3460 (comment) made github and other provider's sign up redirects to stop working. I am sensing it's an ssl thing. But it's way easier for development compared to setting up ssl. 😉

@aandis aandis added Review and removed Review labels Feb 1, 2016
@techtonik
Copy link
Contributor

What users are subscribed to?

@aandis
Copy link
Contributor Author

aandis commented Feb 1, 2016

Giving to teams @techtonik. See #3460 for details. :)

@chadwhitacre
Copy link
Contributor

POST added. 💃

!m @aandis :)

@chadwhitacre
Copy link
Contributor

@aandis First thing I notice is that we'll need some tests for this endpoint.

@aandis
Copy link
Contributor Author

aandis commented Feb 1, 2016

Yep. That's next. Figured I should first review then write tests. :)

@techtonik
Copy link
Contributor

That sounds strange. When I subscribe to something (especially for something), I expect to receive something. If I have a lot of subscribers, I automatically feel obliged to do something in exchange.

If we are still for "giving with no strings attached" then maybe there is a better term? Facebook has "liking", newspapers and lists have "subscribing", and when we send money the closest term is "supporting", but if we want more involvement and more positive value on the receiver's end, how do we call it? "links" to the causes, so we "link" people with "projects" and use "routes" to send them gratitude in the emotionless form of money that can be used to do something good for them. =)

@chadwhitacre
Copy link
Contributor

@aandis Gotcha.

@chadwhitacre
Copy link
Contributor

@techtonik You raise a good point: over in gratipay/inside.gratipay.com#117 we decided to go with "payment instructions" instead of "subscriptions" (gratipay/inside.gratipay.com#117 (comment) notwithstanding). Presumably #3460 predates that decision.

@aandis Let's go ahead and switch from "subscription" to "payment instruction" here. That'll line up with the database table and set_payment_instruction method name, as well.

@chadwhitacre
Copy link
Contributor

You raise a good point

(Though we are no longer "for 'giving with no strings attached,'" post-gratipay/inside.gratipay.com#180 and pre-gratipay/inside.gratipay.com#423 .)


slug = request.qs.get("team_slug", "")

if slug: # Filter subscription info only for this team from the list.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this intended to related to the existing %team/payment-instruction.json.spt API? Looks like it at least partially duplicates the functionality over there. Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only thing similar between them as of now is GET with team filter. But team/payment-instruction.json.spt returns a different response which isn't really relevant to this api. This endpoint offers an additional GET without a team filter to show all subscriptions of a user. Per #3909 (comment), we should maintain consistency in the api responses. Hence everything is implemented right here.

@aandis
Copy link
Contributor Author

aandis commented Feb 2, 2016

Let's go ahead and switch from "subscription" to "payment instruction"

Alright, will do. :)

@aandis aandis force-pushed the subscriptions-api branch 2 times, most recently from 8db0f72 to eebf8f8 Compare February 3, 2016 18:19
@chadwhitacre
Copy link
Contributor

@aandis Yeah that's most of it. We'd need some tests to land a PR in Aspen, and Aspen is undergoing big changes right now so you can decide if you want to spend time on that. :) The workaround would be to do hxt('PATCH', ...).

@aandis
Copy link
Contributor Author

aandis commented Feb 5, 2016

Cool. I'll look into it. Thanks :)

@aandis
Copy link
Contributor Author

aandis commented Feb 6, 2016

Readme updated. 💃

@chadwhitacre
Copy link
Contributor

@aandis Nice! Can you rebase this PR branch onto the latest master? Seems we have conflicts.

@aandis
Copy link
Contributor Author

aandis commented Feb 7, 2016

👍

@chadwhitacre
Copy link
Contributor

README looks fine. I hard-wrapped the new paragraphs and added a missing space in 63c74dd.

I think this is ready to go!

Except that ... @rohitpaulk Didn't you say somewhere that you want to move to /api/v1/ style endpoints? Was that a blocker for this PR?

@rohitpaulk
Copy link
Contributor

Was that a blocker for this PR?

Not a blocker

chadwhitacre added a commit that referenced this pull request Feb 9, 2016
@chadwhitacre chadwhitacre merged commit ca9c608 into master Feb 9, 2016
@chadwhitacre chadwhitacre deleted the subscriptions-api branch February 9, 2016 19:53
@chadwhitacre
Copy link
Contributor

!m @aandis

@aandis
Copy link
Contributor Author

aandis commented Feb 9, 2016

@whit537 If you have deployed this, can you confirm that POST to this endpoint works? I think I am still seeing signs of #3460 (comment) on production.

@chadwhitacre
Copy link
Contributor

@aandis It's working for me (and I found a good example of #3876 ;).

screen shot 2016-02-09 at 3 32 58 pm

screen shot 2016-02-09 at 3 32 42 pm

@chadwhitacre
Copy link
Contributor

(The second payment instruction is the one that changes in those screenshots—I guess including 0.00 tips is okay, so we can use this for the "Canceled" tab on the Giving page if we want. The first one to sudo room demonstrates the runaway dues.)

@aandis
Copy link
Contributor Author

aandis commented Feb 9, 2016

Heh okay! I see now. All this time I had been hitting /~/aandis/payment-instructions.json instead of /~aandis/payment-instructions.json. The former redirects and becomes a GET.

@aandis
Copy link
Contributor Author

aandis commented Feb 9, 2016

Learnt about http redirect methods in depth while overcoming this though. So all good in the end I guess. ;)

@aandis
Copy link
Contributor Author

aandis commented Feb 9, 2016

The doc instructs to hit /aandis/payment-instructions.json which also doesn't work. Should change that.

@aandis
Copy link
Contributor Author

aandis commented Feb 9, 2016

Ideally though, all these routes should work with POST too because a GET to any of them will give you identical response.

@chadwhitacre
Copy link
Contributor

All this time I had been hitting /~/aandis/payment-instructions.json

Oh no! 🙀 Glad you figured it out. :)

The doc instructs to hit /aandis/payment-instructions.json which also doesn't work. Should change that.

#3916, ya?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants