cliskip2 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,6 +57,47 @@ module Cliskip2
57
57
  Cliskip2::User.new(user_attr['user'])
58
58
  end
59
59
 
60
+ def sync_users users_csv_path
61
+ inserted_users_count = 0
62
+ updated_users_count = 0
63
+ failed_users_count = 0
64
+ skipped_users_count = 0
65
+ logger.info 'Start syncing users...'
66
+ CSV.foreach(File.expand_path(users_csv_path), :headers => true, :encoding => 'UTF-8') do |row|
67
+ begin
68
+ if email = row['email'] and email != ''
69
+ if user = self.get_user(:email => email)
70
+ self.update_user :user => {:name => row['name'], :email => email, :section => row['section'], :status => row['status']}
71
+ logger.info " Updated email: #{email}"
72
+ updated_users_count = updated_users_count + 1
73
+ else
74
+ self.create_user :user => {:name => row['name'], :email => email, :section => row['section']}
75
+ logger.info " Inserted email: #{email}"
76
+ inserted_users_count = inserted_users_count + 1
77
+ end
78
+ else
79
+ logger.info " Skipped email: #{email}"
80
+ skipped_users_count = skipped_users_count + 1
81
+ end
82
+ rescue Faraday::Error::ClientError => e
83
+ logger.error " Failed email: #{email}"
84
+ failed_users_count = failed_users_count + 1
85
+ logger.error e.message
86
+ rescue => e
87
+ logger.error " Failed email: #{email}"
88
+ failed_users_count = failed_users_count + 1
89
+ logger.error e
90
+ end
91
+ end
92
+ logger.info 'Finish syncing users...'
93
+ {
94
+ :inserted_users_count => inserted_users_count,
95
+ :updated_users_count => updated_users_count,
96
+ :failed_users_count => failed_users_count,
97
+ :skipped_users_count => skipped_users_count
98
+ }
99
+ end
100
+
60
101
  # ========================================
61
102
  # Community APIs
62
103
  # ========================================
@@ -1,5 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require "cliskip2/version"
3
+ require 'logger'
3
4
 
4
5
  module Cliskip2
5
6
  module Config
@@ -30,6 +31,9 @@ module Cliskip2
30
31
  # The proxy server if none is set
31
32
  DEFAULT_PROXY = nil
32
33
 
34
+ # The logger if none is set
35
+ DEFAULT_LOGGER = ::Logger.new(STDOUT)
36
+
33
37
  # An array of valid keys in the options hash when configuring a {Twitter::Client}
34
38
  VALID_OPTIONS_KEYS = [
35
39
  :adapter,
@@ -40,7 +44,8 @@ module Cliskip2
40
44
  :xauth_username,
41
45
  :xauth_password,
42
46
  :proxy,
43
- :user_agent
47
+ :user_agent,
48
+ :logger
44
49
  ]
45
50
 
46
51
  attr_accessor *VALID_OPTIONS_KEYS
@@ -74,6 +79,7 @@ module Cliskip2
74
79
  self.xauth_password = DEFAULT_XAUTH_PASSWORD
75
80
  self.proxy = DEFAULT_PROXY
76
81
  self.user_agent = DEFAULT_USER_AGENT
82
+ self.logger = DEFAULT_LOGGER
77
83
  self
78
84
  end
79
85
  end
@@ -1,3 +1,3 @@
1
1
  module Cliskip2
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cliskip2
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Naoki Maeda