Skip to content

Instantly share code, notes, and snippets.

@jeremiak
Created July 9, 2014 21:56
Show Gist options
  • Save jeremiak/a6e803640992a797e637 to your computer and use it in GitHub Desktop.
Save jeremiak/a6e803640992a797e637 to your computer and use it in GitHub Desktop.
return the return of the return
var $ = require('jquery')
var Home = require('./models/home')
function homeFromJSON(json) {
var json = JSON.parse(json)
var data = {
id: json.id,
quote: 'string',
address: json.address,
type: 'string',
data: [],
owner: {}
}
var home = new Home(data)
console.log(home)
return home
}
var APIClient = function() {
var APIRoot = 'http://www.corsproxy.com/bestnest-api-dev.herokuapp.com/'
return {
fetch: function(endpoint) {
return $.ajax({
url: APIRoot + endpoint
})
},
getHome: function(id, cb) {
return this.fetch('buildings/'+id)
.done(homeFromJSON)
},
search: function(text, cb) {
console.log('Search currently not implemented, good luck finding', text)
}
}
}
module.exports = APIClient
@junosuarez
Copy link

you could do something like

var $ = require('jquery')

var Home = require('./models/home')

function homeFromJSON(json) {
  var json = JSON.parse(json)
  var data = {
    id: json.id,
    quote: 'string',
    address: json.address,
    type: 'string',
    data: [],
    owner: {}
  }
  var home = new Home(data)
  console.log(home)
  return home
}

var APIClient = function() {
  var APIRoot = 'http://www.corsproxy.com/bestnest-api-dev.herokuapp.com/'

  var fetch = function(endpoint) {
    return $.ajax({
      url: APIRoot + endpoint
    })
  } 

  return {
    fetch: fetch,
    getHome: function(id, cb) {
      return fetch('buildings/'+id)
        .then(homeFromJSON)
    },
    search: function(text, cb) {
      console.log('Search currently not implemented, good luck finding', text)
    }
  }
}

module.exports = APIClient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment