googleplus-reader 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e9af9e59801e32dcf8c902485144e0f35c3d73e
4
- data.tar.gz: f6fb7a4f92dbc7c42b46f7ee4b394219d839cea3
3
+ metadata.gz: 5e6464b486318c333d4c7cc2d89cf54473eef50e
4
+ data.tar.gz: 0cbc58dfa6382b1f909deefbba0451472f1745b4
5
5
  SHA512:
6
- metadata.gz: 7890b855a82bb630da6455be5aae72ec05a6b80c6c06f4ffe3e8f356ea85c3cfa64fb9b2c8cac584cec298073d25af4900c9abc30f903f06dd548780daed95ce
7
- data.tar.gz: 51ce40677da1a506b25d448351cb165aca378fec5fc2c37ff5a73a167cc0c3c9579a28c4df84d2c6abf00b58307331e475ad0f4017e4d7fd6e8f38481715d6cd
6
+ metadata.gz: 4d852aacdb87788bb02ef12b4f6d2ce3dc7f4bdfc86ffdd6d6d96f87f8021e5a7f681f59124134f0c5c1bd414eeffca1e88916c9c69e661e142319fb9a7274b8
7
+ data.tar.gz: ef4541183a576fc8e48755b5f76eb54bf2bcaa6c40b1d529daf8a29e75f3beb6c648cbd728534e84c7457ba5d1bc018c48bdf7e2d36cc30c372d3bb015917484
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## GooglePlus Reader 0.0.4 (August 2, 2014)
2
+
3
+ * Changed the API to rely on deferreds instead of callbacks.
4
+
1
5
  ## GooglePlus Reader 0.0.3 (August 1, 2014)
2
6
 
3
7
  * Fixed a cross-domain-related issue discovered in IE9.
data/README.md CHANGED
@@ -7,9 +7,10 @@ A [jQuery](http://jquery.com)-based library for reading public posts of a
7
7
 
8
8
  ## Installation
9
9
 
10
- ```bash
11
- $ echo "gem 'googleplus-reader'" >> Gemfile
12
- $ bundle install
10
+ In `Gemfile`:
11
+
12
+ ```ruby
13
+ gem 'googleplus-reader'
13
14
  ```
14
15
 
15
16
  The code is written in [CoffeeScript](http://coffeescript.org); however,
@@ -19,30 +20,30 @@ have CoffeeScript installed.
19
20
  ## Usage
20
21
 
21
22
  Here is an example in the context of a [Rails](http://rubyonrails.org)
22
- application. First, we need CoffeeScript as it was noted earlier:
23
+ application.
24
+
25
+ In `Gemfile`:
23
26
 
24
- ```bash
25
- $ echo "gem 'coffee-rails'" >> Gemfile
26
- $ bundle install
27
+ ```ruby
28
+ gem 'coffee-rails'
27
29
  ```
28
30
 
29
- In your `app/views/layouts/application.html.haml`:
31
+ In `app/views/layouts/application.html.haml`:
30
32
 
31
33
  ```haml
32
- = javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js'
34
+ = javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'
33
35
  = javascript_include_tag :application
34
36
  ```
35
37
 
36
- In your `app/assets/javascripts/application.js.coffee`:
38
+ In `app/assets/javascripts/application.js.coffee`:
37
39
 
38
40
  ```coffee
39
41
  //= require googleplus.reader
40
42
 
41
- reader = new GooglePlus.Reader \
42
- id: 'user_id', key: 'api_key'
43
+ reader = new GooglePlus.Reader(id: 'user_id', key: 'api_key')
43
44
 
44
- reader.next 5, (posts) ->
45
- console.log post for post in posts
45
+ reader.next(5).done (posts) ->
46
+ console.log(post) for post in posts
46
47
  ```
47
48
 
48
49
  Here `user_id` is the identifier of a Google+ user, and `api_key` is your
@@ -56,11 +57,10 @@ A more interesting example with photos that a user publishes:
56
57
  ```coffee
57
58
  //= require googleplus.photoreader
58
59
 
59
- reader = new GooglePlus.PhotoReader \
60
- id: 'user_id', key: 'api_key'
60
+ reader = new GooglePlus.PhotoReader(id: 'user_id', key: 'api_key')
61
61
 
62
- reader.next 5, (photos) ->
63
- console.log photo.attributes for photo in photos
62
+ reader.next(5).done (photos) ->
63
+ console.log(photo.attributes) for photo in photos
64
64
  ```
65
65
 
66
66
  `photo` is an instance of `GooglePlus.Photo`. Right now, `attributes`
@@ -69,23 +69,19 @@ can be easily added via a pull request >:)~ The only method that `photo`
69
69
  has is `load`, which can be used as follows:
70
70
 
