Created
July 27, 2014 15:12
-
-
Save xl1/58e33a3eb13d5a47a1e2 to your computer and use it in GitHub Desktop.
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
api = require('./urlmapper')('https://api.example.com/v1') | |
api.users.GET(limit: 1) | |
.then ([user]) -> | |
console.log user.name, user.age | |
api.users[user.id].posts.GET() | |
.then (posts) -> | |
posts.forEach ({ content }) -> console.log content |
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 'harmony-reflect' | |
Promise = require 'bluebird' | |
module.exports = createUrlMapper = (base) -> | |
new Proxy {}, | |
get: (target, name) -> | |
if /^[A-Z]+$/.test name | |
(data) -> | |
Promise.resolve $.ajax(base, method: name, data: data) | |
else | |
createUrlMapper "#{base}/#{encodeURIComponent name}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment