Skip to content

Instantly share code, notes, and snippets.

@adampash
Last active August 29, 2015 14:16
Show Gist options
  • Save adampash/474cd07349a675177bdf to your computer and use it in GitHub Desktop.
Save adampash/474cd07349a675177bdf to your computer and use it in GitHub Desktop.
JSONP request to kinja GET post api
$ = 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