zendesk-populator 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/zdpop +1 -1
- data/lib/zdpop/populator.rb +28 -8
- data/lib/zdpop/version.rb +1 -1
- metadata +6 -7
data/bin/zdpop
CHANGED
data/lib/zdpop/populator.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'csv'
|
3
|
+
require 'uri'
|
3
4
|
|
4
5
|
begin
|
5
6
|
require 'httparty'
|
@@ -10,12 +11,16 @@ end
|
|
10
11
|
module Zdpop
|
11
12
|
class Populator
|
12
13
|
|
13
|
-
def initialize(
|
14
|
+
def initialize(options)
|
14
15
|
begin
|
16
|
+
# Process options
|
17
|
+
configfile = options[:cfile]
|
18
|
+
datafile = options[:dfile]
|
19
|
+
|
15
20
|
# Set configuration
|
16
21
|
raise "Configuration file #{configfile} missing" unless File.file? configfile
|
17
22
|
config = YAML.load_file(configfile)
|
18
|
-
@site = config[:zendesk_site]
|
23
|
+
@site = valid_site(config[:zendesk_site])
|
19
24
|
@user = config[:zendesk_user]
|
20
25
|
@password = config[:zendesk_password]
|
21
26
|
raise "Missing Zendesk site, user or password" if [ @site, @user, @password ].include?(nil)
|
@@ -49,8 +54,7 @@ module Zdpop
|
|
49
54
|
|
50
55
|
def list_orgs
|
51
56
|
orglist = []
|
52
|
-
organizations =
|
53
|
-
|
57
|
+
organizations = get_orgs
|
54
58
|
organizations.each { |o|
|
55
59
|
orglist << o["name"]
|
56
60
|
}
|
@@ -59,7 +63,7 @@ module Zdpop
|
|
59
63
|
|
60
64
|
def lookup_org_id(org)
|
61
65
|
orgtable = {}
|
62
|
-
organizations =
|
66
|
+
organizations = get_orgs
|
63
67
|
organizations.each { |o|
|
64
68
|
orgtable["#{o["name"]}"] = o["id"]
|
65
69
|
}
|
@@ -67,9 +71,13 @@ module Zdpop
|
|
67
71
|
return id
|
68
72
|
end
|
69
73
|
|
74
|
+
def get_orgs
|
75
|
+
HTTParty.get("#{@site}/api/v1/organizations.json", :basic_auth => {:username=>"#{@user}", :password=> "#{@password}" } )
|
76
|
+
end
|
77
|
+
|
70
78
|
def list_users
|
71
79
|
userlist = []
|
72
|
-
users = HTTParty.get("#{@site}users.json", :basic_auth => {:username=>"#{@user}", :password=> "#{@password}" } )
|
80
|
+
users = HTTParty.get("#{@site}/users.json", :basic_auth => {:username=>"#{@user}", :password=> "#{@password}" } )
|
73
81
|
users.each { |u|
|
74
82
|
userlist << u["name"]
|
75
83
|
}
|
@@ -78,7 +86,7 @@ module Zdpop
|
|
78
86
|
|
79
87
|
def create_org(org,domain)
|
80
88
|
payload = { :organization => { :name => org, :is_shared => 'true', :is_shared_comments => 'true', :default => domain } }
|
81
|
-
response = HTTParty.post("#{@site}api/v1/organizations.json", :basic_auth => {:username=>"#{@user}", :password=> "#{@password}" }, :body => payload )
|
89
|
+
response = HTTParty.post("#{@site}/api/v1/organizations.json", :basic_auth => {:username=>"#{@user}", :password=> "#{@password}" }, :body => payload )
|
82
90
|
if response.code == 201
|
83
91
|
puts "Created organization #{org}"
|
84
92
|
else
|
@@ -89,12 +97,24 @@ module Zdpop
|
|
89
97
|
def create_user(name,email,org)
|
90
98
|
id = lookup_org_id(org)
|
91
99
|
payload = { :user => { :name => name, :email => email, :roles => '0', :restriction_id => '2', :organization_id => id } }
|
92
|
-
response = HTTParty.post("#{@site}users.json", :basic_auth => {:username=>"#{@user}", :password=> "#{@password}" }, :body => payload )
|
100
|
+
response = HTTParty.post("#{@site}/users.json", :basic_auth => {:username=>"#{@user}", :password=> "#{@password}" }, :body => payload )
|
93
101
|
if response.code == 200
|
94
102
|
puts "Created user #{name}"
|
95
103
|
else
|
96
104
|
puts "Response code: #{response.code} - #{response.body}"
|
97
105
|
end
|
98
106
|
end
|
107
|
+
|
108
|
+
def valid_site(site)
|
109
|
+
begin
|
110
|
+
uri = URI.parse(site.gsub(/\/*$/,''))
|
111
|
+
if uri.class != URI::HTTPS
|
112
|
+
puts "Only HTTPS protocol addresses can be used"
|
113
|
+
end
|
114
|
+
return uri
|
115
|
+
rescue URI::InvalidURIError
|
116
|
+
puts "The site: #{site} is not a valid URL"
|
117
|
+
end
|
118
|
+
end
|
99
119
|
end
|
100
120
|
end
|
data/lib/zdpop/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zendesk-populator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Turnbull
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable: zdpop
|
18
|
+
date: 2012-02-01 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: httparty
|
@@ -48,7 +47,6 @@ files:
|
|
48
47
|
- bin/zdpop
|
49
48
|
- lib/zdpop/populator.rb
|
50
49
|
- lib/zdpop/version.rb
|
51
|
-
has_rdoc: true
|
52
50
|
homepage: http://github.com/jamtur01/zendesk-populator/
|
53
51
|
licenses:
|
54
52
|
- APL2
|
@@ -78,9 +76,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
76
|
requirements: []
|
79
77
|
|
80
78
|
rubyforge_project:
|
81
|
-
rubygems_version: 1.
|
79
|
+
rubygems_version: 1.8.11
|
82
80
|
signing_key:
|
83
81
|
specification_version: 3
|
84
82
|
summary: A command line tool to generate Zendesk orgs and users from CSV.
|
85
83
|
test_files: []
|
86
84
|
|
85
|
+
has_rdoc:
|