 
   getBranches: (repoOwner, repoName) ->
     deferred = q.defer()
-    url = "#{API_URL}#{repoOwner}/#{repoName}/refs/branches?pagelen=100"
-    options =
-      url: url
-      auth: @buildAuth()
-      json: true
+    url = "#{API_URL}#{repoOwner}/#{repoName}/refs/branches"
 
-    request.get options, (error, response, body) ->
-      try
-        console.log "API returned:", body
-        deferred.resolve transformBranchResponse(body)
-      catch error
-        deferred.reject error
+    @invokeTillHasNext(url, transformBranchResponse).then (result) ->
+      deferred.resolve result
 
     return deferred.promise
 


request = require 'request'
q = require 'q'

transformResponse = (body) ->
  if !body

      "sendImmediately": true
    }

  _get: (url) ->
    deferred = q.defer()
    options =
      url: url
      auth: @buildAuth()
