cliskip2 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -32,6 +32,10 @@ A Ruby wrapper for the SKIP2 REST APIs
32
32
  client = Cliskip2::Client.new
33
33
  client.update_user :user => {:name => 'foobar', :email => 'hoge@hoge.com'}
34
34
 
35
+ ### delete the user by email
36
+ client = Cliskip2::Client.new
37
+ client.delete_user :user => {:email => 'hoge@hoge.com'}
38
+
35
39
  ### search communities by the community-name
36
40
  client = Cliskip2::Client.new
37
41
  client.search_communities({:search => {:name => 'I love ruby'} })
@@ -52,14 +52,27 @@ module Cliskip2
52
52
  # Update the user by params
53
53
  # @return [Cliskip2::User]
54
54
  def update_user params
55
- user = get_user :email => params[:user][:email]
56
- user_attr = put("/admin/tenants/#{current_user.tenant_id}/users/#{user.id}.json", params)
57
- Cliskip2::User.new(user_attr['user'])
55
+ if user = get_user(:email => params[:user][:email])
56
+ user_attr = put("/admin/tenants/#{current_user.tenant_id}/users/#{user.id}.json", params)
57
+ Cliskip2::User.new(user_attr['user'])
58
+ else
59
+ nil
60
+ end
61
+ end
62
+
63
+ def delete_user params
64
+ if user = get_user(:email => params[:user][:email])
65
+ user_attr = delete("/admin/tenants/#{current_user.tenant_id}/users/#{user.id}.json")
66
+ Cliskip2::User.new(user_attr['user'])
67
+ else
68
+ nil
69
+ end
58
70
  end
59
71
 
60
72
  def sync_users users_csv_path
61
73
  inserted_users_count = 0
62
74
  updated_users_count = 0
75
+ deleted_users_count = 0
63
76
  failed_users_count = 0
64
77
  skipped_users_count = 0
65
78
  logger.info 'Start syncing users...'
@@ -67,13 +80,24 @@ module Cliskip2
67
80
  begin
68
81
  if email = row['email'] and email != ''
69
82
  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
83
+ if user.status == 'UNUSED' && row['status'] == 'RETIRED'
84
+ self.delete_user :user => {:email => email}
85
+ logger.info " Deleted email: #{email}"
86
+ deleted_users_count = deleted_users_count + 1
87
+ else
88
+ self.update_user :user => {:name => row['name'], :email => email, :section => row['section'], :status => row['status']}
89
+ logger.info " Updated email: #{email}"
90
+ updated_users_count = updated_users_count + 1
91
+ end
73
92
  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
93
+ unless row['status'] == 'RETIRED'
94
+ self.create_user :user => {:name => row['name'], :email => email, :section => row['section']}
95
+ logger.info " Inserted email: #{email}"
96
+ inserted_users_count = inserted_users_count + 1
97
+ else
98
+ logger.info " Skipped to sync users. because of retired user."
99
+ skipped_users_count = skipped_users_count + 1
100
+ end
77
101
  end
78
102
  else
79
103
  logger.info " Skipped to sync users. because of blank-email."
@@ -93,6 +117,7 @@ module Cliskip2
93
117
  {
94
118
  :inserted_users_count => inserted_users_count,
95
119
  :updated_users_count => updated_users_count,
120
+ :deleted_users_count => deleted_users_count,
96
121
  :failed_users_count => failed_users_count,
97
122
  :skipped_users_count => skipped_users_count
98
123
  }
data/lib/cliskip2/user.rb CHANGED
@@ -3,6 +3,6 @@ require 'cliskip2/base'
3
3
 
4
4
  module Cliskip2
5
5
  class User < Cliskip2::Base
6
- lazy_attr_reader :id, :tenant_id, :email
6
+ lazy_attr_reader :id, :tenant_id, :email, :status
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module Cliskip2
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cliskip2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-29 00:00:00.000000000 Z
12
+ date: 2012-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday_middleware