navi_email_sync 0.0.3 → 0.0.4
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 +4 -4
 - data/lib/cloud/navi_cloud_client.rb +25 -13
 - data/lib/gmail_client.rb +18 -2
 - data/lib/local/navi_local_client.rb +1 -1
 - data/lib/navi_client/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: dbb62f60b851990be4456f7c89b54fcd92c4587f44834d44ee8c07d6865a6d02
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 2eed53dfc8a715dc761f7dbf022b15b68d7293839f22e17088d5512c35fd0e29
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 0215a6efc370348c3638f1cd2a8932923b4e2ccd808cf1c022c7ddc23c6fcb07a68bf0435381c336990e9a5b5217d35446144b7a7d874a9dd00d54e38328aaff
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: cb26d6604fa0d92c1d4a86e83634f6b74a988fec726b554e2cae6e108388807b7b0e8f65a31a1f8f9c16dfcc07eaa645947f22f156f751e2291c1999193fb34c
         
     | 
| 
         @@ -1,4 +1,6 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require Gem::Specification.find_by_name("navi_email_sync").gem_dir+"/lib/client"
         
     | 
| 
      
 1 
     | 
    
         
            +
            # require Gem::Specification.find_by_name("navi_email_sync").gem_dir+"/lib/client"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative '../gmail_client'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative '../client'
         
     | 
| 
       2 
4 
     | 
    
         
             
            require 'concurrent'
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
       4 
6 
     | 
    
         
             
            module NaviEmailSync
         
     | 
| 
         @@ -9,7 +11,6 @@ module NaviEmailSync 
     | 
|
| 
       9 
11 
     | 
    
         
             
              #
         
     | 
| 
       10 
12 
     | 
    
         
             
              class Cloud
         
     | 
| 
       11 
13 
     | 
    
         
             
                include Concurrent::Async
         
     | 
| 
       12 
     | 
    
         
            -
                include Client
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
       14 
15 
     | 
    
         
             
                attr_reader :id
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
         @@ -62,13 +63,17 @@ module NaviEmailSync 
     | 
|
| 
       62 
63 
     | 
    
         
             
                  @download_path = config[:s3_download_folder] + '/' + email + "/"
         
     | 
| 
       63 
64 
     | 
    
         
             
                end
         
     | 
| 
       64 
65 
     | 
    
         | 
| 
      
 66 
     | 
    
         
            +
                def set_user_details(email, identifier, method)
         
     | 
| 
      
 67 
     | 
    
         
            +
                  @current_user_email = email
         
     | 
| 
      
 68 
     | 
    
         
            +
                  @download_path = "#{config[:s3_download_folder]}/#{identifier}/#{method}/"
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
       65 
71 
     | 
    
         
             
                ##
         
     | 
| 
       66 
72 
     | 
    
         
             
                # send bulk request to navi-ai service with list of input files downloaded from imap server.
         
     | 
| 
       67 
73 
     | 
    
         
             
                #
         
     | 
| 
       68 
74 
     | 
    
         
             
                def send_request(in_filenames = [], is_last: false, email_count:)
         
     | 
| 
       69 
75 
     | 
    
         
             
                  unless in_filenames.blank?
         
     | 
| 
       70 
     | 
    
         
            -
                     
     | 
| 
       71 
     | 
    
         
            -
                    filepath = download_path + "/inputs/" + (Time.now.to_f * 1000).to_s
         
     | 
| 
      
 76 
     | 
    
         
            +
                    filepath = @download_path + "inputs/" + (Time.now.to_f * 1000).to_s
         
     | 
| 
       72 
77 
     | 
    
         
             
                    filename = upload_to_s3(filepath, in_filenames.join("\n"))
         
     | 
| 
       73 
78 
     | 
    
         | 
| 
       74 
79 
     | 
    
         
             
                    HTTPService::NaviAI.start(filepath: filename, client_id: @id, client_type: @client_type, token: @token, email: @current_user_email, is_last: is_last, email_count: email_count, total_emails: @total_emails)
         
     | 
