Permalink
Browse files

Switched from request to needle (fixed an issue with spotify)

  • Loading branch information...
1 parent b6657a2 commit f40a08b753d25cbe5d463b495acdea4ea5f0dcac amix committed May 13, 2014
Showing with 22 additions and 15 deletions.
  1. +12 −9 lib/media-parser.js
  2. +9 −5 src/httpservice_node.coffee
  3. +1 −1 src/media_types.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -2,16 +2,20 @@ NodeHttpService = {
oembedRequest: (url, callback_ok, callback_error,
content_url, timeout) ->
- request = require("request")
+ needle = require("needle")
timeout = timeout or 5000
- args = {"url": url, "timeout": timeout}
+ args = {"timeout": timeout}
- request(args, (error, response, body) ->
- if error
+ needle.get(url, args, (error, response) ->
+ if error or response.statusCode != 200
callback_error(error)
else
try
- json = JSON.parse(body)
+ body = response.body
+ if typeof(body) == 'string'
+ json = JSON.parse(body)
+ else
+ json = body
callback_ok(json)
catch e
callback_error('Unknown error happened')
View
@@ -76,7 +76,7 @@ MediaTypes = {
else
callback(result)
- cb_error = (json) ->
+ cb_error = (json, err) ->
callback(null)
MediaParser.http_service.oembedRequest(req_url, cb_ok, cb_error,

0 comments on commit f40a08b

Please sign in to comment.