google_plus 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/google_plus.rb CHANGED
@@ -9,7 +9,7 @@ module GooglePlus
9
9
  autoload :Person, File.dirname(__FILE__) + '/google_plus/person'
10
10
 
11
11
  class << self
12
- attr_accessor :api_key
12
+ attr_accessor :api_key, :access_token
13
13
  end
14
14
 
15
15
  # Return whether or not the we have an API
@@ -26,14 +26,33 @@ module GooglePlus
26
26
  GooglePlus::Cursor.new(self, :get, resource, params)
27
27
  end
28
28
 
29
+ # get the comments for this activity
29
30
  def list_comments
30
31
  GooglePlus::Comment.for_activity(id)
31
32
  end
32
33
 
34
+ # get the actor of this activity
33
35
  def person
34
36
  @person ||= GooglePlus::Person.get(actor.id)
35
37
  end
36
38
 
39
+ # list the people of a certain action on this activity
40
+ # options available at https://developers.google.com/+/api/latest/people/listByActivity
41
+ def list_people(collection, params = {})
42
+ resource = "activities/#{id}/people/#{collection}"
43
+ GooglePlus::Cursor.new(GooglePlus::Person, :get, resource, params)
44
+ end
45
+
46
+ # get a cursor for the plusoners of this activity
47
+ def plusoners(params = {})
48
+ list_people(:plusoners)
49
+ end
50
+
51
+ # get a cursor for the resharers of this activity
52
+ def resharers(params = {})
53
+ list_people(:resharers)
54
+ end
55
+
37
56
  def initialize(hash)
38
57
  load_hash(hash)
39
58
  end
@@ -11,12 +11,19 @@ module GooglePlus
11
11
 
12
12
  # Make a request to an external resource
13
13
  def make_request(method, resource, params = {})
14
+ # Put together the common params
14
15
  params[:key] ||= GooglePlus.api_key unless GooglePlus.api_key.nil?
15
16
  params[:userIp] = params.delete(:user_ip) if params.has_key?(:user_ip)
16
17
  params[:pp] = '0' # google documentation is incorrect, it says 'prettyPrint'
18
+ # Add the access token if we have it
19
+ headers = {}
20
+ if token = params[:access_token] || GooglePlus.access_token
21
+ headers[:Authorization] = "OAuth #{token}"
22
+ end
23
+ # And make the request
17
24
  begin
18
- RestClient.get "#{BASE_URI}#{resource}", :params => params
19
- rescue RestClient::Forbidden, RestClient::BadRequest => e
25
+ RestClient.get "#{BASE_URI}#{resource}", headers.merge(:params => params)
26
+ rescue RestClient::Unauthorized, RestClient::Forbidden, RestClient::BadRequest => e
20
27
  raise GooglePlus::RequestError.new(e)
21
28
  rescue SocketError => e
22
29
  raise GooglePlus::ConnectionError.new(e)
@@ -1,5 +1,5 @@
1
1
  module GooglePlus
2
2
 
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-04 00:00:00.000000000 -04:00
12
+ date: 2011-10-05 00:00:00.000000000 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &70317110102440 !ruby/object:Gem::Requirement
17
+ requirement: &70129871014340 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.6.0
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70317110102440
25
+ version_requirements: *70129871014340
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rest-client
28
- requirement: &70317110101940 !ruby/object:Gem::Requirement
28
+ requirement: &70129871013840 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 1.6.1
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70317110101940
36
+ version_requirements: *70129871013840
37
37
  description: Google+ Ruby Gem
38
38
  email: john.crepezzi@gmail.com
39
39
  executables: []