| 
         @@ -79,14 +84,15 @@ module NaviEmailSync 
     | 
|
| 
       79 
84 
     | 
    
         
             
                # Downloads the email content from imap-server and save it to the download_path
         
     | 
| 
       80 
85 
     | 
    
         
             
                #
         
     | 
| 
       81 
86 
     | 
    
         
             
                def download(message, custom_uid)
         
     | 
| 
       82 
     | 
    
         
            -
                   
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
      
 87 
     | 
    
         
            +
                  mime_type = message["mime_type"].nil? ? message.mime_type : message["mime_type"]
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                  if ['text/plain', 'text/html'].include? mime_type
         
     | 
| 
       84 
90 
     | 
    
         | 
| 
       85 
91 
     | 
    
         
             
                    h = Hash.new
         
     | 
| 
       86 
     | 
    
         
            -
                    out_file = download_path +  
     | 
| 
      
 92 
     | 
    
         
            +
                    out_file = @download_path + mime_type + "/"+custom_uid
         
     | 
| 
       87 
93 
     | 
    
         | 
| 
       88 
     | 
    
         
            -
                    s3_filepath = upload_to_s3(out_file, encrypt(message.decoded))
         
     | 
| 
       89 
     | 
    
         
            -
                    key =  
     | 
| 
      
 94 
     | 
    
         
            +
                    s3_filepath = upload_to_s3(out_file, encrypt(message["decoded"].nil? ? message.decoded : message["decoded"]))
         
     | 
| 
      
 95 
     | 
    
         
            +
                    key = mime_type.split("/").join("_")
         
     | 
| 
       90 
96 
     | 
    
         | 
| 
       91 
97 
     | 
    
         
             
                    h[key] = s3_filepath
         
     | 
| 
       92 
98 
     | 
    
         
             
                    return h
         
     | 
| 
         @@ -98,9 +104,7 @@ module NaviEmailSync 
     | 
|
| 
       98 
104 
     | 
    
         
             
                # Input is hashmap, and it save the hashmap as yml format.
         
     | 
| 
       99 
105 
     | 
    
         
             
                #
         
     | 
| 
       100 
106 
     | 
    
         
             
                def save(data={}, filename)
         
     | 
| 
       101 
     | 
    
         
            -
                   
     | 
| 
       102 
     | 
    
         
            -
                  filepath = download_path + "/" + filename + ".yml"
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
      
 107 
     | 
    
         
            +
                  filepath = @download_path + filename + ".yml"
         
     | 
| 
       104 
108 
     | 
    
         
             
                  return upload_to_s3(filepath, data.to_yaml)
         
     | 
| 
       105 
109 
     | 
    
         
             
                end
         
     | 
| 
       106 
110 
     | 
    
         | 
| 
         @@ -130,11 +134,19 @@ module NaviEmailSync 
     | 
|
| 
       130 
134 
     | 
    
         | 
| 
       131 
135 
     | 
    
         
             
                def getMessageUUIds(prefix)
         
     | 
| 
       132 
136 
     | 
    
         
             
                  files = s3_resource_files(config[:s3_bucket], prefix)
         
     | 
| 
       133 
     | 
    
         
            -
                  files.empty? ? [] : files.map { |i| i.empty? ? 0 : i.split('/').last.split("_").first 
     | 
| 
      
 137 
     | 
    
         
            +
                  files.empty? ? [] : files.map { |i| i.empty? ? 0 : i.split('/').last.split("_").first }
         
     | 
| 
       134 
138 
     | 
    
         
             
                end
         
     | 
| 
       135 
139 
     | 
    
         | 
| 
       136 
140 
     | 
    
         
             
                def config
         
     | 
| 
       137 
141 
     | 
    
         
             
                  YAML.load_file(Rails.root.join("config/navi_client.yml")).with_indifferent_access
         
     | 
| 
       138 
142 
     | 
    
         
             
                end
         
     | 
| 
       139 
143 
     | 
    
         
             
              end
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
              class GmailCloudApi < Cloud
         
     | 
| 
      
 146 
     | 
    
         
            +
                include GmailClient
         
     | 
| 
      
 147 
     | 
    
         
            +
              end
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
              class ImapCloudApi < Cloud
         
     | 
| 
      
 150 
     | 
    
         
            +
                include Client
         
     | 
| 
      
 151 
     | 
    
         
            +
              end
         
     | 
| 
       140 
152 
     | 
    
         
             
            end
         
     | 
    
        data/lib/gmail_client.rb
    CHANGED
    
    | 
         @@ -69,6 +69,22 @@ module GmailClient 
     | 
|
| 
       69 
69 
     | 
    
         
             
                @service.authorization = cred
         
     | 
| 
       70 
70 
     | 
    
         
             
              end
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
      
 72 
     | 
    
         
            +
              def init_apis_cloud client_path, scope, token, expires
         
     | 
| 
      
 73 
     | 
    
         
            +
                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)
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                @service = Google::Apis::GmailV1::GmailService.new
         
     | 
| 
      
 84 
     | 
    
         
            +
                @service.client_options.application_name = APPLICATION_NAME
         
     | 
| 
      
 85 
     | 
    
         
            +
                @service.authorization = Signet::OAuth2::Client.new(client_opts)
         
     | 
| 
      
 86 
     | 
    
         
            +
              end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
       72 
88 
     | 
    
         
             
              def authorization_url
         
     | 
| 
       73 
89 
     | 
    
         
             
                @authorizer.get_authorization_url(base_url: OOB_URI)
         
     | 
| 
       74 
90 
     | 
    
         
             
              end
         
     | 
| 
         @@ -128,11 +144,11 @@ module GmailClient 
     | 
|
| 
       128 
144 
     | 
    
         | 
| 
       129 
145 
     | 
    
         
             
                if payload.parts&.any?
         
     | 
| 
       130 
146 
     | 
    
         
             
                  payload.parts.map { |part|
         
     | 
| 
       131 
     | 
    
         
            -
                    m = download({"decoded" => part.body.data, "mime_type" => part.mime_type}, custom_uid)
         
     | 
| 
      
 147 
     | 
    
         
            +
                    m = download({"decoded" => part.body.data.nil? ? "" : part.body.data, "mime_type" => part.mime_type.nil? ? "text/html" : part.mime_type}, custom_uid)
         
     | 
| 
       132 
148 
     | 
    
         
             
                    meta.merge!(m) unless m.nil?
         
     | 
| 
       133 
149 
     | 
    
         
             
                  }
         
     | 
| 
       134 
150 
     | 
    
         
             
                else
         
     | 
| 
       135 
     | 
    
         
            -
                  m = download({"decoded" => payload.body.data, "mime_type" => "text/html"}, custom_uid)
         
     | 
| 
      
 151 
     | 
    
         
            +
                  m = download({"decoded" => payload.body.data.nil? ? "" : payload.body.data, "mime_type" => "text/html"}, custom_uid)
         
     | 
| 
       136 
152 
     | 
    
         
             
                  meta.merge!(m) unless m.nil?
         
     | 
| 
       137 
153 
     | 
    
         
             
                end
         
     | 
| 
       138 
154 
     | 
    
         | 
| 
         @@ -72,7 +72,7 @@ module NaviEmailSync 
     | 
|
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
                  mime_type = message["mime_type"].nil? ? message.mime_type : message["mime_type"]
         
     | 
| 
       74 
74 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
                  if ['text/plain', 'text/html' 
     | 
| 
      
 75 
     | 
    
         
            +
                  if ['text/plain', 'text/html'].include? mime_type
         
     | 
| 
       76 
76 
     | 
    
         | 
| 
       77 
77 
     | 
    
         
             
                    h = Hash.new
         
     | 
| 
       78 
78 
     | 
    
         
             
                    out_file = @download_path + mime_type + "/"+custom_uid
         
     | 
    
        data/lib/navi_client/version.rb
    CHANGED
    
    
    
        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 
     | 
    
         
            +
              version: 0.0.4
         
     | 
| 
       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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-06-25 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |