googleplus-reader 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b7bafbe0f5e029e2ce170e6e02cbf191f1fa6f8
4
+ data.tar.gz: dd06beb0865017d290f282bd1b40d64dccf5434b
5
+ SHA512:
6
+ metadata.gz: 140d495bec389d85b61e3e0d25c200cca3a2360eaa9ea6122cb9ea9dbe6a7bfc050733467a4269886dd6376eaaf048e4ad937a818d1fc3d38b056c62084b643b
7
+ data.tar.gz: 1e2c0028b36dd6ef4563dc5aa577dfa798ccb2ef003146adbf9a1549032a55923c1ed84239bbb8c8d41c8f099e597c614f422bf9b950856b485447971f2e2217
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright 2014 Ivan Ukhov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # GooglePlus Reader
2
+
3
+ A [jQuery](http://jquery.com)-based library for reading public posts
4
+ of a [Google+](https://plus.google.com) user. An example can be found
5
+ [here](http://ivanukhov.com). Best enjoyed responsibly.
6
+
7
+ ## Installation
8
+
9
+ $ echo "gem 'googleplus-reader'" >> Gemfile
10
+ $ bundle install
11
+
12
+ The code is written in [CoffeeScript](http://coffeescript.org); however,
13
+ any dependencies in this regard are purposely omitted. So make sure you
14
+ have CoffeeScript installed.
15
+
16
+ ## Usage
17
+
18
+ Here is an example in the context of a [Rails](http://rubyonrails.org)
19
+ application. First, we need CoffeeScript as it was noted earlier:
20
+
21
+ $ echo "gem 'coffee-rails'" >> Gemfile
22
+ $ bundle install
23
+
24
+ In your `app/views/layouts/application.html.haml`:
25
+ ``` rails
26
+ = javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js'
27
+ = javascript_include_tag :application
28
+ ```
29
+
30
+ In your `app/assets/javascripts/application.js.coffee`:
31
+ ``` coffee
32
+ //= require googleplus.reader
33
+
34
+ reader = new GooglePlus.Reader \
35
+ id: 'user_id', key: 'api_key'
36
+
37
+ reader.next 5, (posts) ->
38
+ console.log post for post in posts
39
+ ```
40
+ Here `user_id` is the identifier of a Google+ user, and `api_key` is your
41
+ [Google+ API key](https://developers.google.com/+/api/oauth).
42
+ `post` is exactly what Google has to say about each post without any
43
+ additional preprocessing. You might want to inspect it and fetch what is
44
+ needed for your application.
45
+
46
+ A more interesting example with photos that a user publishes:
47
+ ``` coffee
48
+ //= require googleplus.photoreader
49
+
50
+ reader = new GooglePlus.PhotoReader \
51
+ id: 'user_id', key: 'api_key'
52
+
53
+ reader.next 5, (photos) ->
54
+ console.log photo.attributes for photo in photos
55
+ ```
56
+ `photo` is an instance of `GooglePlus.Photo`. Right now, `attributes`
57
+ contain only `url`, `date`, and `width` (if available), but other parameters
58
+ can be easily added via a pull request >:)~ The only method that `photo`
59
+ has is `load`, which can be used as follows:
60
+ ``` coffee
61
+ photo.load {}, (element) ->
62
+ $('#original').append element
63
+
64
+ photo.load width: 300, (element) ->
65
+ $('#small').append element
66
+
67
+ photo.load width: 1000, (element) ->
68
+ $('#large').append element
69
+
70
+ element = photo.load width: 2000
71
+ console.log element.attr('href')
72
+ $('#huge').append element
73
+ ```
74
+ `load` constructs an URL referencing the photo of the desired size and
75
+ preloads it using an `img` element, which it returns right away and also
76
+ passes to the callback function once the photo has been loaded.
77
+
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it (https://github.com/IvanUkhov/googleplus-reader/fork)
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'googleplus/reader/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'googleplus-reader'
8
+ spec.version = GooglePlus::Reader::VERSION
9
+ spec.authors = [ 'Ivan Ukhov' ]
10
+ spec.email = [ 'ivan.ukhov@gmail.com' ]
11
+ spec.summary = 'A jQuery-based library for reading public posts of a Google+ user'
12
+ spec.homepage = 'https://github.com/IvanUkhov/googleplus-reader'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+
17
+ spec.add_development_dependency 'bundler', '~> 1.6'
18
+ spec.add_development_dependency 'rake'
19
+ end
@@ -0,0 +1,32 @@
1
+ class Photo
2
+ constructor: (@attributes) ->
3
+
4
+ load: (options, callback) ->
5
+ options ||= {}
6
+
7
+ width = options.width if options.width?
8
+
9
+ if @attributes.width?
10
+ if width?
11
+ width = Math.min width, @attributes.width
12
+ else
13
+ width = @attributes.width
14
+
15
+ if width?
16
+ width = Math.round width
17
+ url = @attributes.url.replace /w\d+-h\d+(-p)?/, "w#{ width }"
18
+ else
19
+ url = @attributes.url
20
+
21
+ element = $('<img/>')
22
+
23
+ element.on 'load', ->
24
+ element.off 'load'
25
+ callback element if callback?
26
+
27
+ element.attr src: url
28
+
29
+ element
30
+
31
+ window.GooglePlus ||= {}
32
+ window.GooglePlus.Photo = Photo
@@ -0,0 +1,50 @@
1
+ #= require googleplus.reader
2
+ #= require googleplus.photo
3
+
4
+ class PhotoReader extends GooglePlus.Reader
5
+ append: (items) ->
6
+ for item in items
7
+ continue unless item.verb?
8
+ continue unless item.verb is 'post'
9
+
10
+ date = null
11
+ date = new Date item.published if item.published?
12
+
13
+ continue unless item.object?
14
+
15
+ post = item.object
16
+
17
+ continue unless post.attachments?
18
+
19
+ for attachment in post.attachments
20
+ continue unless attachment.objectType?
21
+
22
+ if attachment.objectType is 'photo'
23
+ continue unless attachment.image?
24
+
25
+ if attachment.fullImage?
26
+ @collection.push new GooglePlus.Photo \
27
+ url: attachment.image.url,
28
+ width: attachment.fullImage.width,
29
+ date: date
30
+ else
31
+ @collection.push new GooglePlus.Photo \
32
+ url: attachment.image.url,
33
+ width: null,
34
+ date: date
35
+
36
+ else if attachment.objectType is 'album'
37
+ continue unless attachment.thumbnails?
38
+
39
+ for thumbnail in attachment.thumbnails
40
+ continue unless thumbnail.image?
41
+
42
+ @collection.push new GooglePlus.Photo \
43
+ url: thumbnail.image.url,
44
+ width: null,
45
+ date: date
46
+
47
+ return
48
+
49
+ window.GooglePlus ||= {}
50
+ window.GooglePlus.PhotoReader = PhotoReader
@@ -0,0 +1,37 @@
1
+ class Reader
2
+ constructor: (options) ->
3
+ @id = options.id
4
+ @key = options.key
5
+ @token = null
6
+ @collection = []
7
+ @position = 0
8
+
9
+ next: (count, callback) ->
10
+ nextPosition = @position + count
11
+
12
+ if nextPosition <= @collection.length
13
+ callback @collection.slice(@position, nextPosition) if callback?
14
+ @position = nextPosition
15
+ return
16
+
17
+ @load =>
18
+ nextPosition = Math.min nextPosition, @collection.length
19
+ callback @collection.slice(@position, nextPosition) if callback?
20
+ @position = nextPosition
21
+
22
+ return
23
+
24
+ load: (callback) ->
25
+ url = "https://www.googleapis.com/plus/v1/people/#{ @id }/activities/public?key=#{ @key }"
26
+ url = "#{ url }&pageToken=#{ @token }" if @token
27
+
28
+ jQuery.ajax(url: url).done (result) =>
29
+ @append result.items
30
+ @token = result.nextPageToken
31
+ callback() if callback?
32
+
33
+ append: (items) ->
34
+ @collection.push item for item in items
35
+
36
+ window.GooglePlus ||= {}
37
+ window.GooglePlus.Reader = Reader
@@ -0,0 +1,5 @@
1
+ module GooglePlus
2
+ module Reader
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'googleplus/reader/version'
2
+
3
+ module GooglePlus
4
+ module Reader
5
+ if defined? ::Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: googleplus-reader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Ukhov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - ivan.ukhov@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - googleplus-reader.gemspec
54
+ - lib/assets/javascripts/googleplus.photo.js.coffee
55
+ - lib/assets/javascripts/googleplus.photoreader.js.coffee
56
+ - lib/assets/javascripts/googleplus.reader.js.coffee
57
+ - lib/googleplus/reader.rb
58
+ - lib/googleplus/reader/version.rb
59
+ homepage: https://github.com/IvanUkhov/googleplus-reader
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.0
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: A jQuery-based library for reading public posts of a Google+ user
83
+ test_files: []