Sha256: 788c54b77f21d43e1e1e10f8efd35aa880bfdd852a0c03402e2ae2e648240a2f

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

class Reader
  constructor: (options) ->
    @id = options.id
    @key = options.key
    @token = null
    @collection = []
    @position = 0

  next: (count, callback) ->
    nextPosition = @position + count

    if nextPosition <= @collection.length
      callback @collection.slice(@position, nextPosition) if callback?
      @position = nextPosition
      return

    @load =>
      nextPosition = Math.min nextPosition, @collection.length
      callback @collection.slice(@position, nextPosition) if callback?
      @position = nextPosition
      return

    return

  load: (callback) ->
    url = "https://www.googleapis.com/plus/v1/people/#{ @id }/activities/public?key=#{ @key }"
    url = "#{ url }&pageToken=#{ @token }" if @token

    jQuery.ajax(url: url, crossDomain: true, dataType: 'jsonp').done (result) =>
      @append result.items
      @token = result.nextPageToken
      callback() if callback?
      return

    return

  append: (items) ->
    @collection.push item for item in items
    return

window.GooglePlus ||= {}
window.GooglePlus.Reader = Reader

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
googleplus-reader-0.0.3 lib/assets/javascripts/googleplus.reader.js.coffee