zedkit 1.1.3
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.
- data/LICENSE +15 -0
- data/README.rdoc +8 -0
- data/Rakefile +75 -0
- data/VERSION +1 -0
- data/bin/zedkit +23 -0
- data/lib/cli/config.rb +20 -0
- data/lib/zedkit/cli/bottom.rb +32 -0
- data/lib/zedkit/cli/exceptions.rb +49 -0
- data/lib/zedkit/cli/projects.rb +56 -0
- data/lib/zedkit/cli/runner.rb +144 -0
- data/lib/zedkit/cli/text.rb +82 -0
- data/lib/zedkit/client/client.rb +108 -0
- data/lib/zedkit/client/configuration.rb +53 -0
- data/lib/zedkit/client/exceptions.rb +67 -0
- data/lib/zedkit/ext/hash.rb +51 -0
- data/lib/zedkit/instances/instance.rb +50 -0
- data/lib/zedkit/instances/project.rb +43 -0
- data/lib/zedkit/resources/projects.rb +77 -0
- data/lib/zedkit/resources/users.rb +44 -0
- data/lib/zedkit.rb +71 -0
- data/test/helper.rb +41 -0
- data/test/test_emails.rb +21 -0
- data/test/test_entities.rb +64 -0
- data/test/test_projects.rb +139 -0
- data/test/test_users.rb +81 -0
- metadata +120 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module Zedkit
|
19
|
+
class Configuration
|
20
|
+
attr_accessor :project_key, :locales_key, :ssl, :exceptions, :api_host, :api_port
|
21
|
+
|
22
|
+
API_HOSTNAME = 'api.zedapi.com'
|
23
|
+
API_PORT = 80
|
24
|
+
PROJECT_KEY_LENGTH = 18
|
25
|
+
LOCALES_KEY_LENGTH = 18
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
@project_key, @locales_key = nil, nil
|
29
|
+
@ssl = false
|
30
|
+
@exceptions = false
|
31
|
+
@api_host = API_HOSTNAME
|
32
|
+
@api_port = API_PORT
|
33
|
+
end
|
34
|
+
|
35
|
+
def has_project_key?
|
36
|
+
(not project_key.nil?) && project_key.is_a?(String) && project_key.length == PROJECT_KEY_LENGTH
|
37
|
+
end
|
38
|
+
def has_locales_key?
|
39
|
+
(not locales_key.nil?) && locales_key.is_a?(String) && locales_key.length == LOCALES_KEY_LENGTH
|
40
|
+
end
|
41
|
+
|
42
|
+
def ssl?
|
43
|
+
ssl
|
44
|
+
end
|
45
|
+
def exceptions?
|
46
|
+
exceptions
|
47
|
+
end
|
48
|
+
|
49
|
+
def api_url
|
50
|
+
ssl? ? "https://#{api_host}:#{api_port}" : "http://#{api_host}:#{api_port}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module Zedkit
|
19
|
+
class ZedkitError < StandardError
|
20
|
+
end
|
21
|
+
|
22
|
+
module Client
|
23
|
+
class ClientError < ZedkitError
|
24
|
+
attr_reader :http_code, :api_code, :message, :errors
|
25
|
+
|
26
|
+
def initialize(info = {})
|
27
|
+
@http_code = info[:http_code] || 0
|
28
|
+
@api_code = info[:api_code] || nil
|
29
|
+
@message = info[:message] || nil
|
30
|
+
@errors = info[:errors] || nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
rs = "\nZedkit API Error Response.\n" \
|
35
|
+
<< " HTTP Code => #{http_code}. #{http_string(http_code)}\n"
|
36
|
+
rs << " API Status Code => #{api_code}.\n" unless api_code.nil?
|
37
|
+
rs << " API Response Message => #{message}.\n" unless message.nil?
|
38
|
+
rs << " API Error Attribute Details => #{@errors['attributes'].map {|k,v| "#{k} => #{v}" }}.\n" unless errors.nil?
|
39
|
+
rs << "\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def http_string(code)
|
44
|
+
case code.to_i
|
45
|
+
when 200
|
46
|
+
"OK."
|
47
|
+
when 401
|
48
|
+
"Unauthorized."
|
49
|
+
when 403
|
50
|
+
"Forbidden."
|
51
|
+
when 404
|
52
|
+
"Does Not Exist."
|
53
|
+
else
|
54
|
+
"Undefined." end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class UnauthorizedAccess < ClientError
|
59
|
+
end
|
60
|
+
class UnauthorizedAccess < ClientError
|
61
|
+
end
|
62
|
+
class ResourceNotFound < ClientError
|
63
|
+
end
|
64
|
+
class DataValidationError < ClientError
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
##
|
19
|
+
# We want to transform something like this:
|
20
|
+
# { :user => { :email => "whatever@zedkit.com", :password => "pwd", :first_name => "Fred", :surname => "Flintstone" } }
|
21
|
+
#
|
22
|
+
# Into something like this for submission to the ZedAPI:
|
23
|
+
# {
|
24
|
+
# "user[email]" => "whatever@zedkit.com",
|
25
|
+
# "user[password]" => "pwd", "user[first_name]" => "Fred", "user[surname]" => "Flintstone"
|
26
|
+
# }
|
27
|
+
#
|
28
|
+
# The API only ever uses a single level, never something like [user][project][name]. If more than a single level is
|
29
|
+
# submitted we don't bother to try and sort it out here, as it will not work anyway. Let the caller figure that out and
|
30
|
+
# resolve it on their end.
|
31
|
+
#
|
32
|
+
# FYI, the API's backend controllers do NOT use mass assignment for attributes submitted, EVER. Submitting anything other
|
33
|
+
# than documented object data items for each API method has no negative impact. Inapplicable attributes, or nefarious
|
34
|
+
# submissions on update, such as user[uuid], are simply ignored.
|
35
|
+
##
|
36
|
+
|
37
|
+
class Hash
|
38
|
+
def flatten_zedkit_params! ## The implementation of this did not require a staging hash until
|
39
|
+
tmph = {} ## 1.9.2: RuntimeError: can't add a new key into hash during iteration
|
40
|
+
each do |k,v|
|
41
|
+
if v.is_a?(Hash) # self.each do |k,v|
|
42
|
+
v.each {|vk,vv| tmph["#{k}[#{vk}]"] = vv } # if v.is_a?(Hash)
|
43
|
+
delete(k) # v.each {|vk,vv| merge!({ "#{k}[#{vk}]" => vv }) }
|
44
|
+
end # self.delete(k)
|
45
|
+
end # end
|
46
|
+
merge!(tmph) # end
|
47
|
+
end
|
48
|
+
def zdelete_keys!(zedkeys = [])
|
49
|
+
delete_if {|k| zedkeys.include?(k.to_s) }
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module Zedkit
|
19
|
+
class Instance < Hash
|
20
|
+
attr_accessor :user_key, :locale
|
21
|
+
alias_method :uk, :user_key
|
22
|
+
alias_method :lc, :locale
|
23
|
+
|
24
|
+
def initialize(api = {})
|
25
|
+
@user_key = api[:user_key] || nil
|
26
|
+
@locale = api[:locale] || :en
|
27
|
+
if api.has_key?(:owner) && api.has_key?(:uuid)
|
28
|
+
set_with_owner_and_uuid(api[:owner], api[:uuid]) && respond_to?(:set_with_owner_and_uuid)
|
29
|
+
elsif api.has_key?(:uuid) && respond_to?(:uuid)
|
30
|
+
set_with_uuid(api[:uuid]) end
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_with_hash(hh)
|
34
|
+
replace hh
|
35
|
+
end
|
36
|
+
|
37
|
+
def method_missing(kk)
|
38
|
+
return self[kk.to_s] if self.has_key? kk.to_s
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
def time(i)
|
44
|
+
Time.at(i).to_date
|
45
|
+
end
|
46
|
+
def dashes(length = 128)
|
47
|
+
Array.new(length, '-').join << "\n"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module Zedkit
|
19
|
+
class Project < Zedkit::Instance
|
20
|
+
def to_s
|
21
|
+
"\n" \
|
22
|
+
<< "Zedkit Project:\n" \
|
23
|
+
<< " Name : #{name}\n" \
|
24
|
+
<< " UUID : #{uuid}\n" \
|
25
|
+
<< " Location : #{location}\n" \
|
26
|
+
<< " Locales\n" \
|
27
|
+
<< " Default : #{locales['default']}\n" \
|
28
|
+
<< " Development : #{locales['development']}\n" \
|
29
|
+
<< " Production : #{locales['production']}\n" \
|
30
|
+
<< " Shelves : []\n" \
|
31
|
+
<< " Blogs : []\n" \
|
32
|
+
<< " Version : #{version}\n" \
|
33
|
+
<< " Created : #{time(created_at)}\n" \
|
34
|
+
<< " Updated : #{time(updated_at)}\n" \
|
35
|
+
<< dashes(20) << "\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
def set_with_uuid(uuid_to_use)
|
40
|
+
replace Zedkit::Projects.get(:user_key => uk, :locale => lc, :uuid => uuid_to_use)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module Zedkit
|
19
|
+
class Projects
|
20
|
+
class << self
|
21
|
+
def verify(type, key = nil, &block)
|
22
|
+
rs = nil
|
23
|
+
case type.to_sym
|
24
|
+
when :project
|
25
|
+
rs = Zedkit::Client.get('projects/verify', nil)
|
26
|
+
when :locales
|
27
|
+
rs = Zedkit::Client.get('projects/verify/locales', nil, { :locales_key => key })
|
28
|
+
end
|
29
|
+
yield(rs) if rs && block_given?
|
30
|
+
rs
|
31
|
+
end
|
32
|
+
|
33
|
+
def get(zks = {}, &block) ## This avoids /projects/[nil] which is a
|
34
|
+
zks[:uuid] = 'uuid' if zks[:uuid].nil? ## valid resource to list a user's projects.
|
35
|
+
Zedkit::Client.crud(:get, "projects/#{zks[:uuid]}", zks, [], &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
def create(zks = {}, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def update(zks = {}, &block)
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete(zks = {}, &block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Users
|
49
|
+
class << self
|
50
|
+
def get(zks = {}, &block)
|
51
|
+
Zedkit::Client.crud(:get, "projects/#{zks[:project][:uuid]}/users", zks, %w(project), &block)
|
52
|
+
end
|
53
|
+
|
54
|
+
def create(zks = {}, &block)
|
55
|
+
Zedkit::Client.crud(:create, "projects/#{zks[:project][:uuid]}/users", zks, %w(project), &block)
|
56
|
+
end
|
57
|
+
|
58
|
+
def update(zks = {}, &block)
|
59
|
+
Zedkit::Client.crud(:update,
|
60
|
+
"projects/#{zks[:project][:uuid]}/users/#{zks[:user][:uuid]}", zks, %w(project), &block)
|
61
|
+
end
|
62
|
+
|
63
|
+
def delete(zks = {}, &block)
|
64
|
+
Zedkit::Client.crud(:delete, "projects/#{zks[:project][:uuid]}/users/#{zks[:user][:uuid]}", zks, [], &block)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Emails
|
70
|
+
class << self
|
71
|
+
def get(zks = {}, &block)
|
72
|
+
Zedkit::Client.crud(:get, 'emails', zks, [], &block)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module Zedkit
|
19
|
+
class Users
|
20
|
+
class << self
|
21
|
+
def verify(zks = {}, &block)
|
22
|
+
rs = Zedkit::Client.verify(zks[:username], zks[:password])
|
23
|
+
yield(rs) if rs && block_given?
|
24
|
+
rs
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(zks = {}, &block)
|
28
|
+
Zedkit::Client.crud(:get, "users/#{zks[:uuid]}", zks, [], &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def create(zks = {}, &block)
|
32
|
+
Zedkit::Client.crud(:create, 'users', zks, [], &block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Projects
|
37
|
+
class << self
|
38
|
+
def get(zks = {}, &block)
|
39
|
+
Zedkit::Client.crud(:get, 'projects', zks, [], &block)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/zedkit.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
require 'rubygems'
|
19
|
+
require 'json'
|
20
|
+
require 'nestful'
|
21
|
+
|
22
|
+
Dir["#{File.dirname(__FILE__)}/zedkit/ext/*.rb"].each {|ci| require ci }
|
23
|
+
|
24
|
+
module Zedkit
|
25
|
+
class << self
|
26
|
+
def countries(user_key)
|
27
|
+
rs = Zedkit::Client.get('entities/countries', user_key)
|
28
|
+
if rs && block_given?
|
29
|
+
rs.is_a?(Array) ? rs.each {|i| yield(i) } : yield(rs)
|
30
|
+
end
|
31
|
+
rs
|
32
|
+
end
|
33
|
+
def regions(user_key, zks = {})
|
34
|
+
rs = Zedkit::Client.get('entities/regions', user_key, zks)
|
35
|
+
if rs && block_given?
|
36
|
+
rs.is_a?(Array) ? rs.each {|i| yield(i) } : yield(rs)
|
37
|
+
end
|
38
|
+
rs
|
39
|
+
end
|
40
|
+
|
41
|
+
def entities(user_key)
|
42
|
+
rs = Zedkit::Client.get('entities/zedkit', user_key)
|
43
|
+
if rs && block_given?
|
44
|
+
rs.is_a?(Array) ? rs.each {|i| yield(i) } : yield(rs)
|
45
|
+
end
|
46
|
+
rs
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# == Configuration
|
51
|
+
#
|
52
|
+
# Call the configure method within an application configuration initializer to set your project key,
|
53
|
+
# and other goodies:
|
54
|
+
# Zedkit.configure do |zb|
|
55
|
+
# zb.project_key = 'from.zedkit.com.members.area'
|
56
|
+
# zb.ssl = true
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
|
60
|
+
attr_accessor :configuration
|
61
|
+
def configure
|
62
|
+
self.configuration ||= Configuration.new
|
63
|
+
yield(configuration)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Dir["#{File.dirname(__FILE__)}/zedkit/client/*.rb"].each {|ci| require ci }
|
69
|
+
Dir["#{File.dirname(__FILE__)}/zedkit/cli/*.rb"].each {|ci| require ci }
|
70
|
+
Dir["#{File.dirname(__FILE__)}/zedkit/instances/*.rb"].each {|ci| require ci }
|
71
|
+
Dir["#{File.dirname(__FILE__)}/zedkit/resources/*.rb"].each {|ci| require ci }
|
data/test/helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
require 'test/unit'
|
19
|
+
require 'rubygems'
|
20
|
+
require 'zedkit'
|
21
|
+
|
22
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
23
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
24
|
+
|
25
|
+
class Test::Unit::TestCase
|
26
|
+
TEST_GEMS_PROJECT_KEY = 'BE1OZog8gJogtQTosh'
|
27
|
+
TEST_GEMS_LOCALES_KEY = '6yca7DsnBvaDVupKEZ'
|
28
|
+
TEST_GEMS_LOGIN = 'gems@zedkit.com'
|
29
|
+
TEST_GEMS_LACKY = 'gems_lacky@zedkit.com'
|
30
|
+
TEST_GEMS_TEMP = 'temp@zedkit.com'
|
31
|
+
TEST_GEMS_PASSWORD = 'NGIaDhr5vDlXo1tDs6bW3Gd'
|
32
|
+
|
33
|
+
def setup
|
34
|
+
Zedkit.configure do |zk|
|
35
|
+
zk.project_key = TEST_GEMS_PROJECT_KEY
|
36
|
+
# zk.api_host = '0.0.0.0'
|
37
|
+
# zk.api_port = 5010
|
38
|
+
end
|
39
|
+
@uu = Zedkit::Users.verify(:username => TEST_GEMS_LOGIN, :password => TEST_GEMS_PASSWORD)
|
40
|
+
end
|
41
|
+
end
|
data/test/test_emails.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
require 'helper'
|
19
|
+
|
20
|
+
class TestEmails < Test::Unit::TestCase
|
21
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
require 'helper'
|
19
|
+
|
20
|
+
class TestEntities < Test::Unit::TestCase
|
21
|
+
def test_entities
|
22
|
+
zkes = Zedkit.entities(@uu['user_key'])
|
23
|
+
end
|
24
|
+
def test_entities_with_block
|
25
|
+
Zedkit.entities(@uu['user_key']) do |zkes|
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_countries
|
30
|
+
cnts = Zedkit.countries(@uu['user_key'])
|
31
|
+
assert cnts.is_a? Array
|
32
|
+
assert cnts.length >= 2
|
33
|
+
end
|
34
|
+
def test_countries_with_block
|
35
|
+
Zedkit.countries(@uu['user_key']) do |cnts|
|
36
|
+
assert_not_nil cnts['code']
|
37
|
+
assert_not_nil cnts['name']
|
38
|
+
assert_not_nil cnts['locale']
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_regions
|
43
|
+
rgss = Zedkit.regions(@uu['user_key'])
|
44
|
+
assert rgss.is_a? Array
|
45
|
+
assert_not_nil rgss.detect {|region| region['code'] == 'WA' }
|
46
|
+
assert_not_nil rgss.detect {|region| region['code'] == 'BC' }
|
47
|
+
end
|
48
|
+
def test_regions_with_block
|
49
|
+
Zedkit.regions(@uu['user_key']) do |rgss|
|
50
|
+
assert_not_nil rgss['code']
|
51
|
+
assert_not_nil rgss['name']
|
52
|
+
end
|
53
|
+
end
|
54
|
+
def test_states_for_usa
|
55
|
+
rgss = Zedkit.regions(@uu['user_key'], :country => { :code => 'US' })
|
56
|
+
assert rgss.is_a? Array
|
57
|
+
assert_nil rgss.detect {|region| region['code'] == 'BC' }
|
58
|
+
end
|
59
|
+
def test_provinces_for_canada
|
60
|
+
rgss = Zedkit.regions(@uu['user_key'], :country => { :code => 'CA' })
|
61
|
+
assert rgss.is_a? Array
|
62
|
+
assert_nil rgss.detect {|region| region['code'] == 'WA' }
|
63
|
+
end
|
64
|
+
end
|