Last active
August 29, 2015 14:16
-
-
Save adampash/474cd07349a675177bdf to your computer and use it in GitHub Desktop.
JSONP request to kinja GET post api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ = require 'jquery' | |
module.exports = PostGetter = | |
api: "http://kinja.com/api/core/post" | |
isLink: (link) -> | |
@newLink(link) or @oldLink(link) | |
newLink: (link) -> | |
link.match(/-(\d+)\/?/) | |
oldLink: (link) -> | |
link.match(/\.com\/\d+\//) | |
postId: (link) -> | |
if @newLink(link) | |
link.match(/-(\d+)\/?/)[1] | |
else | |
link.match(/\.com\/(\d+)\//)[1] | |
apiURL: (postId) -> | |
"#{@api}/#{postId}" | |
getPost: (postId, complete) -> | |
url = @apiURL(postId) | |
$.ajax | |
url: url | |
dataType: "jsonp" | |
jsonp: 'jsonp' | |
success: (post) => | |
type = $('input[name=roundup-type]:checked', '.radios').val() | |
if post.data.starterId is post.data.id | |
complete(post) if complete? | |
else | |
complete(post) if complete? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment