allplayers 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/allplayers.gemspec +1 -1
- data/lib/allplayers/api.rb +2 -2
- data/lib/allplayers/authentication.rb +2 -2
- data/lib/allplayers/client/forms.rb +11 -11
- data/lib/allplayers/client/groups.rb +16 -0
- data/lib/allplayers/client/users.rb +14 -0
- data/lib/allplayers/error.rb +5 -22
- data/lib/allplayers/request.rb +12 -13
- metadata +2 -2
data/allplayers.gemspec
CHANGED
data/lib/allplayers/api.rb
CHANGED
@@ -10,13 +10,13 @@ module AllPlayers
|
|
10
10
|
include Authentication
|
11
11
|
attr_accessor :logger
|
12
12
|
|
13
|
-
def initialize(server = 'https://www.allplayers.com', auth = 'basic', access_token = nil)
|
13
|
+
def initialize(server = 'https://www.allplayers.com', auth = 'basic', access_token = nil, content_type = 'application/json')
|
14
14
|
@base_uri = server
|
15
15
|
if (auth == 'basic')
|
16
16
|
extend AllPlayers::Authentication
|
17
17
|
end
|
18
18
|
@access_token = access_token
|
19
|
-
@headers = {}
|
19
|
+
@headers = {:Content_Type => 'application/json'}
|
20
20
|
end
|
21
21
|
|
22
22
|
# Exchange your oauth_token and oauth_token_secret for an AccessToken instance.
|
@@ -2,13 +2,13 @@ module AllPlayers
|
|
2
2
|
module Authentication
|
3
3
|
def login(name, pass)
|
4
4
|
begin
|
5
|
-
post '
|
5
|
+
post 'user/login' , {:username => name, :password => pass}
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
def logout()
|
10
10
|
begin
|
11
|
-
post '
|
11
|
+
post 'user/logout'
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -1,23 +1,19 @@
|
|
1
1
|
module AllPlayers
|
2
2
|
module Forms
|
3
|
-
def get_submission(form_uuid,
|
4
|
-
if
|
5
|
-
get 'forms/' + form_uuid + '/
|
3
|
+
def get_submission(form_uuid, submission_uuid = nil, user_uuid = nil, form_keys = {})
|
4
|
+
if submission_uuid.nil?
|
5
|
+
get 'forms/' + form_uuid + '/submission', {:user_uuid => user_uuid, :form_keys => form_keys}
|
6
6
|
else
|
7
|
-
get 'forms/' + form_uuid + '/
|
7
|
+
get 'forms/' + form_uuid + '/submission/' + submission_uuid.to_s, {:user_uuid => user_uuid}
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def assign_submission(form_uuid,
|
12
|
-
post 'forms/' + form_uuid + '/assign_submission/' +
|
11
|
+
def assign_submission(form_uuid, submission_uuid, user_uuid)
|
12
|
+
post 'forms/' + form_uuid + '/assign_submission/' + submission_uuid.to_s, {:user_uuid => user_uuid}
|
13
13
|
end
|
14
14
|
|
15
15
|
def create_submission(form_uuid, data = {}, user_uuid = nil)
|
16
|
-
|
17
|
-
data.each do |cid, value|
|
18
|
-
formatted_data.merge!(cid => {:value => {0 => value}})
|
19
|
-
end
|
20
|
-
submission = {:data => formatted_data}
|
16
|
+
submission = {:data => data}
|
21
17
|
|
22
18
|
unless user_uuid.nil?
|
23
19
|
submission.merge!(:user_uuid => user_uuid)
|
@@ -25,6 +21,10 @@ module AllPlayers
|
|
25
21
|
post 'submissions', {:webform => form_uuid, :submission => submission}
|
26
22
|
end
|
27
23
|
|
24
|
+
def delete_submission(form_uuid)
|
25
|
+
delete 'submissions/' + form_uuid
|
26
|
+
end
|
27
|
+
|
28
28
|
def get_webform(form_uuid)
|
29
29
|
get 'webforms/' + form_uuid
|
30
30
|
end
|
@@ -18,6 +18,10 @@ module AllPlayers
|
|
18
18
|
post 'groups/' + target_uuid + '/copy/' + origin_uuid, {:groups_above => groups_above_setting}
|
19
19
|
end
|
20
20
|
|
21
|
+
def group_clone_webforms(target_uuid, origin_uuid, create_new = false, user_uuid = nil)
|
22
|
+
post 'groups/' + target_uuid + '/copywebforms/' + origin_uuid, {:new => create_new, :user_uuid => user_uuid}
|
23
|
+
end
|
24
|
+
|
21
25
|
def group_get(group_uuid)
|
22
26
|
get 'groups/' + group_uuid
|
23
27
|
end
|
@@ -42,6 +46,10 @@ module AllPlayers
|
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
49
|
+
def group_webforms_list(group_uuid)
|
50
|
+
get 'groups/' + group_uuid + '/webforms'
|
51
|
+
end
|
52
|
+
|
45
53
|
def group_roles_list(group_uuid, user_uuid = nil, params = {})
|
46
54
|
if user_uuid.nil?
|
47
55
|
get 'groups/' + group_uuid + '/roles', params
|
@@ -49,5 +57,13 @@ module AllPlayers
|
|
49
57
|
get 'groups/' + group_uuid + '/roles/' + user_uuid, params
|
50
58
|
end
|
51
59
|
end
|
60
|
+
|
61
|
+
def group_subgroups_tree(group_uuid)
|
62
|
+
get 'groups/' + group_uuid + '/subgroups/tree'
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_store_payee(group_uuid, payee = nil)
|
66
|
+
post 'group_stores/' + group_uuid + '/payee', {:payee_uuid => payee}
|
67
|
+
end
|
52
68
|
end
|
53
69
|
end
|
@@ -41,8 +41,22 @@ module AllPlayers
|
|
41
41
|
post 'groups/' + group_uuid + '/join/' + user_uuid, {:org_webform_uuid => webform_id, :role_name => role_name.to_s, :role_options => options}
|
42
42
|
end
|
43
43
|
|
44
|
+
def user_leave_group(group_uuid, user_uuid)
|
45
|
+
post 'groups/' + group_uuid + '/leave/' + user_uuid
|
46
|
+
end
|
47
|
+
|
44
48
|
def user_group_add_role(group_uuid, user_uuid, role_uuid, params = {})
|
45
49
|
post 'groups/' + group_uuid + '/addrole/' + user_uuid + '/' + role_uuid, params
|
46
50
|
end
|
51
|
+
|
52
|
+
def user_create_group(uuid, title, description, location, categories, more_params = {})
|
53
|
+
required_params = {
|
54
|
+
:title => title,
|
55
|
+
:description => description,
|
56
|
+
:location => location,
|
57
|
+
:category => categories
|
58
|
+
}
|
59
|
+
post 'users/' + uuid + '/creategroup', required_params.merge(more_params)
|
60
|
+
end
|
47
61
|
end
|
48
62
|
end
|
data/lib/allplayers/error.rb
CHANGED
@@ -1,32 +1,15 @@
|
|
1
1
|
module AllPlayers
|
2
2
|
# Custom error class for rescuing from all AllPlayers errors
|
3
3
|
class Error < StandardError
|
4
|
-
attr_reader :
|
5
|
-
|
6
|
-
# @return [Hash]
|
7
|
-
def self.errors
|
8
|
-
@errors ||= Hash[descendants.map{|klass| [klass.const_get(:HTTP_STATUS_CODE), klass]}]
|
9
|
-
end
|
10
|
-
|
11
|
-
# @return [Array]
|
12
|
-
def self.descendants
|
13
|
-
ObjectSpace.each_object(::Class).select{|klass| klass < self}
|
14
|
-
end
|
4
|
+
attr_reader :code, :error
|
15
5
|
|
16
6
|
# Initializes a new Error object
|
17
7
|
#
|
18
|
-
# @param
|
19
|
-
# @param response_headers [Hash]
|
8
|
+
# @param response [Hash]
|
20
9
|
# @return [AllPlayers::Error]
|
21
|
-
def initialize(
|
22
|
-
@
|
23
|
-
@
|
24
|
-
exception.respond_to?(:backtrace) ? super(exception.message) : super(exception.to_s)
|
10
|
+
def initialize(response)
|
11
|
+
@code = response.code
|
12
|
+
@error = response.body
|
25
13
|
end
|
26
|
-
|
27
|
-
def backtrace
|
28
|
-
@wrapped_exception.respond_to?(:backtrace) ? @wrapped_exception.backtrace : super
|
29
|
-
end
|
30
|
-
|
31
14
|
end
|
32
15
|
end
|
data/lib/allplayers/request.rb
CHANGED
@@ -28,6 +28,9 @@ module AllPlayers
|
|
28
28
|
string_uri = uri.to_s
|
29
29
|
string_uri = string_uri + '?' + query_params
|
30
30
|
headers.merge!(@headers) unless @headers.empty?
|
31
|
+
if headers[:Content_Type] == 'application/json'
|
32
|
+
payload = payload.to_json
|
33
|
+
end
|
31
34
|
|
32
35
|
# Use access_token if this is oauth authentication.
|
33
36
|
unless @access_token.nil?
|
@@ -38,22 +41,18 @@ module AllPlayers
|
|
38
41
|
end
|
39
42
|
return JSON.parse(response.body) if response.code == '200'
|
40
43
|
return 'No Content' if response.code == '204'
|
41
|
-
|
42
|
-
|
43
|
-
# Use RestClient if using basic auth.
|
44
|
-
if [:patch, :post, :put].include? verb
|
45
|
-
response = RestClient.send(verb, uri.to_s, payload, headers)
|
44
|
+
raise AllPlayers::Error.new(response), 'Oauth Error'
|
46
45
|
else
|
47
|
-
|
46
|
+
# Use RestClient if using basic auth.
|
47
|
+
if [:patch, :post, :put].include? verb
|
48
|
+
response = RestClient.send(verb, uri.to_s, payload, headers)
|
49
|
+
else
|
50
|
+
response = RestClient.send(verb, string_uri, headers)
|
51
|
+
end
|
52
|
+
return JSON.parse(response) if response.code == 200
|
48
53
|
end
|
49
|
-
return JSON.parse(response) if response.code == 200
|
50
54
|
return 'No Content' if response.code == 204
|
51
|
-
|
52
|
-
raise AllPlayers::Error::ClientError
|
53
|
-
rescue JSON::ParserError
|
54
|
-
raise AllPlayers::Error::DecodeError
|
55
|
-
rescue Exception
|
56
|
-
raise AllPlayers::Error::ClientError
|
55
|
+
raise AllPlayers::Error.new(response), 'RestClient Error'
|
57
56
|
end
|
58
57
|
end
|
59
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: allplayers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
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: 2014-
|
12
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|