71
71
  ```coffee
72
- photo.load {}, (element) ->
73
- $('#original').append element
74
-
75
- photo.load width: 300, (element) ->
76
- $('#small').append element
72
+ photo.load().done (element) ->
73
+ $('#original').append(element)
77
74
 
78
- photo.load width: 1000, (element) ->
79
- $('#large').append element
75
+ photo.load(width: 300).done (element) ->
76
+ $('#small').append(element)
80
77
 
81
- element = photo.load width: 2000
82
- console.log element.attr('href')
83
- $('#huge').append element
78
+ photo.load(width: 1000).done (element) ->
79
+ $('#large').append(element)
84
80
  ```
85
81
 
86
- `load` constructs an URL referencing the photo of the desired size and
87
- preloads it using an `img` element, which it returns right away and also
88
- passes to the callback function once the photo has been loaded.
82
+ `load` constructs an URL referencing the photo of the desired size and preloads
83
+ it using an `img` element, which is passes to `done` once the photo has been
84
+ loaded.
89
85
 
90
86
  ## Contributing
91
87
 
@@ -1,33 +1,40 @@
1
1
  class Photo
2
2
  constructor: (@attributes) ->
3
+ @$ = jQuery
3
4
 
4
- load: (options, callback) ->
5
- options ||= {}
5
+ load: (options = {}) ->
6
+ deferred = @$.Deferred()
6
7
 
7
8
  width = options.width if options.width?
8
9
 
9
10
  if @attributes.width?
10
11
  if width?
11
- width = Math.min width, @attributes.width
12
+ width = Math.min(width, @attributes.width)
12
13
  else
13
14
  width = @attributes.width
14
15
 
15
16
  if width?
16
- width = Math.round width
17
- url = @attributes.url.replace /w\d+-h\d+(-p)?/, "w#{ width }"
17
+ width = Math.round(width)
18
+ url = @attributes.url.replace(/w\d+-h\d+(-p)?/, "w#{width}")
18
19
  else
19
20
  url = @attributes.url
20
21
 
21
- element = $('<img/>')
22
+ element = @$('<img/>')
22
23
 
23
- if callback?
24
- element.on 'load', ->
25
- element.off 'load'
26
- callback element
24
+ element
25
+ .on 'load', ->
26
+ element.off('load error')
27
+ deferred.resolve(element)
28
+ return
27
29
 
28
- element.attr src: url
30
+ .on 'error', (details...) ->
31
+ element.off('load error')
32
+ deferred.reject(details...)
33
+ return
29
34
 
30
- element
35
+ element.attr(src: url)
36
+
37
+ deferred.promise()
31
38
 
32
39
  window.GooglePlus ||= {}
33
40
  window.GooglePlus.Photo = Photo
@@ -1,41 +1,49 @@
1
1
  class Reader
2
2
  constructor: (options) ->
3
+ @$ = jQuery
4
+
3
5
  @id = options.id
4
6
  @key = options.key
5
7
  @token = null
6
8
  @collection = []
7
9
  @position = 0
8
10
 
9
- next: (count, callback) ->
11
+ next: (count) ->
12
+ deferred = @$.Deferred()
13
+
10
14
  nextPosition = @position + count
11
15
 
12
16
  if nextPosition <= @collection.length
13
- callback @collection.slice(@position, nextPosition) if callback?
17
+ elements = @collection.slice(@position, nextPosition)
14
18
  @position = nextPosition
15
- return
19
+ deferred.resolve(elements)
16
20
 
17
- @load =>
18
- nextPosition = Math.min nextPosition, @collection.length
19
- callback @collection.slice(@position, nextPosition) if callback?
20
- @position = nextPosition
21
- return
21
+ else
22
+ @load()
23
+ .done =>
24
+ nextPosition = Math.min(nextPosition, @collection.length)
25
+ elements = @collection.slice(@position, nextPosition)
26
+ @position = nextPosition
27
+ deferred.resolve(elements)
28
+ return
22
29
 
23
- return
30
+ .fail (details...) =>
31
+ deferred.reject(details...)
32
+ return
33
+
34
+ deferred.promise()
24
35
 
25
- load: (callback) ->
26
- url = "https://www.googleapis.com/plus/v1/people/#{ @id }/activities/public?key=#{ @key }"
27
- url = "#{ url }&pageToken=#{ @token }" if @token
36
+ load: ->
37
+ url = "https://www.googleapis.com/plus/v1/people/#{@id}/activities/public?key=#{@key}"
38
+ url = "#{url}&pageToken=#{@token}" if @token
28
39
 
29
- jQuery.ajax(url: url, crossDomain: true, dataType: 'jsonp').done (result) =>
30
- @append result.items
40
+ @$.ajax(url: url, crossDomain: true, dataType: 'jsonp').done (result) =>
41
+ @append(result.items)
31
42
  @token = result.nextPageToken
32
- callback() if callback?
33
43
  return
34
44
 
35
- return
36
-
37
45
  append: (items) ->
38
- @collection.push item for item in items
46
+ @collection.push(item) for item in items
39
47
  return
40
48
 
41
49
  window.GooglePlus ||= {}
@@ -1,5 +1,5 @@
1
1
  module GooglePlus
2
2
  module Reader
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googleplus-reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Ukhov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-01 00:00:00.000000000 Z
11
+ date: 2014-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler