navi_email_sync 0.0.4 → 0.0.5

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
  SHA256:
3
- metadata.gz: dbb62f60b851990be4456f7c89b54fcd92c4587f44834d44ee8c07d6865a6d02
4
- data.tar.gz: 2eed53dfc8a715dc761f7dbf022b15b68d7293839f22e17088d5512c35fd0e29
3
+ metadata.gz: 0b1adf63fea9de38a1b9d436bf203145a525649937e2fd40f5a02a91e6b9447e
4
+ data.tar.gz: b23865f07b4813281998e695e13ff00f9bd737ff516cbcd4f4bbb6f3f0b3702d
5
5
  SHA512:
6
- metadata.gz: 0215a6efc370348c3638f1cd2a8932923b4e2ccd808cf1c022c7ddc23c6fcb07a68bf0435381c336990e9a5b5217d35446144b7a7d874a9dd00d54e38328aaff
7
- data.tar.gz: cb26d6604fa0d92c1d4a86e83634f6b74a988fec726b554e2cae6e108388807b7b0e8f65a31a1f8f9c16dfcc07eaa645947f22f156f751e2291c1999193fb34c
6
+ metadata.gz: 03d65abca7c01fae9757740e392402e05625b85afc710fce25b27a29563f9adfc59a069ffce6caa0bb700627acf210014b9914873bc5704fb0c92bb00c4d3374
7
+ data.tar.gz: 01c925f82dde2da7b0f21133e441754195c4021a82988fcaf060c976c2c191bade12133d1143722e7cb408d16ccab0a394b72b7014b20ec40f56e456decbc2f8
data/lib/gmail_client.rb CHANGED
@@ -29,6 +29,8 @@ module GmailClient
29
29
 
30
30
  attr_accessor :total_emails
31
31
 
32
+ attr_accessor :auth_client
33
+
32
34
  @logglyTag
33
35
 
34
36
  def logger
@@ -69,20 +71,23 @@ module GmailClient
69
71
  @service.authorization = cred
70
72
  end
71
73
 
72
- def init_apis_cloud client_path, scope, token, expires
74
+ def init_apis_cloud client_path, scope, token, type = "code"
73
75
  client_secrets = Google::APIClient::ClientSecrets.load client_path
74
- auth_client = client_secrets.to_authorization
75
- auth_client.client_secret = nil
76
-
77
- auth_client.update!(
78
- :scope => scope,
79
- :access_token => token, :expires_in => expires)
80
-
81
- client_opts = JSON.parse(auth_client.to_json)
76
+ @auth_client = client_secrets.to_authorization
77
+ @auth_client.update!(:scope => scope,
78
+ :redirect_uri => "postmessage")
79
+ if(type == "code")
80
+ @auth_client.code = token
81
+ else
82
+ @auth_client.grant_type = "refresh_token"
83
+ @auth_client.refresh_token = token
84
+ end
82
85
 
86
+ @auth_client.refresh!
87
+ # @auth_client.client_secret = nil
83
88
  @service = Google::Apis::GmailV1::GmailService.new
84
89
  @service.client_options.application_name = APPLICATION_NAME
85
- @service.authorization = Signet::OAuth2::Client.new(client_opts)
90
+ @service.authorization = Signet::OAuth2::Client.new(JSON.parse(@auth_client.to_json))
86
91
  end
87
92
 
88
93
  def authorization_url
@@ -101,8 +106,13 @@ module GmailClient
101
106
  begin
102
107
  # fetch all the email contents
103
108
  # data = imap.uid_fetch(message_id, "RFC822")
104
- result = @service.get_user_message('me', message_id)
109
+ if @auth_client.expired?
110
+ @auth_client.grant_type = "refresh_token"
111
+ @auth_client.refresh!
112
+ @service.authorization = Signet::OAuth2::Client.new(JSON.parse(@auth_client.to_json))
113
+ end
105
114
 
115
+ result = @service.get_user_message('me', message_id)
106
116
 
107
117
  process_email_block.call result, i, i == @message_ids.length-1, message_id
108
118
 
@@ -1,3 +1,3 @@
1
1
  module NaviEmailSync
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navi_email_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sanjib
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-25 00:00:00.000000000 Z
11
+ date: 2018-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler