zedkit 1.1.5 → 1.2.0
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/README.rdoc +1 -1
- data/Rakefile +19 -19
- data/VERSION +1 -1
- data/bin/zedkit +3 -3
- data/lib/cli/config.rb +2 -2
- data/lib/zedkit.rb +33 -25
- data/lib/zedkit/cli/runner.rb +18 -12
- data/lib/zedkit/cli/text.rb +6 -1
- data/lib/zedkit/cli/users.rb +48 -0
- data/lib/zedkit/client/client.rb +41 -34
- data/lib/zedkit/client/configuration.rb +13 -7
- data/lib/zedkit/client/exceptions.rb +2 -2
- data/lib/zedkit/ext/array.rb +22 -0
- data/lib/zedkit/ext/benchmark.rb +38 -0
- data/lib/zedkit/ext/hash.rb +11 -4
- data/lib/zedkit/instances/instance.rb +2 -2
- data/lib/zedkit/instances/project.rb +2 -2
- data/lib/zedkit/rails/sessions.rb +3 -3
- data/lib/zedkit/resources/blog_posts.rb +38 -0
- data/lib/zedkit/resources/blogs.rb +46 -0
- data/lib/zedkit/resources/email_settings.rb +3 -3
- data/lib/zedkit/resources/emails.rb +3 -3
- data/lib/zedkit/resources/project_admins.rb +35 -0
- data/lib/zedkit/resources/project_keys.rb +34 -0
- data/lib/zedkit/resources/projects.rb +26 -22
- data/lib/zedkit/resources/shortened_urls.rb +38 -0
- data/lib/zedkit/resources/shorteners.rb +46 -0
- data/lib/zedkit/resources/users.rb +5 -5
- data/test/helper.rb +15 -15
- data/test/test_blog_posts.rb +38 -0
- data/test/test_blogs.rb +41 -0
- data/test/test_email_settings.rb +3 -3
- data/test/test_emails.rb +3 -3
- data/test/test_entities.rb +20 -20
- data/test/test_projects.rb +80 -62
- data/test/test_shortened_urls.rb +38 -0
- data/test/test_shorteners.rb +41 -0
- data/test/test_users.rb +30 -30
- metadata +51 -65
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#
|
2
2
|
# Copyright (c) Zedkit.
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
@@ -13,13 +13,13 @@
|
|
13
13
|
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
14
|
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
15
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
-
|
16
|
+
#
|
17
17
|
|
18
|
-
require
|
19
|
-
require
|
18
|
+
require "rubygems"
|
19
|
+
require "rake"
|
20
20
|
|
21
21
|
begin
|
22
|
-
require
|
22
|
+
require "jeweler"
|
23
23
|
Jeweler::Tasks.new do |gem|
|
24
24
|
gem.name = "zedkit"
|
25
25
|
gem.summary = %Q{gem for Zedkit}
|
@@ -30,30 +30,30 @@ begin
|
|
30
30
|
gem.authors = ["Zedkit"]
|
31
31
|
gem.rubyforge_project = "zedkit"
|
32
32
|
|
33
|
-
gem.files = FileList[
|
33
|
+
gem.files = FileList["[A-Z]*", "bin/*", "lib/**/*.rb", "test/**/*.rb"]
|
34
34
|
gem.executables = %w(zedkit)
|
35
35
|
gem.default_executable = %q{zedkit}
|
36
36
|
|
37
|
-
gem.add_dependency
|
38
|
-
gem.add_dependency
|
37
|
+
gem.add_dependency "json", ">= 1.4.0"
|
38
|
+
gem.add_dependency "nestful"
|
39
39
|
end
|
40
40
|
Jeweler::GemcutterTasks.new
|
41
41
|
rescue LoadError
|
42
42
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
43
43
|
end
|
44
44
|
|
45
|
-
require
|
45
|
+
require "rake/testtask"
|
46
46
|
Rake::TestTask.new(:test) do |test|
|
47
|
-
test.libs <<
|
48
|
-
test.pattern =
|
47
|
+
test.libs << "lib" << "test"
|
48
|
+
test.pattern = "test/**/test_*.rb"
|
49
49
|
test.verbose = true
|
50
50
|
end
|
51
51
|
|
52
52
|
begin
|
53
|
-
require
|
53
|
+
require "rcov/rcovtask"
|
54
54
|
Rcov::RcovTask.new do |test|
|
55
|
-
test.libs <<
|
56
|
-
test.pattern =
|
55
|
+
test.libs << "test"
|
56
|
+
test.pattern = "test/**/test_*.rb"
|
57
57
|
test.verbose = true
|
58
58
|
end
|
59
59
|
rescue LoadError
|
@@ -65,11 +65,11 @@ end
|
|
65
65
|
task :test => :check_dependencies
|
66
66
|
task :default => :test
|
67
67
|
|
68
|
-
require
|
68
|
+
require "rdoc/task"
|
69
69
|
Rake::RDocTask.new do |rdoc|
|
70
|
-
version = File.exist?(
|
71
|
-
rdoc.rdoc_dir =
|
70
|
+
version = File.exist?("VERSION") ? File.read("VERSION") : ""
|
71
|
+
rdoc.rdoc_dir = "rdoc"
|
72
72
|
rdoc.title = "zedkit #{version}"
|
73
|
-
rdoc.rdoc_files.include(
|
74
|
-
rdoc.rdoc_files.include(
|
73
|
+
rdoc.rdoc_files.include("README*")
|
74
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
75
75
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/bin/zedkit
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
#
|
3
3
|
# Copyright (c) Zedkit.
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
@@ -14,9 +14,9 @@
|
|
14
14
|
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
15
|
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
16
16
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
|
-
|
17
|
+
#
|
18
18
|
|
19
|
-
require
|
19
|
+
require "zedkit"
|
20
20
|
|
21
21
|
Dir["#{File.dirname(__FILE__)}/../lib/cli/*.rb"].each {|ci| require ci }
|
22
22
|
|
data/lib/cli/config.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#
|
2
2
|
# Copyright (c) Zedkit.
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
@@ -13,7 +13,7 @@
|
|
13
13
|
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
14
|
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
15
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
-
|
16
|
+
#
|
17
17
|
|
18
18
|
Zedkit.configure do |zk|
|
19
19
|
zk.exceptions = true
|
data/lib/zedkit.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#
|
2
2
|
# Copyright (c) Zedkit.
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
@@ -13,25 +13,27 @@
|
|
13
13
|
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
14
|
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
15
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
-
|
16
|
+
#
|
17
17
|
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
18
|
+
require "rubygems"
|
19
|
+
require "json"
|
20
|
+
require "nestful"
|
21
21
|
|
22
|
-
require
|
22
|
+
require "zedkit/ext/array.rb"
|
23
|
+
require "zedkit/ext/hash.rb"
|
24
|
+
require "zedkit/ext/benchmark.rb"
|
23
25
|
|
24
26
|
module Zedkit
|
25
27
|
class << self
|
26
28
|
def countries
|
27
|
-
rs = Zedkit::Client.get(
|
29
|
+
rs = Zedkit::Client.get("entities/countries")
|
28
30
|
if rs && block_given?
|
29
31
|
rs.is_a?(Array) ? rs.each {|i| yield(i) } : yield(rs)
|
30
32
|
end
|
31
33
|
rs
|
32
34
|
end
|
33
35
|
def regions(zks = {})
|
34
|
-
rs = Zedkit::Client.get(
|
36
|
+
rs = Zedkit::Client.get("entities/regions", nil, zks)
|
35
37
|
if rs && block_given?
|
36
38
|
rs.is_a?(Array) ? rs.each {|i| yield(i) } : yield(rs)
|
37
39
|
end
|
@@ -39,7 +41,7 @@ module Zedkit
|
|
39
41
|
end
|
40
42
|
|
41
43
|
def entities
|
42
|
-
rs = Zedkit::Client.get(
|
44
|
+
rs = Zedkit::Client.get("entities/zedkit")
|
43
45
|
if rs && block_given?
|
44
46
|
rs.is_a?(Array) ? rs.each {|i| yield(i) } : yield(rs)
|
45
47
|
end
|
@@ -52,7 +54,7 @@ module Zedkit
|
|
52
54
|
# Call the configure method within an application configuration initializer to set your project key,
|
53
55
|
# and other goodies:
|
54
56
|
# Zedkit.configure do |zb|
|
55
|
-
# zb.project_key =
|
57
|
+
# zb.project_key = "from.zedkit.com.members.area"
|
56
58
|
# zb.ssl = true
|
57
59
|
# end
|
58
60
|
#
|
@@ -65,22 +67,28 @@ module Zedkit
|
|
65
67
|
end
|
66
68
|
end
|
67
69
|
|
68
|
-
require
|
69
|
-
require
|
70
|
-
require
|
70
|
+
require "zedkit/client/configuration.rb"
|
71
|
+
require "zedkit/client/client.rb"
|
72
|
+
require "zedkit/client/exceptions.rb"
|
71
73
|
|
72
|
-
require
|
73
|
-
require
|
74
|
-
require
|
75
|
-
require
|
76
|
-
require
|
74
|
+
require "zedkit/cli/bottom.rb"
|
75
|
+
require "zedkit/cli/exceptions.rb"
|
76
|
+
require "zedkit/cli/projects.rb"
|
77
|
+
require "zedkit/cli/runner.rb"
|
78
|
+
require "zedkit/cli/text.rb"
|
77
79
|
|
78
|
-
require
|
79
|
-
require
|
80
|
+
require "zedkit/instances/instance.rb"
|
81
|
+
require "zedkit/instances/project.rb"
|
80
82
|
|
81
|
-
require
|
82
|
-
require
|
83
|
-
require
|
84
|
-
require
|
83
|
+
require "zedkit/resources/projects.rb"
|
84
|
+
require "zedkit/resources/project_keys.rb"
|
85
|
+
require "zedkit/resources/project_admins.rb"
|
86
|
+
require "zedkit/resources/users.rb"
|
87
|
+
require "zedkit/resources/blogs.rb"
|
88
|
+
require "zedkit/resources/blog_posts.rb"
|
89
|
+
require "zedkit/resources/shorteners.rb"
|
90
|
+
require "zedkit/resources/shortened_urls.rb"
|
91
|
+
require "zedkit/resources/emails.rb"
|
92
|
+
require "zedkit/resources/email_settings.rb"
|
85
93
|
|
86
|
-
require
|
94
|
+
require "zedkit/rails/sessions" if defined?(Rails::Railtie)
|
data/lib/zedkit/cli/runner.rb
CHANGED
@@ -19,14 +19,14 @@ module Zedkit
|
|
19
19
|
module CLI
|
20
20
|
class Runner
|
21
21
|
attr_accessor :user_key, :username, :password, :locale
|
22
|
-
attr_reader :section, :command, :items
|
22
|
+
attr_reader :config, :section, :command, :items
|
23
23
|
|
24
24
|
SECTIONS = ['projects']
|
25
|
-
CONFIG = "#{File.expand_path('~')}/.zedkit"
|
26
25
|
|
27
26
|
def initialize
|
28
27
|
@user_key, @username, @password = nil, nil, nil
|
29
28
|
@locale = :en
|
29
|
+
@config = File.expand_path('~') << "/.zedkit"
|
30
30
|
if !ARGV.empty? && ARGV[0].include?(":")
|
31
31
|
@section = ARGV[0].split(":")[0]
|
32
32
|
@command = ARGV[0].split(":")[1]
|
@@ -76,7 +76,7 @@ module Zedkit
|
|
76
76
|
if has_section? && has_command?
|
77
77
|
if has_credentials?
|
78
78
|
unless has_user_key?
|
79
|
-
@user_key = Zedkit::Users.verify(:
|
79
|
+
@user_key = Zedkit::Users.verify(:login => username, :password => password)['user_key']
|
80
80
|
end
|
81
81
|
run
|
82
82
|
else
|
@@ -108,18 +108,24 @@ module Zedkit
|
|
108
108
|
def commands
|
109
109
|
"\n" \
|
110
110
|
<< "== #{Zedkit::CLI.tt(locale, :commands, :projects)}\n\n" \
|
111
|
-
<< "list
|
112
|
-
<< "show <uuid>
|
113
|
-
<< "create <name> key=value [...]
|
114
|
-
<< "update <uuid> key=value [...]
|
115
|
-
<< "delete <uuid>
|
111
|
+
<< "list # #{Zedkit::CLI.tt(locale, :commands, :projects_list)}\n" \
|
112
|
+
<< "show <uuid> # #{Zedkit::CLI.tt(locale, :commands, :projects_show)}\n" \
|
113
|
+
<< "create <name> key=value [...] # #{Zedkit::CLI.tt(locale, :commands, :projects_create)}\n" \
|
114
|
+
<< "update <uuid> key=value [...] # #{Zedkit::CLI.tt(locale, :commands, :projects_update)}\n" \
|
115
|
+
<< "delete <uuid> # #{Zedkit::CLI.tt(locale, :commands, :projects_delete)}\n\n" \
|
116
|
+
<< "== User Commands\n\n" \
|
117
|
+
<< "users:list <project uuid> # #{Zedkit::CLI.tt(locale, :commands, :users_list)}\n" \
|
118
|
+
<< "users:show <project uuid> <login> # #{Zedkit::CLI.tt(locale, :commands, :users_show)}\n" \
|
119
|
+
<< "users:create <project> key=value [...] # #{Zedkit::CLI.tt(locale, :commands, :users_create)}\n" \
|
120
|
+
<< "users:update <uuid> key=value [...] # #{Zedkit::CLI.tt(locale, :commands, :users_update)}\n" \
|
121
|
+
<< "users:delete <uuid> # #{Zedkit::CLI.tt(locale, :commands, :users_delete)}\n\n" \
|
116
122
|
<< "==\n\n"
|
117
123
|
end
|
118
124
|
|
119
125
|
private
|
120
126
|
def set_credentials
|
121
|
-
if File.exists?(
|
122
|
-
st = File.open(
|
127
|
+
if File.exists?(config)
|
128
|
+
st = File.open(config).readlines.map(&:strip).delete_if {|i| i.empty? }
|
123
129
|
if st.length > 2
|
124
130
|
@username = st[0]
|
125
131
|
@password = st[1]
|
@@ -132,8 +138,8 @@ module Zedkit
|
|
132
138
|
ARGV.length > 1 ? @items = ARGV.slice(1, ARGV.length - 1) : @items = nil
|
133
139
|
end
|
134
140
|
def set_locale
|
135
|
-
if File.exists?(
|
136
|
-
st = File.open(
|
141
|
+
if File.exists?(config)
|
142
|
+
st = File.open(config).readlines.map(&:strip).delete_if {|i| i.empty? }
|
137
143
|
if st.length >= 2
|
138
144
|
@locale = st[st.length - 1].to_sym if Zedkit::CLI.include?(st[st.length - 1].to_sym)
|
139
145
|
end
|
data/lib/zedkit/cli/text.rb
CHANGED
@@ -35,7 +35,12 @@ module Zedkit
|
|
35
35
|
:projects_show => "Show Zedkit project details",
|
36
36
|
:projects_create => "Create a new Zedkit project",
|
37
37
|
:projects_update => "Update an existing Zedkit project",
|
38
|
-
:projects_delete => "Delete an existing Zedkit project"
|
38
|
+
:projects_delete => "Delete an existing Zedkit project",
|
39
|
+
:users_list => "List a project's users",
|
40
|
+
:users_show => "Show user details",
|
41
|
+
:users_create => "Create a new user",
|
42
|
+
:users_update => "Update an existing user",
|
43
|
+
:users_delete => "Delete an existing user"
|
39
44
|
}
|
40
45
|
}
|
41
46
|
}
|
@@ -0,0 +1,48 @@
|
|
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
|
+
module CLI
|
20
|
+
class Users < Zedkit::CLI::Bottom
|
21
|
+
class << self
|
22
|
+
def list(opts = {})
|
23
|
+
puts "\n" << Zedkit::CLI.ee(opts[:locale], :general, :not_done) << "\n\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
def show(opts = {})
|
27
|
+
puts "\n" << Zedkit::CLI.ee(opts[:locale], :general, :not_done) << "\n\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
def create(opts = {})
|
31
|
+
puts "\n" << Zedkit::CLI.ee(opts[:locale], :general, :not_done) << "\n\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
def update(opts = {})
|
35
|
+
puts "\n" << Zedkit::CLI.ee(opts[:locale], :general, :not_done) << "\n\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete(opts = {})
|
39
|
+
puts "\n" << Zedkit::CLI.ee(opts[:locale], :general, :not_done) << "\n\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
def before_show_update_delete(opts = {})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/zedkit/client/client.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#
|
2
2
|
# Copyright (c) Zedkit.
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
@@ -13,20 +13,20 @@
|
|
13
13
|
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
14
|
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
15
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
-
|
16
|
+
#
|
17
17
|
|
18
18
|
module Zedkit
|
19
19
|
module Client
|
20
20
|
class << self
|
21
|
-
def crud(method, resource, zks,
|
21
|
+
def crud(method, resource, zks, del_keys, &block)
|
22
22
|
rs = nil
|
23
23
|
case method
|
24
24
|
when :get
|
25
|
-
rs = submit_request(:get, resource, zks[:user_key], zks.zdelete_keys!(%w(user_key uuid) +
|
25
|
+
rs = submit_request(:get, resource, zks[:user_key], zks.zdelete_keys!(%w(user_key uuid) + del_keys))
|
26
26
|
when :create
|
27
|
-
rs = submit_request(:post, resource, zks[:user_key], zks.zdelete_keys!(%w(user_key) +
|
27
|
+
rs = submit_request(:post, resource, zks[:user_key], zks.zdelete_keys!(%w(user_key) + del_keys))
|
28
28
|
when :update
|
29
|
-
rs = submit_request(:put, resource, zks[:user_key], zks.zdelete_keys!(%w(user_key uuid) +
|
29
|
+
rs = submit_request(:put, resource, zks[:user_key], zks.zdelete_keys!(%w(user_key uuid) + del_keys))
|
30
30
|
when :delete
|
31
31
|
rs = submit_request(:delete, resource, zks[:user_key])
|
32
32
|
end
|
@@ -36,42 +36,49 @@ module Zedkit
|
|
36
36
|
rs
|
37
37
|
end
|
38
38
|
|
39
|
-
def verify(
|
40
|
-
submit_request(:verify,
|
39
|
+
def verify(login, password)
|
40
|
+
submit_request(:verify, "users/verify", nil, {}, { :user => login, :password => password })
|
41
41
|
end
|
42
|
-
def get(resource, user_key = nil, params = {})
|
43
|
-
submit_request(:get, resource, user_key, params)
|
42
|
+
def get(resource, user_key = nil, params = {}, &block)
|
43
|
+
rs = submit_request(:get, resource, user_key, params)
|
44
|
+
if rs && block_given?
|
45
|
+
rs.is_a?(Array) ? rs.each {|i| yield(i) } : yield(rs)
|
46
|
+
end
|
47
|
+
rs
|
44
48
|
end
|
45
49
|
|
46
50
|
protected
|
47
51
|
def submit_request(method, rs, user_key = nil, params = {}, options = {})
|
48
52
|
rh = nil
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
Benchmark.zk_time(method, Zedkit.configuration.debug?) do
|
54
|
+
begin
|
55
|
+
http_request(method, resource_url(rs), user_key, params.flatten_zedkit_params!, options) do |nh|
|
56
|
+
rh = JSON.parse(nh)
|
57
|
+
if rh.is_a?(Hash) && rh.has_key?("status") && Zedkit.configuration.exceptions?
|
58
|
+
raise DataValidationError.new(:http_code => 200, :api_code => rh["status"]["code"],
|
59
|
+
:errors => rh["errors"],
|
60
|
+
:message => rh["status"]["message"] << " [#{method.upcase} #{resource_url(rs)}]")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
rescue Net::HTTPBadResponse
|
64
|
+
## TBD
|
65
|
+
rescue Nestful::UnauthorizedAccess
|
66
|
+
if Zedkit.configuration.exceptions?
|
67
|
+
raise Zedkit::Client::UnauthorizedAccess.new(:http_code => 401,
|
68
|
+
:message => "User Credentials are Invalid [#{method.upcase} #{resource_url(rs)}]")
|
69
|
+
end
|
70
|
+
rescue Nestful::ResourceNotFound
|
71
|
+
if Zedkit.configuration.exceptions?
|
72
|
+
raise Zedkit::Client::ResourceNotFound.new(:http_code => 404,
|
73
|
+
:message => "Resource Requested does not Exist [#{method.upcase} #{resource_url(rs)}]")
|
74
|
+
end
|
75
|
+
rescue Nestful::ForbiddenAccess
|
76
|
+
if Zedkit.configuration.exceptions?
|
77
|
+
raise Zedkit::Client::ForbiddenAccess.new(:http_code => 403,
|
78
|
+
:message => "Access Denied to the Resource Requested [#{method.upcase} #{resource_url(rs)}]")
|
56
79
|
end
|
57
80
|
end
|
58
|
-
|
59
|
-
## TBD
|
60
|
-
rescue Nestful::UnauthorizedAccess
|
61
|
-
if Zedkit.configuration.exceptions?
|
62
|
-
raise Zedkit::Client::UnauthorizedAccess.new(:http_code => 401,
|
63
|
-
:message => "User Credentials are Invalid [#{method.upcase} #{resource_url(rs)}]")
|
64
|
-
end
|
65
|
-
rescue Nestful::ResourceNotFound
|
66
|
-
if Zedkit.configuration.exceptions?
|
67
|
-
raise Zedkit::Client::ResourceNotFound.new(:http_code => 404,
|
68
|
-
:message => "Resource Requested does not Exist [#{method.upcase} #{resource_url(rs)}]")
|
69
|
-
end
|
70
|
-
rescue Nestful::ForbiddenAccess
|
71
|
-
if Zedkit.configuration.exceptions?
|
72
|
-
raise Zedkit::Client::ForbiddenAccess.new(:http_code => 403,
|
73
|
-
:message => "Access Denied to the Resource Requested [#{method.upcase} #{resource_url(rs)}]")
|
74
|
-
end
|
81
|
+
rh
|
75
82
|
end
|
76
83
|
rh
|
77
84
|
end
|