googleplus-reader 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +27 -31
- data/lib/assets/javascripts/googleplus.photo.js.coffee +19 -12
- data/lib/assets/javascripts/googleplus.reader.js.coffee +26 -18
- data/lib/googleplus/reader/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e6464b486318c333d4c7cc2d89cf54473eef50e
|
4
|
+
data.tar.gz: 0cbc58dfa6382b1f909deefbba0451472f1745b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d852aacdb87788bb02ef12b4f6d2ce3dc7f4bdfc86ffdd6d6d96f87f8021e5a7f681f59124134f0c5c1bd414eeffca1e88916c9c69e661e142319fb9a7274b8
|
7
|
+
data.tar.gz: ef4541183a576fc8e48755b5f76eb54bf2bcaa6c40b1d529daf8a29e75f3beb6c648cbd728534e84c7457ba5d1bc018c48bdf7e2d36cc30c372d3bb015917484
|
data/CHANGELOG.md
CHANGED
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
|
-
|
11
|
-
|
12
|
-
|
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.
|
23
|
+
application.
|
24
|
+
|
25
|
+
In `Gemfile`:
|
23
26
|
|
24
|
-
```
|
25
|
-
|
26
|
-
$ bundle install
|
27
|
+
```ruby
|
28
|
+
gem 'coffee-rails'
|
27
29
|
```
|
28
30
|
|
29
|
-
In
|
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.
|
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
|
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
|
45
|
-
console.log
|
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
|
63
|
-
console.log
|
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
|
73
|
-
$('#original').append
|
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
|
79
|
-
$('#
|
75
|
+
photo.load(width: 300).done (element) ->
|
76
|
+
$('#small').append(element)
|
80
77
|
|
81
|
-
|
82
|
-
|
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
|
-
|
88
|
-
|
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
|
5
|
-
|
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
|
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
|
17
|
-
url = @attributes.url.replace
|
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 =
|
22
|
+
element = @$('<img/>')
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
element.off
|
26
|
-
|
24
|
+
element
|
25
|
+
.on 'load', ->
|
26
|
+
element.off('load error')
|
27
|
+
deferred.resolve(element)
|
28
|
+
return
|
27
29
|
|
28
|
-
|
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
|
11
|
+
next: (count) ->
|
12
|
+
deferred = @$.Deferred()
|
13
|
+
|
10
14
|
nextPosition = @position + count
|
11
15
|
|
12
16
|
if nextPosition <= @collection.length
|
13
|
-
|
17
|
+
elements = @collection.slice(@position, nextPosition)
|
14
18
|
@position = nextPosition
|
15
|
-
|
19
|
+
deferred.resolve(elements)
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
30
|
+
.fail (details...) =>
|
31
|
+
deferred.reject(details...)
|
32
|
+
return
|
33
|
+
|
34
|
+
deferred.promise()
|
24
35
|
|
25
|
-
load:
|
26
|
-
url = "https://www.googleapis.com/plus/v1/people/#{
|
27
|
-
url = "#{
|
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
|
-
|
30
|
-
@append
|
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
|
46
|
+
@collection.push(item) for item in items
|
39
47
|
return
|
40
48
|
|
41
49
|
window.GooglePlus ||= {}
|
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.
|
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-
|
11
|
+
date: 2014-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|