Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleaned up echonest.coffee

fixed crash where error is null
  • Loading branch information...
commit 292a8a80ed5b088a4a07c4fccc6ef73e545f05bc 1 parent dc9092b
@badamson authored
View
2  README.md
@@ -56,7 +56,7 @@ Contributing
The echonest.js file distributed by npm is generated from coffeescript, and not checked into the repository. To see it, run `rake build`.
-It's very new, clould be cleaned up and could use some fancier handling of [echonest's response codes](http://developer.echonest.com/docs/v4/index.html#response-codes). It could also probably work outside node.js in a browser without too much work. It's missing some of the slicker stuff from [other client libraries](http://developer.echonest.com/client_libraries.html).
+It could use some fancier handling of [echonest's response codes](http://developer.echonest.com/docs/v4/index.html#response-codes). It could also probably work outside node.js in a browser without too much work. It's missing some of the slicker stuff from [other client libraries](http://developer.echonest.com/client_libraries.html).
Exploring
---------
View
19 lib/echonest.coffee
@@ -17,18 +17,13 @@ class echonest.Echonest
@jsonclient = fermata.json(@host)['api'][@api_version](api_key: @api_key)
api = echonest_api[@api_version]
- for endpoint, httpMethods of api
- httpMethod = httpMethods.post? and 'post' or 'get' # FIXME good enough?
- # build objects on @ from api endpoints, assign functions
- # wrapping request to endpoint
- # FIXME: clean this mess up
- path = endpoint.split('/')
- [beforeTip, tip] = [path[...-1], path[-1...]]
- _.reduce(beforeTip, (memo, x) ->
- memo[x] ||= {}
- , @)[tip] = do (endpoint, httpMethod) =>
+ for endpoint, httpmethod of api
+ # echonest is always just /type/method
+ [type, method] = endpoint.split('/')
+ @[type] ?= {}
+ @[type][method] ?= do (endpoint, httpmethod) =>
(query, callback) =>
- @request(endpoint, query, callback, httpMethod)
+ @request(endpoint, query, callback, httpmethod)
defaultCallback: (err, data) ->
console.log 'err: ', err
@@ -43,7 +38,7 @@ class echonest.Echonest
wrapper = (err, result) =>
callback ?= @defaultCallback
# pluck response
- if result.response?
+ if result?.response?
result = result.response
callback err, result
switch method
View
79 lib/echonest_api.coffee
@@ -1,46 +1,47 @@
module.exports =
'bogusVersion':
- 'totally/fake/endpoint': get: {}
+ 'fake/endpoint': 'get'
+
'v4':
- 'song/search': get: {}
- 'song/profile': get: {}
- 'song/identify': post: {}
+ 'song/search': 'get'
+ 'song/profile': 'get'
+ 'song/identify': 'post'
- 'artist/biographies': get: {}
- 'artist/blogs': get: {}
- 'artist/familiarity': get: {}
- 'artist/hotttnesss': get: {}
- 'artist/images': get: {}
- 'artist/list_terms': get: {}
- 'artist/news': get: {}
- 'artist/profile': get: {}
- 'artist/reviews': get: {}
- 'artist/search': get: {}
- 'artist/extract': get: {}
- 'artist/songs': get: {}
- 'artist/similar': get: {}
- 'artist/suggest': get: {}
- 'artist/terms': get: {}
- 'artist/top_hottt': get: {}
- 'artist/top_terms': get: {}
- 'artist/twitter': get: {}
- 'artist/urls': get: {}
- 'artist/video': get: {}
+ 'artist/biographies': 'get'
+ 'artist/blogs': 'get'
+ 'artist/familiarity': 'get'
+ 'artist/hotttnesss': 'get'
+ 'artist/images': 'get'
+ 'artist/list_terms': 'get'
+ 'artist/news': 'get'
+ 'artist/profile': 'get'
+ 'artist/reviews': 'get'
+ 'artist/search': 'get'
+ 'artist/extract': 'get'
+ 'artist/songs': 'get'
+ 'artist/similar': 'get'
+ 'artist/suggest': 'get'
+ 'artist/terms': 'get'
+ 'artist/top_hottt': 'get'
+ 'artist/top_terms': 'get'
+ 'artist/twitter': 'get'
+ 'artist/urls': 'get'
+ 'artist/video': 'get'
- 'track/analyze': post: {}
- 'track/profile': get: {}
- 'track/upload': post: {}
+ 'track/analyze': 'post'
+ 'track/profile': 'get'
+ 'track/upload': 'post'
- 'playlist/basic': get: {}
- 'playlist/static': get: {}
- 'playlist/dynamic': get: {}
- 'playlist/session_info': get: {}
+ 'playlist/basic': 'get'
+ 'playlist/static': 'get'
+ 'playlist/dynamic': 'get'
+ 'playlist/session_info': 'get'
- 'catalog/create': post: {}
- 'catalog/update': post: {}
- 'catalog/status': get: {}
- 'catalog/profile': get: {}
- 'catalog/read': get: {}
- 'catalog/feed': get: {}
- 'catalog/list': list: {}
- 'catalog/delete': post: {}
+ 'catalog/create': 'post'
+ 'catalog/update': 'post'
+ 'catalog/status': 'get'
+ 'catalog/profile': 'get'
+ 'catalog/read': 'get'
+ 'catalog/feed': 'get'
+ 'catalog/list': 'get'
+ 'catalog/delete': 'post'
View
2  test/v4/testArtist.coffee
@@ -103,8 +103,6 @@ vows.describe('artist methods').addBatch({
}, @callback
undefined
'we get someone': (err, response) ->
- # FIXME: the example response documentation is wrong
- # artists is a list, but obj in doc
assert.ok response.artists[0].name.length > 0
'we see no errors': checkErrors
"to extract names from 'behold... the arctopus pickle beatles
View
2  test/v4/testErrors.coffee
@@ -38,7 +38,7 @@ vows.describe('error tests').addBatch({
topic: (nest) ->
# fake endpoint, but specified in echonest_api.coffee
# under bogusVersion
- nest.totally.fake.endpoint {}, @callback # no parameters
+ nest.fake.endpoint {}, @callback # no parameters
undefined
'we see a 502': (err, data) ->
assert.equal err.message, 'Bad status code from server: 502'
Please sign in to comment.
Something went wrong with that request. Please try again.