widgets_api_client 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/domain/application_config.rb +14 -0
- data/lib/domain/authentication.rb +29 -1
- data/lib/domain/client_info_base.rb +10 -0
- data/lib/domain/user.rb +28 -3
- data/lib/domain/user_base.rb +11 -1
- data/lib/domain/widget.rb +24 -0
- data/lib/domain/widget_base.rb +10 -1
- data/lib/services/authentication_service.rb +33 -0
- data/lib/services/user_service.rb +69 -0
- data/lib/services/user_widget_service.rb +39 -4
- data/lib/services/widget_service.rb +59 -2
- data/lib/widgets_api_client.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89008eec1366ab100f65284591ddc10556c3c02e749f707216f685c4d158b684
|
4
|
+
data.tar.gz: c63b702e0ec63aaaea1ecbfba0246c8e6fa4596215aaa0688de04739fde56bbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e56ce66a4ce67530241013ffaa3bf113993a0ca00e22dcbaec51ea2f41b4a0b332d75529e396ac492f4576856fd25fcd0046d24b2bf1266e65f269847b6ac0d
|
7
|
+
data.tar.gz: 58ae7f1cf56a66893ee2a48633a20229971ed76759e14468b86b2b9e0307295802501b7075d717aded517da6ee883cc38d62edf628fb511c1bbcac290475bdd1
|
data/Gemfile
CHANGED
@@ -1,16 +1,30 @@
|
|
1
|
+
#
|
2
|
+
# Sets Application Configurations
|
3
|
+
#
|
1
4
|
class ApplicationConfig
|
2
5
|
@@client_id = ''
|
3
6
|
@@client_secret = ''
|
7
|
+
@@base_url = ''
|
4
8
|
|
5
9
|
def self.set_config(client_id, client_secret)
|
6
10
|
@@client_id = client_id
|
7
11
|
@@client_secret = client_secret
|
8
12
|
end
|
9
13
|
|
14
|
+
#
|
15
|
+
# Return Client Id
|
16
|
+
#
|
17
|
+
# @return [String]
|
18
|
+
#
|
10
19
|
def self.client_id
|
11
20
|
@@client_id
|
12
21
|
end
|
13
22
|
|
23
|
+
#
|
24
|
+
# Returns Client Secret
|
25
|
+
#
|
26
|
+
# @return [String]
|
27
|
+
#
|
14
28
|
def self.client_secret
|
15
29
|
@@client_secret
|
16
30
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
+
#
|
4
|
+
# Authentication model conatining token generation attributes
|
5
|
+
#
|
3
6
|
class Authentication
|
4
7
|
attr_accessor :grant_type
|
5
8
|
attr_accessor :client_id
|
@@ -9,6 +12,17 @@ class Authentication
|
|
9
12
|
attr_accessor :token
|
10
13
|
attr_accessor :refresh_token
|
11
14
|
|
15
|
+
#
|
16
|
+
# Inialise the authentication model
|
17
|
+
#
|
18
|
+
# @param [String] grant_type Token grant type
|
19
|
+
# @param [String] client_id
|
20
|
+
# @param [String] client_secret
|
21
|
+
# @param [String] username
|
22
|
+
# @param [String] password
|
23
|
+
# @param [String] token Bearer token
|
24
|
+
# @param [String] refresh_token Refresh token
|
25
|
+
#
|
12
26
|
def initialize(grant_type: nil, client_id: nil, client_secret: nil,
|
13
27
|
username: nil, password: nil, token: nil, refresh_token: nil)
|
14
28
|
self.grant_type = grant_type
|
@@ -20,6 +34,13 @@ class Authentication
|
|
20
34
|
self.refresh_token = refresh_token
|
21
35
|
end
|
22
36
|
|
37
|
+
#
|
38
|
+
# Converts Authentication object to Json object
|
39
|
+
#
|
40
|
+
# @param [Refrence] *data authentication object refrence
|
41
|
+
#
|
42
|
+
# @return [Json] Json represenatation of authentication object
|
43
|
+
#
|
23
44
|
def to_json(*data)
|
24
45
|
hash = {
|
25
46
|
grant_type: @grant_type,
|
@@ -34,7 +55,14 @@ class Authentication
|
|
34
55
|
hash.to_json(*data)
|
35
56
|
end
|
36
57
|
|
37
|
-
|
58
|
+
#
|
59
|
+
# Gets Json represenatation of authentication object
|
60
|
+
#
|
61
|
+
# @param [Object] auth_data Authentication object
|
62
|
+
#
|
63
|
+
# @return [Json] Json represenatation of authentication object
|
64
|
+
#
|
65
|
+
def self.get_payload(auth_data)
|
38
66
|
auth_data.to_json
|
39
67
|
end
|
40
68
|
end
|
@@ -1,10 +1,20 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
+
#
|
4
|
+
# Client Base model conatining client information
|
5
|
+
#
|
3
6
|
class ClientInfoBase
|
4
7
|
attr_accessor :client_id
|
5
8
|
attr_accessor :client_secret
|
6
9
|
attr_accessor :user
|
7
10
|
|
11
|
+
#
|
12
|
+
# Converts User with client details object to Json object
|
13
|
+
#
|
14
|
+
# @param [refrence] *data User object with client details refrence
|
15
|
+
#
|
16
|
+
# @return [<Type>] Json represenatation of User with client details
|
17
|
+
#
|
8
18
|
def to_json(*data)
|
9
19
|
{
|
10
20
|
client_id: @client_id,
|
data/lib/domain/user.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
+
#
|
4
|
+
# User model conatining user create and update attributes
|
5
|
+
#
|
3
6
|
class User
|
4
7
|
attr_accessor :first_name
|
5
8
|
attr_accessor :last_name
|
@@ -10,6 +13,16 @@ class User
|
|
10
13
|
attr_accessor :email
|
11
14
|
attr_accessor :image_url
|
12
15
|
|
16
|
+
#
|
17
|
+
# Inialise the User model
|
18
|
+
#
|
19
|
+
# @param [String] first_name
|
20
|
+
# @param [String] last_name
|
21
|
+
# @param [String] password
|
22
|
+
# @param [String] date_of_birth
|
23
|
+
# @param [String] email
|
24
|
+
# @param [String] image_url
|
25
|
+
#
|
13
26
|
def initialize(first_name: nil, last_name: nil, password: nil,
|
14
27
|
date_of_birth: nil, email: nil, image_url: nil)
|
15
28
|
self.first_name = first_name
|
@@ -22,6 +35,13 @@ class User
|
|
22
35
|
self.image_url = image_url
|
23
36
|
end
|
24
37
|
|
38
|
+
#
|
39
|
+
# Converts User object to Json object
|
40
|
+
#
|
41
|
+
# @param [Refrence] *data user object refrence
|
42
|
+
#
|
43
|
+
# @return [Json] Json represenatation of user object
|
44
|
+
#
|
25
45
|
def to_json(*data)
|
26
46
|
hash = {
|
27
47
|
first_name: @first_name,
|
@@ -37,9 +57,14 @@ class User
|
|
37
57
|
hash.to_json(*data)
|
38
58
|
end
|
39
59
|
|
40
|
-
|
60
|
+
#
|
61
|
+
# Gets Json represenatation of user object
|
62
|
+
#
|
63
|
+
# @param [Object] user User object
|
64
|
+
#
|
65
|
+
# @return [Json] Json represenatation of user object
|
66
|
+
#
|
67
|
+
def self.get_payload(user)
|
41
68
|
user.to_json
|
42
69
|
end
|
43
70
|
end
|
44
|
-
|
45
|
-
|
data/lib/domain/user_base.rb
CHANGED
@@ -1,11 +1,21 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
+
#
|
4
|
+
# User Base class containing user object
|
5
|
+
#
|
3
6
|
class UserBase
|
4
7
|
attr_accessor :user
|
5
8
|
|
9
|
+
#
|
10
|
+
# Converts User object to Json object
|
11
|
+
#
|
12
|
+
# @param [Refrence] *data user object refrence
|
13
|
+
#
|
14
|
+
# @return [<Type>] Json represenatation of user object
|
15
|
+
#
|
6
16
|
def to_json(*data)
|
7
17
|
{
|
8
18
|
user: @user
|
9
19
|
}.to_json(*data)
|
10
20
|
end
|
11
|
-
|
21
|
+
end
|
data/lib/domain/widget.rb
CHANGED
@@ -1,16 +1,33 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
+
#
|
4
|
+
# Widget model conatining widget craeate and update attributes
|
5
|
+
#
|
3
6
|
class Widget
|
4
7
|
attr_accessor :name
|
5
8
|
attr_accessor :description
|
6
9
|
attr_accessor :kind
|
7
10
|
|
11
|
+
#
|
12
|
+
# Inialise the widget model
|
13
|
+
#
|
14
|
+
# @param [String] name Name of widget
|
15
|
+
# @param [String] description
|
16
|
+
# @param [String] kind Kind of widget - hidden/visible
|
17
|
+
#
|
8
18
|
def initialize(name: nil, description: nil, kind: nil)
|
9
19
|
self.name = name
|
10
20
|
self.description = description
|
11
21
|
self.kind = kind
|
12
22
|
end
|
13
23
|
|
24
|
+
#
|
25
|
+
# Converts Widget object to Json object
|
26
|
+
#
|
27
|
+
# @param [refrence] *data widget object refrence
|
28
|
+
#
|
29
|
+
# @return [<Type>] Json represenatation of widget object
|
30
|
+
#
|
14
31
|
def to_json(*data)
|
15
32
|
hash = {
|
16
33
|
name: @name,
|
@@ -21,6 +38,13 @@ class Widget
|
|
21
38
|
hash.to_json(*data)
|
22
39
|
end
|
23
40
|
|
41
|
+
#
|
42
|
+
# Gets Json represenatation of widget object
|
43
|
+
#
|
44
|
+
# @param [Object] widget Widget object
|
45
|
+
#
|
46
|
+
# @return [Json] Json represenatation of widget object
|
47
|
+
#
|
24
48
|
def self.get_payload(widget)
|
25
49
|
widget.to_json
|
26
50
|
end
|
data/lib/domain/widget_base.rb
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
+
#
|
4
|
+
# Widget Base class containing widget object
|
5
|
+
#
|
3
6
|
class WidgetBase
|
4
7
|
attr_accessor :widget
|
5
8
|
|
9
|
+
#
|
10
|
+
# Converts Widget object to Json object
|
11
|
+
#
|
12
|
+
# @param [Refrence] *data widget object refrence
|
13
|
+
#
|
14
|
+
# @return [Json] Json represenatation of widget object
|
15
|
+
#
|
6
16
|
def to_json(*data)
|
7
17
|
{
|
8
18
|
widget: @widget
|
9
19
|
}.to_json(*data)
|
10
20
|
end
|
11
|
-
|
12
21
|
end
|
@@ -3,10 +3,20 @@ require 'json'
|
|
3
3
|
require_relative '../domain/authentication.rb'
|
4
4
|
require_relative '../domain/application_config.rb'
|
5
5
|
|
6
|
+
#
|
7
|
+
# Authentication Service for token activies
|
8
|
+
#
|
6
9
|
class AuthenticationService
|
7
10
|
@@authentication_url = 'https://showoff-rails-react-production.herokuapp.com/oauth/token'
|
8
11
|
@@revoke_url = 'https://showoff-rails-react-production.herokuapp.com/oauth/revoke'
|
9
12
|
|
13
|
+
#
|
14
|
+
# Creates authentication token
|
15
|
+
#
|
16
|
+
# @param [object] auth_data Authentication object
|
17
|
+
#
|
18
|
+
# @return [Json] Response with brearer and refresh token
|
19
|
+
#
|
10
20
|
def self.create_authentication(auth_data)
|
11
21
|
auth_data = get_auth_with_client_info(auth_data)
|
12
22
|
auth_payload = Authentication.get_payload(auth_data)
|
@@ -16,6 +26,14 @@ class AuthenticationService
|
|
16
26
|
headers: { 'Content-Type': 'application/json' })
|
17
27
|
end
|
18
28
|
|
29
|
+
#
|
30
|
+
# Refresh authentication token
|
31
|
+
#
|
32
|
+
# @param [Object] auth_data Authentication object
|
33
|
+
# @param [String] bearer_token
|
34
|
+
#
|
35
|
+
# @return [Json] Response with brearer and refresh token
|
36
|
+
#
|
19
37
|
def self.refresh_authentication_token(auth_data, bearer_token)
|
20
38
|
auth_data = get_auth_with_client_info(auth_data)
|
21
39
|
auth_payload = Authentication.get_payload(auth_data)
|
@@ -26,6 +44,14 @@ class AuthenticationService
|
|
26
44
|
'Authorization': bearer_token })
|
27
45
|
end
|
28
46
|
|
47
|
+
#
|
48
|
+
# Revokes authentication token
|
49
|
+
#
|
50
|
+
# @param [Object] auth_data Authentication object
|
51
|
+
# @param [String] bearer_token
|
52
|
+
#
|
53
|
+
# @return [Json] Response with revoke message
|
54
|
+
#
|
29
55
|
def self.revoke_authentication_token(auth_data, bearer_token)
|
30
56
|
auth_payload = Authentication.get_payload(auth_data)
|
31
57
|
RestClient::Request.execute(method: :post,
|
@@ -35,6 +61,13 @@ class AuthenticationService
|
|
35
61
|
'Authorization': bearer_token })
|
36
62
|
end
|
37
63
|
|
64
|
+
#
|
65
|
+
# Sets Client id and secrets to Authentication object
|
66
|
+
#
|
67
|
+
# @param [Object] auth_data Authentication object
|
68
|
+
#
|
69
|
+
# @return [Object] Authentication object
|
70
|
+
#
|
38
71
|
def self.get_auth_with_client_info(auth_data)
|
39
72
|
auth_data.client_id = ApplicationConfig.client_id
|
40
73
|
auth_data.client_secret = ApplicationConfig.client_secret
|
@@ -5,6 +5,9 @@ require_relative '../domain/user.rb'
|
|
5
5
|
require_relative '../domain/user_base.rb'
|
6
6
|
require_relative '../domain/application_config.rb'
|
7
7
|
|
8
|
+
#
|
9
|
+
# User Service for CRUD operation related to user
|
10
|
+
#
|
8
11
|
class UserService
|
9
12
|
@@create_user_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users'
|
10
13
|
@@create_update_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/me'
|
@@ -14,6 +17,13 @@ class UserService
|
|
14
17
|
@@show_logged_in_user_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/me'
|
15
18
|
@@show_user_id_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/'
|
16
19
|
|
20
|
+
#
|
21
|
+
# Creates User
|
22
|
+
#
|
23
|
+
# @param [Object] user User Object for create
|
24
|
+
#
|
25
|
+
# @return [Json] Response of create user
|
26
|
+
#
|
17
27
|
def self.create_user(user)
|
18
28
|
user_with_client_info = get_user_with_client_info(user)
|
19
29
|
create_user_payload = User.get_payload(user_with_client_info)
|
@@ -23,6 +33,14 @@ class UserService
|
|
23
33
|
headers: { 'Content-Type': 'application/json' })
|
24
34
|
end
|
25
35
|
|
36
|
+
#
|
37
|
+
# Updates existing user
|
38
|
+
#
|
39
|
+
# @param [Object] user User Object for update
|
40
|
+
# @param [String] bearer_token
|
41
|
+
#
|
42
|
+
# @return [Json] Response of update user
|
43
|
+
#
|
26
44
|
def self.update_user(user, bearer_token)
|
27
45
|
user_data = get_user(user)
|
28
46
|
update_user_payload = User.get_payload(user_data)
|
@@ -33,6 +51,13 @@ class UserService
|
|
33
51
|
'Authorization': bearer_token })
|
34
52
|
end
|
35
53
|
|
54
|
+
#
|
55
|
+
# Verifies if email is already registered
|
56
|
+
#
|
57
|
+
# @param [Object] user user object conatining email
|
58
|
+
#
|
59
|
+
# @return [Json] Response of verify email
|
60
|
+
#
|
36
61
|
def self.check_email(user)
|
37
62
|
RestClient::Request.execute(method: :get,
|
38
63
|
url: @@check_email_url,
|
@@ -42,6 +67,13 @@ class UserService
|
|
42
67
|
client_secret: ApplicationConfig.client_secret } })
|
43
68
|
end
|
44
69
|
|
70
|
+
#
|
71
|
+
# Sends email with reset password link
|
72
|
+
#
|
73
|
+
# @param [Object] user User object
|
74
|
+
#
|
75
|
+
# @return [Json] Response of reset password
|
76
|
+
#
|
45
77
|
def self.reset_password(user)
|
46
78
|
user_with_client_info = get_user_with_client_info(user)
|
47
79
|
reset_password_payload = User.get_payload(user_with_client_info)
|
@@ -51,6 +83,14 @@ class UserService
|
|
51
83
|
headers: { 'Content-Type': 'application/json' })
|
52
84
|
end
|
53
85
|
|
86
|
+
#
|
87
|
+
# Updates old password to new password
|
88
|
+
#
|
89
|
+
# @param [Object] user User object with old and new password details
|
90
|
+
# @param [String] bearer_token
|
91
|
+
#
|
92
|
+
# @return [Json] Response of change password
|
93
|
+
#
|
54
94
|
def self.change_password(user, bearer_token)
|
55
95
|
user_data = get_user(user)
|
56
96
|
change_password_payload = User.get_payload(user_data)
|
@@ -61,6 +101,13 @@ class UserService
|
|
61
101
|
'Authorization': bearer_token })
|
62
102
|
end
|
63
103
|
|
104
|
+
#
|
105
|
+
# Displays logged in user details
|
106
|
+
#
|
107
|
+
# @param [String] bearer_token
|
108
|
+
#
|
109
|
+
# @return [Json] Response containing logged in user details
|
110
|
+
#
|
64
111
|
def self.show_logged_in_user(bearer_token)
|
65
112
|
RestClient::Request.execute(method: :get,
|
66
113
|
url: @@show_logged_in_user_url,
|
@@ -68,6 +115,14 @@ class UserService
|
|
68
115
|
'Authorization': bearer_token })
|
69
116
|
end
|
70
117
|
|
118
|
+
#
|
119
|
+
# Displays details of user id
|
120
|
+
#
|
121
|
+
# @param [String] user_id
|
122
|
+
# @param [String] bearer_token
|
123
|
+
#
|
124
|
+
# @return [Json] Response containing details of given user id
|
125
|
+
#
|
71
126
|
def self.show_user_id(user_id, bearer_token)
|
72
127
|
url_with_id = @@show_user_id_url + user_id.to_s
|
73
128
|
RestClient::Request.execute(method: :get,
|
@@ -76,6 +131,13 @@ class UserService
|
|
76
131
|
'Authorization': bearer_token })
|
77
132
|
end
|
78
133
|
|
134
|
+
#
|
135
|
+
# Sets Client information to user object
|
136
|
+
#
|
137
|
+
# @param [Object] user User Object
|
138
|
+
#
|
139
|
+
# @return [Object] User with client details
|
140
|
+
#
|
79
141
|
def self.get_user_with_client_info(user)
|
80
142
|
user_with_client_info = ClientInfoBase.new
|
81
143
|
user_with_client_info.client_id = ApplicationConfig.client_id
|
@@ -84,6 +146,13 @@ class UserService
|
|
84
146
|
user_with_client_info
|
85
147
|
end
|
86
148
|
|
149
|
+
#
|
150
|
+
# Sets Parent to User object
|
151
|
+
#
|
152
|
+
# @param [Object] user User Object
|
153
|
+
#
|
154
|
+
# @return [Object] User as child object
|
155
|
+
#
|
87
156
|
def self.get_user(user)
|
88
157
|
user_data = UserBase.new
|
89
158
|
user_data.user = user
|
@@ -2,11 +2,21 @@ require 'rest-client'
|
|
2
2
|
require 'json'
|
3
3
|
require_relative '../domain/application_config.rb'
|
4
4
|
|
5
|
+
#
|
6
|
+
# User Widget Service for widget display based on user details
|
7
|
+
#
|
5
8
|
class UserWidgetService
|
6
9
|
@@own_widgets_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/me/widgets'
|
7
10
|
@@widgets_by_user_id_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/'
|
8
11
|
|
9
|
-
|
12
|
+
#
|
13
|
+
# Displays own widgets
|
14
|
+
#
|
15
|
+
# @param [String] bearer_token
|
16
|
+
#
|
17
|
+
# @return [Json] Response containing list of own widgets
|
18
|
+
#
|
19
|
+
def self.get_private_widgets(bearer_token)
|
10
20
|
RestClient::Request.execute(method: :get,
|
11
21
|
url: @@own_widgets_url,
|
12
22
|
headers: { 'Content-Type': 'application/json',
|
@@ -15,7 +25,15 @@ class UserWidgetService
|
|
15
25
|
'Authorization': bearer_token })
|
16
26
|
end
|
17
27
|
|
18
|
-
|
28
|
+
#
|
29
|
+
# Displays own widget with search term
|
30
|
+
#
|
31
|
+
# @param [String] search_term
|
32
|
+
# @param [String] bearer_token
|
33
|
+
#
|
34
|
+
# @return [Json] Response containing list of own widget by search term
|
35
|
+
#
|
36
|
+
def self.get_private_widgets_with_search_term(search_term, bearer_token)
|
19
37
|
RestClient::Request.execute(method: :get,
|
20
38
|
url: @@own_widgets_url,
|
21
39
|
headers: { 'Content-Type': 'application/json',
|
@@ -25,7 +43,15 @@ class UserWidgetService
|
|
25
43
|
'Authorization': bearer_token })
|
26
44
|
end
|
27
45
|
|
28
|
-
|
46
|
+
#
|
47
|
+
# Displays widgets for given user id
|
48
|
+
#
|
49
|
+
# @param [String] user_id
|
50
|
+
# @param [String] bearer_token
|
51
|
+
#
|
52
|
+
# @return [Json] Resopnse containing widgets list for given user id
|
53
|
+
#
|
54
|
+
def self.get_widgets_by_user_id(user_id, bearer_token)
|
29
55
|
url_with_id = @@widgets_by_user_id_url + user_id.to_s + '/widgets'
|
30
56
|
RestClient::Request.execute(method: :get,
|
31
57
|
url: url_with_id,
|
@@ -35,7 +61,16 @@ class UserWidgetService
|
|
35
61
|
'Authorization': bearer_token })
|
36
62
|
end
|
37
63
|
|
38
|
-
|
64
|
+
#
|
65
|
+
# Displays widgets for given user id and serach term
|
66
|
+
#
|
67
|
+
# @param [String] user_id
|
68
|
+
# @param [String] search_term
|
69
|
+
# @param [String] bearer_token
|
70
|
+
#
|
71
|
+
# @return [Json] Response contating widget details for user id and serach term
|
72
|
+
#
|
73
|
+
def self.get_widgets_by_user_id_with_search_term(user_id, search_term, bearer_token)
|
39
74
|
url_with_id = @@widgets_by_user_id_url + user_id.to_s + '/widgets'
|
40
75
|
RestClient::Request.execute(method: :get,
|
41
76
|
url: url_with_id,
|
@@ -4,11 +4,22 @@ require_relative '../domain/widget_base.rb'
|
|
4
4
|
require_relative '../domain/widget.rb'
|
5
5
|
require_relative '../domain/application_config.rb'
|
6
6
|
|
7
|
+
#
|
8
|
+
# Widget Service for CRUD operation related to widget
|
9
|
+
#
|
7
10
|
class WidgetService
|
8
11
|
@@create_widget_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets'
|
9
12
|
@@update_destroy_widget_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets/'
|
10
13
|
@@list_widget_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets/visible'
|
11
14
|
|
15
|
+
#
|
16
|
+
# Creates Widget
|
17
|
+
#
|
18
|
+
# @param [Object] widget Widget object for create
|
19
|
+
# @param [String] bearer_token
|
20
|
+
#
|
21
|
+
# @return [Json] Response of create widget
|
22
|
+
#
|
12
23
|
def self.create_widget(widget, bearer_token)
|
13
24
|
widget_data = get_widget(widget)
|
14
25
|
create_widget_payload = Widget.get_payload(widget_data)
|
@@ -18,6 +29,15 @@ class WidgetService
|
|
18
29
|
'Authorization': bearer_token })
|
19
30
|
end
|
20
31
|
|
32
|
+
#
|
33
|
+
# Updates existing widget
|
34
|
+
#
|
35
|
+
# @param [Object] widget Widget object for update
|
36
|
+
# @param [String] widget_id widget to update
|
37
|
+
# @param [String] bearer_token
|
38
|
+
#
|
39
|
+
# @return [Json] Response of update widget
|
40
|
+
#
|
21
41
|
def self.update_widget(widget, widget_id, bearer_token)
|
22
42
|
update_url_with_widget_id = @@update_destroy_widget_url + widget_id.to_s
|
23
43
|
widget_data = get_widget(widget)
|
@@ -28,7 +48,15 @@ class WidgetService
|
|
28
48
|
'Authorization': bearer_token })
|
29
49
|
end
|
30
50
|
|
31
|
-
|
51
|
+
#
|
52
|
+
# Deletes own widget for given widget id
|
53
|
+
#
|
54
|
+
# @param [String] widget_id widgets to delete
|
55
|
+
# @param [String] bearer_token
|
56
|
+
#
|
57
|
+
# @return [Json] Response of delete widget
|
58
|
+
#
|
59
|
+
def self.delete_widget(widget_id, bearer_token)
|
32
60
|
destroy_url_with_widget_id = @@update_destroy_widget_url + widget_id.to_s
|
33
61
|
RestClient::Request.execute(method: :delete,
|
34
62
|
url: destroy_url_with_widget_id,
|
@@ -36,13 +64,27 @@ class WidgetService
|
|
36
64
|
'Authorization': bearer_token })
|
37
65
|
end
|
38
66
|
|
39
|
-
|
67
|
+
#
|
68
|
+
# Lists own widgets
|
69
|
+
#
|
70
|
+
# @param [String] bearer_token
|
71
|
+
#
|
72
|
+
# @return [String] Response with list of own widgets
|
73
|
+
#
|
74
|
+
def self.get_own_widgets(bearer_token)
|
40
75
|
RestClient::Request.execute(method: :get,
|
41
76
|
url: @@create_widget_url,
|
42
77
|
headers: { 'Content-Type': 'application/json',
|
43
78
|
'Authorization': bearer_token })
|
44
79
|
end
|
45
80
|
|
81
|
+
#
|
82
|
+
# Lists public widgets
|
83
|
+
#
|
84
|
+
# @param [String] bearer_token
|
85
|
+
#
|
86
|
+
# @return [Json] Response with list of public visible widgets
|
87
|
+
#
|
46
88
|
def self.get_public_widgets(bearer_token)
|
47
89
|
RestClient::Request.execute(method: :get,
|
48
90
|
url: @@list_widget_url,
|
@@ -52,6 +94,14 @@ class WidgetService
|
|
52
94
|
'Authorization': bearer_token })
|
53
95
|
end
|
54
96
|
|
97
|
+
#
|
98
|
+
# Lists public widgets with search term
|
99
|
+
#
|
100
|
+
# @param [String] search_term
|
101
|
+
# @param [String] bearer_token
|
102
|
+
#
|
103
|
+
# @return [Json] Response with searched public widgets by given search term
|
104
|
+
#
|
55
105
|
def self.get_public_widgets_with_search_term(search_term, bearer_token)
|
56
106
|
RestClient::Request.execute(method: :get,
|
57
107
|
url: @@list_widget_url,
|
@@ -62,6 +112,13 @@ class WidgetService
|
|
62
112
|
'Authorization': bearer_token })
|
63
113
|
end
|
64
114
|
|
115
|
+
#
|
116
|
+
# Sets Parent to Widget object
|
117
|
+
#
|
118
|
+
# @param [Object] widget Widget Object
|
119
|
+
#
|
120
|
+
# @return [Object] Widget as child object
|
121
|
+
#
|
65
122
|
def self.get_widget(widget)
|
66
123
|
widget_data = WidgetBase.new
|
67
124
|
widget_data.widget = widget
|
data/lib/widgets_api_client.rb
CHANGED
@@ -63,22 +63,22 @@ class WidgetsApiClient
|
|
63
63
|
|
64
64
|
# Get private widgets
|
65
65
|
def self.show_private_widgets(bearer_token)
|
66
|
-
UserWidgetService.
|
66
|
+
UserWidgetService.get_private_widgets(bearer_token)
|
67
67
|
end
|
68
68
|
|
69
69
|
# Get private widgets with search term
|
70
70
|
def self.show_private_widgets_with_search_term(search_term, bearer_token)
|
71
|
-
UserWidgetService.
|
71
|
+
UserWidgetService.get_private_widgets_with_search_term(search_term, bearer_token)
|
72
72
|
end
|
73
73
|
|
74
74
|
# Get widgets by user id
|
75
75
|
def self.show_widgets_by_user_id(user_id, bearer_token)
|
76
|
-
UserWidgetService.
|
76
|
+
UserWidgetService.get_widgets_by_user_id(user_id, bearer_token)
|
77
77
|
end
|
78
78
|
|
79
79
|
# Get widgets by user id with search term
|
80
80
|
def self.show_widgets_by_user_id_with_search_term(user_id, search_term, bearer_token)
|
81
|
-
UserWidgetService.
|
81
|
+
UserWidgetService.get_widgets_by_user_id_with_search_term(user_id, search_term, bearer_token)
|
82
82
|
end
|
83
83
|
|
84
84
|
# Create widget
|
@@ -93,12 +93,12 @@ class WidgetsApiClient
|
|
93
93
|
|
94
94
|
# Destroy widget
|
95
95
|
def self.destroy_widget(widget_id, bearer_token)
|
96
|
-
WidgetService.
|
96
|
+
WidgetService.delete_widget(widget_id, bearer_token)
|
97
97
|
end
|
98
98
|
|
99
99
|
# Get private widgets
|
100
100
|
def self.get_private_widgets(bearer_token)
|
101
|
-
WidgetService.
|
101
|
+
WidgetService.get_own_widgets(bearer_token)
|
102
102
|
end
|
103
103
|
|
104
104
|
# Get public widgets
|