orkut 0.0.0.10 → 0.0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,9 +50,10 @@ module Orkut
50
50
 
51
51
  def home_timeline22(options={})
52
52
  params = {
53
- Orkut::Constants::Fields::USER_ID => Orkut::Constants::InternalConstants::USERID_ME_SIMPLE,
54
- Orkut::Constants::Fields::COLLECTION => Orkut::Constants::Collection::STREAM,
55
- Orkut::Constants::Fields::ALT => Orkut::Constants::Params::JSON
53
+ Orkut::Constants::Fields::USER_ID => Orkut::Constants::InternalConstants::USERID_ME_SIMPLE,
54
+ Orkut::Constants::Fields::COLLECTION => Orkut::Constants::Collection::STREAM,
55
+ Orkut::Constants::Fields::ALT => Orkut::Constants::Params::JSON,
56
+ Orkut::Constants::Fields::EXTRA_PARAMS => options
56
57
  }
57
58
  execute(Orkut::Constants::Fields::ACTIVITIES, Orkut::Constants::Action::LIST, params)
58
59
  end
@@ -1,5 +1,6 @@
1
1
  require 'omniauth/oauth'
2
2
  require 'google/api_client'
3
+ require 'orkut/error'
3
4
 
4
5
  module Orkut
5
6
  module Connection
@@ -17,6 +18,10 @@ module Orkut
17
18
  client.authorization.authorization_uri.to_s
18
19
  end
19
20
 
21
+ def get_connection_hash
22
+ return get_token_values(connection)
23
+ end
24
+
20
25
  private
21
26
 
22
27
  def connection_v1(options={})
@@ -39,7 +44,7 @@ module Orkut
39
44
  end
40
45
 
41
46
  def connection(options={})
42
- access_token = nil
47
+ client = nil
43
48
  if authenticated?
44
49
  client = Google::APIClient.new
45
50
 
@@ -47,17 +52,49 @@ module Orkut
47
52
  client.authorization.client_secret = client_secret
48
53
  client.authorization.scope = scope
49
54
  client.authorization.redirect_uri = redirect_uri
50
-
51
55
  client.authorization.code = code
52
56
 
57
+ if !options[:token_values].blank?
58
+ client.authorization.update_token!(options[:token_values])
59
+ ::Orkut.configure do |config|
60
+ config.refresh_token = options[:token_values][:refresh_token]
61
+ config.access_token = options[:token_values][:access_token]
62
+ config.expires_in = options[:token_values][:expires_in]
63
+ config.issued_at = options[:token_values][:issued_at]
64
+ end
65
+ else
66
+ if !refresh_token.blank? and !access_token.blank? and !expires_in.blank? and !issued_at.blank?
67
+ client.authorization.update_token!(credentials)
68
+ end
69
+ end
70
+
71
+ client.authorization.fetch_access_token!
72
+
73
+ update_token_values(client.authorization)
74
+
53
75
  orkut = client.discovered_api('orkut', 'v2')
54
76
  unless client.authorization.access_token
55
- r = Rack::Response.new
56
- r.redirect(client.authorization.authorization_uri.to_s)
57
- r.finish
77
+ raise(Orkut::Error, 'Invalid access token')
58
78
  end
59
79
  end
60
- access_token
80
+ client
81
+ end
82
+
83
+ def update_token_values(object)
84
+ ::Orkut.configure do |config|
85
+ config.refresh_token = object.refresh_token
86
+ config.access_token = object.access_token
87
+ config.expires_in = object.expires_in
88
+ config.issued_at = Time.at(object.issued_at)
89
+ end
90
+ end
91
+
92
+ def get_token_values(object)
93
+ return {:refresh_token => object.refresh_token,
94
+ :access_token => object.access_token,
95
+ :expires_in => object.expires_in,
96
+ :issued_at => Time.at(object.issued_at)
97
+ }
61
98
  end
62
99
  end
63
100
  end
@@ -45,6 +45,7 @@ module Orkut
45
45
  # The list of entries in an ACL
46
46
  ENTRIES = 'entries'
47
47
  ERROR_TYPE = 'errorType'
48
+ EXTRA_PARAMS = 'extraParams'
48
49
  FIELDS = 'fields'
49
50
  FROM_USER_ID = 'fromUserId'
50
51
  FROM_USER_PROFILE = 'fromUserProfile'
data/lib/orkut/request.rb CHANGED
@@ -53,11 +53,14 @@ module Orkut
53
53
  connection_v1.delete(verify_path(path), headers)
54
54
  end
55
55
 
56
- def execute(entity, action, body = {})
56
+ def execute(entity, action, params = {})
57
57
  raise(Orkut::Error, 'Parameters entity and action cannot be nil') if entity.blank? or action.blank?
58
- raise(Orkut::Error, 'Parameter body cannot be nil or empty') if body.blank? or body.empty?
58
+ raise(Orkut::Error, 'Parameter body cannot be nil or empty') if params.blank? or params.empty?
59
+
60
+ extra = params.delete(Orkut::Constants::Fields::EXTRA_PARAMS)
61
+
59
62
  orkut = connection.discovered_api('orkut', 'v2')
60
- response = connection.execute(orkut.try(entity.to_sym).try(action.to_sym), body)
63
+ response = connection(extra).execute(orkut.try(entity.to_sym).try(action.to_sym), params)
61
64
  #status, headers, body = response
62
65
  response
63
66
  end
data/lib/orkut/version.rb CHANGED
@@ -14,7 +14,7 @@ module Orkut
14
14
  end
15
15
 
16
16
  def self.pre
17
- 10 #nil
17
+ 11 #nil
18
18
  end
19
19
 
20
20
  def self.to_s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orkut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.10
4
+ version: 0.0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth
16
- requirement: &11806560 !ruby/object:Gem::Requirement
16
+ requirement: &12602060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *11806560
24
+ version_requirements: *12602060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: multi_json
27
- requirement: &11805160 !ruby/object:Gem::Requirement
27
+ requirement: &12601460 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *11805160
35
+ version_requirements: *12601460
36
36
  description: A Ruby wrapper for the Orkut REST/RPC API.
37
37
  email:
38
38
  - contato@umanni.com