widgets_api_client 0.0.4 → 0.0.6
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 +4 -0
- data/lib/domain/application_config.rb +14 -15
- data/lib/domain/authentication.rb +24 -30
- data/lib/domain/client_info_base.rb +11 -16
- data/lib/domain/user.rb +36 -42
- data/lib/domain/user_base.rb +7 -12
- data/lib/domain/widget.rb +15 -22
- data/lib/domain/widget_base.rb +8 -12
- data/lib/services/authentication_service.rb +36 -51
- data/lib/services/user_service.rb +74 -62
- data/lib/services/user_widget_service.rb +38 -26
- data/lib/services/widget_service.rb +62 -52
- data/lib/widgets_api_client.rb +103 -112
- 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: 185557368c2cfbe87f9e6e4bb2579c5dee0e7c5bb48a6d9edba51dc89cc15694
|
4
|
+
data.tar.gz: 705236b3894433070c9b3070e2694e50473350c19cc0fe400f3278a6f98d30ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acd93e65ba68890963a519adf72431d89f40cbf0ed13ae390696d2af5daee27cf027cf613f22313c9b0bdb5a69d60ff1e7eabb5bdd80585b5913772c6f3c7aac
|
7
|
+
data.tar.gz: 914cb67d36f9b14b83a29270e922c9beea68fed2d86a5c9e34efda1d155fac0e40587344b081b45c5efe1adacdfa0087deb17c4cda08c0702175e6c8c20a3507
|
data/Gemfile
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
class ApplicationConfig
|
2
|
-
|
3
|
-
|
2
|
+
@@client_id = ''
|
3
|
+
@@client_secret = ''
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def self.set_config(client_id, client_secret)
|
6
|
+
@@client_id = client_id
|
7
|
+
@@client_secret = client_secret
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
10
|
+
def self.client_id
|
11
|
+
@@client_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.client_secret
|
15
|
+
@@client_secret
|
16
|
+
end
|
17
|
+
end
|
@@ -1,21 +1,27 @@
|
|
1
1
|
require 'json'
|
2
|
+
|
2
3
|
class Authentication
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
attr_accessor :grant_type
|
5
|
+
attr_accessor :client_id
|
6
|
+
attr_accessor :client_secret
|
7
|
+
attr_accessor :username
|
8
|
+
attr_accessor :password
|
9
|
+
attr_accessor :token
|
10
|
+
attr_accessor :refresh_token
|
10
11
|
|
11
|
-
def initialize
|
12
|
-
|
13
|
-
grant_type
|
14
|
-
|
12
|
+
def initialize(grant_type: nil, client_id: nil, client_secret: nil,
|
13
|
+
username: nil, password: nil, token: nil, refresh_token: nil)
|
14
|
+
self.grant_type = grant_type
|
15
|
+
self.client_id = client_id
|
16
|
+
self.client_secret = client_secret
|
17
|
+
self.username = username
|
18
|
+
self.password = password
|
19
|
+
self.token = token
|
20
|
+
self.refresh_token = refresh_token
|
21
|
+
end
|
15
22
|
|
16
|
-
|
17
|
-
|
18
|
-
hash = {
|
23
|
+
def to_json(*data)
|
24
|
+
hash = {
|
19
25
|
grant_type: @grant_type,
|
20
26
|
client_id: @client_id,
|
21
27
|
client_secret: @client_secret,
|
@@ -24,23 +30,11 @@ class Authentication
|
|
24
30
|
token: @token,
|
25
31
|
refresh_token: @refresh_token
|
26
32
|
}
|
27
|
-
hash.delete_if { |k, v| v.nil? || v.empty?
|
28
|
-
hash.to_json(*
|
33
|
+
hash.delete_if { |k, v| v.nil? || v.empty? }
|
34
|
+
hash.to_json(*data)
|
29
35
|
end
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
b_from_json.grant_type = o['grant_type']
|
34
|
-
b_from_json.client_id = o['client_id']
|
35
|
-
b_from_json.client_secret = o['client_secret']
|
36
|
-
b_from_json.username = o['username']
|
37
|
-
b_from_json.password = o['password']
|
38
|
-
b_from_json.token = o['token']
|
39
|
-
b_from_json.refresh_token = o['refresh_token']
|
40
|
-
b_from_json
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.get_payload(auth_data)
|
44
|
-
return auth_data.to_json
|
37
|
+
def self.get_payload(auth_data)
|
38
|
+
auth_data.to_json
|
45
39
|
end
|
46
40
|
end
|
@@ -1,20 +1,15 @@
|
|
1
1
|
require 'json'
|
2
|
-
class ClientInfoBase
|
3
|
-
attr_accessor :client_id
|
4
|
-
attr_accessor :client_secret
|
5
|
-
attr_accessor :user
|
6
2
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
class ClientInfoBase
|
4
|
+
attr_accessor :client_id
|
5
|
+
attr_accessor :client_secret
|
6
|
+
attr_accessor :user
|
11
7
|
|
8
|
+
def to_json(*data)
|
9
|
+
{
|
10
|
+
client_id: @client_id,
|
11
|
+
client_secret: @client_secret,
|
12
|
+
user: @user
|
13
|
+
}.to_json(*data)
|
12
14
|
end
|
13
|
-
|
14
|
-
a_from_json = new
|
15
|
-
a_from_json.client_id = o['client_id']
|
16
|
-
a_from_json.client_secret = o['client_secret']
|
17
|
-
a_from_json.user = o['user']
|
18
|
-
a_from_json
|
19
|
-
end
|
20
|
-
end
|
15
|
+
end
|
data/lib/domain/user.rb
CHANGED
@@ -1,51 +1,45 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
class User
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
attr_accessor :first_name
|
5
|
+
attr_accessor :last_name
|
6
|
+
attr_accessor :password
|
7
|
+
attr_accessor :current_password
|
8
|
+
attr_accessor :new_password
|
9
|
+
attr_accessor :date_of_birth
|
10
|
+
attr_accessor :email
|
11
|
+
attr_accessor :image_url
|
12
12
|
|
13
|
-
def initialize
|
14
|
-
|
15
|
-
first_name
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
last_name: @last_name,
|
24
|
-
password: @password,
|
25
|
-
current_password: @current_password,
|
26
|
-
new_password: @new_password,
|
27
|
-
date_of_birth: @date_of_birth,
|
28
|
-
email: @email,
|
29
|
-
image_url: @image_url
|
30
|
-
}
|
31
|
-
hash.delete_if { |k, v| v.nil? }
|
32
|
-
hash.to_json(*a)
|
13
|
+
def initialize(first_name: nil, last_name: nil, password: nil,
|
14
|
+
date_of_birth: nil, email: nil, image_url: nil)
|
15
|
+
self.first_name = first_name
|
16
|
+
self.last_name = last_name
|
17
|
+
self.password = password
|
18
|
+
self.current_password = current_password
|
19
|
+
self.new_password = new_password
|
20
|
+
self.date_of_birth = date_of_birth
|
21
|
+
self.email = email
|
22
|
+
self.image_url = image_url
|
33
23
|
end
|
34
24
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
25
|
+
def to_json(*data)
|
26
|
+
hash = {
|
27
|
+
first_name: @first_name,
|
28
|
+
last_name: @last_name,
|
29
|
+
password: @password,
|
30
|
+
current_password: @current_password,
|
31
|
+
new_password: @new_password,
|
32
|
+
date_of_birth: @date_of_birth,
|
33
|
+
email: @email,
|
34
|
+
image_url: @image_url
|
35
|
+
}
|
36
|
+
hash.delete_if { |k, v| v.nil? }
|
37
|
+
hash.to_json(*data)
|
38
|
+
end
|
47
39
|
|
48
|
-
|
49
|
-
|
40
|
+
def self.get_payload(user)
|
41
|
+
user.to_json
|
50
42
|
end
|
51
43
|
end
|
44
|
+
|
45
|
+
|
data/lib/domain/user_base.rb
CHANGED
@@ -1,16 +1,11 @@
|
|
1
1
|
require 'json'
|
2
|
+
|
2
3
|
class UserBase
|
3
|
-
|
4
|
+
attr_accessor :user
|
4
5
|
|
5
|
-
def to_json(*
|
6
|
-
{
|
7
|
-
|
8
|
-
}.to_json(*
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.json_create(o)
|
12
|
-
a_from_json = new
|
13
|
-
a_from_json.user = o['user']
|
14
|
-
a_from_json
|
6
|
+
def to_json(*data)
|
7
|
+
{
|
8
|
+
user: @user
|
9
|
+
}.to_json(*data)
|
15
10
|
end
|
16
|
-
end
|
11
|
+
end
|
data/lib/domain/widget.rb
CHANGED
@@ -1,34 +1,27 @@
|
|
1
1
|
require 'json'
|
2
|
+
|
2
3
|
class Widget
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :description
|
6
|
+
attr_accessor :kind
|
6
7
|
|
7
|
-
def initialize
|
8
|
-
self.name
|
9
|
-
|
10
|
-
|
8
|
+
def initialize(name: nil, description: nil, kind: nil)
|
9
|
+
self.name = name
|
10
|
+
self.description = description
|
11
|
+
self.kind = kind
|
12
|
+
end
|
11
13
|
|
12
|
-
def to_json(*
|
13
|
-
hash = {
|
14
|
+
def to_json(*data)
|
15
|
+
hash = {
|
14
16
|
name: @name,
|
15
17
|
description: @description,
|
16
18
|
kind: @kind
|
17
19
|
}
|
18
|
-
hash.delete_if { |k, v| v.nil? || v.empty?
|
19
|
-
hash.to_json(*
|
20
|
+
hash.delete_if { |k, v| v.nil? || v.empty? }
|
21
|
+
hash.to_json(*data)
|
20
22
|
end
|
21
23
|
|
22
|
-
def self.json_create(o)
|
23
|
-
b_from_json = new
|
24
|
-
b_from_json.name = o['name']
|
25
|
-
b_from_json.description = o['description']
|
26
|
-
b_from_json.kind = o['kind']
|
27
|
-
b_from_json
|
28
|
-
end
|
29
|
-
|
30
24
|
def self.get_payload(widget)
|
31
|
-
|
25
|
+
widget.to_json
|
32
26
|
end
|
33
|
-
|
34
|
-
end
|
27
|
+
end
|
data/lib/domain/widget_base.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
require 'json'
|
2
|
+
|
2
3
|
class WidgetBase
|
3
|
-
|
4
|
+
attr_accessor :widget
|
4
5
|
|
5
|
-
def to_json(*
|
6
|
-
{
|
7
|
-
|
8
|
-
}.to_json(*
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.json_create(o)
|
12
|
-
a_from_json = new
|
13
|
-
a_from_json.widget = o['widget']
|
14
|
-
a_from_json
|
6
|
+
def to_json(*data)
|
7
|
+
{
|
8
|
+
widget: @widget
|
9
|
+
}.to_json(*data)
|
15
10
|
end
|
16
|
-
|
11
|
+
|
12
|
+
end
|
@@ -4,55 +4,40 @@ require_relative '../domain/authentication.rb'
|
|
4
4
|
require_relative '../domain/application_config.rb'
|
5
5
|
|
6
6
|
class AuthenticationService
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
auth.password = "password"
|
44
|
-
return auth
|
45
|
-
end
|
46
|
-
|
47
|
-
#remove once tested
|
48
|
-
def self.get_access_token
|
49
|
-
auth_data = AuthenticationService.create_auth_data
|
50
|
-
authJson = AuthenticationService.create_authentication(auth_data)
|
51
|
-
res_data = JSON.parse(authJson)
|
52
|
-
access_token = res_data['data']['token']['access_token']
|
53
|
-
return access_token
|
54
|
-
end
|
55
|
-
|
7
|
+
@@authentication_url = 'https://showoff-rails-react-production.herokuapp.com/oauth/token'
|
8
|
+
@@revoke_url = 'https://showoff-rails-react-production.herokuapp.com/oauth/revoke'
|
9
|
+
|
10
|
+
def self.create_authentication(auth_data)
|
11
|
+
auth_data = get_auth_with_client_info(auth_data)
|
12
|
+
auth_payload = Authentication.get_payload(auth_data)
|
13
|
+
RestClient::Request.execute(method: :post,
|
14
|
+
url: @@authentication_url,
|
15
|
+
payload: auth_payload,
|
16
|
+
headers: { 'Content-Type': 'application/json' })
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.refresh_authentication_token(auth_data, bearer_token)
|
20
|
+
auth_data = get_auth_with_client_info(auth_data)
|
21
|
+
auth_payload = Authentication.get_payload(auth_data)
|
22
|
+
RestClient::Request.execute(method: :post,
|
23
|
+
url: @@authentication_url,
|
24
|
+
payload: auth_payload,
|
25
|
+
headers: { 'Content-Type': 'application/json',
|
26
|
+
'Authorization': bearer_token })
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.revoke_authentication_token(auth_data, bearer_token)
|
30
|
+
auth_payload = Authentication.get_payload(auth_data)
|
31
|
+
RestClient::Request.execute(method: :post,
|
32
|
+
url: @@revoke_url,
|
33
|
+
payload: auth_payload,
|
34
|
+
headers: { 'Content-Type': 'application/json',
|
35
|
+
'Authorization': bearer_token })
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.get_auth_with_client_info(auth_data)
|
39
|
+
auth_data.client_id = ApplicationConfig.client_id
|
40
|
+
auth_data.client_secret = ApplicationConfig.client_secret
|
41
|
+
auth_data
|
42
|
+
end
|
56
43
|
end
|
57
|
-
|
58
|
-
|
@@ -5,76 +5,88 @@ 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
8
|
class UserService
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
@@create_user_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users'
|
10
|
+
@@create_update_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/me'
|
11
|
+
@@check_email_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/email'
|
12
|
+
@@reset_password_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/reset_password'
|
13
|
+
@@change_password_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/me/password'
|
14
|
+
@@show_logged_in_user_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/me'
|
15
|
+
@@show_user_id_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/'
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
def self.create_user(user)
|
18
|
+
user_with_client_info = get_user_with_client_info(user)
|
19
|
+
create_user_payload = User.get_payload(user_with_client_info)
|
20
|
+
RestClient::Request.execute(method: :post,
|
21
|
+
url: @@create_user_url,
|
22
|
+
payload: create_user_payload,
|
23
|
+
headers: { 'Content-Type': 'application/json' })
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
def self.update_user(user, bearer_token)
|
27
|
+
user_data = get_user(user)
|
28
|
+
update_user_payload = User.get_payload(user_data)
|
29
|
+
RestClient::Request.execute(method: :put,
|
30
|
+
url: @@create_update_url,
|
31
|
+
payload: update_user_payload,
|
32
|
+
headers: { 'Content-Type': 'application/json',
|
33
|
+
'Authorization': bearer_token })
|
34
|
+
end
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
def self.check_email(user)
|
37
|
+
RestClient::Request.execute(method: :get,
|
38
|
+
url: @@check_email_url,
|
39
|
+
headers: { 'Content-Type': 'application/json',
|
40
|
+
params: { email: user.email,
|
41
|
+
client_id: ApplicationConfig.client_id,
|
42
|
+
client_secret: ApplicationConfig.client_secret } })
|
43
|
+
end
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
+
def self.reset_password(user)
|
46
|
+
user_with_client_info = get_user_with_client_info(user)
|
47
|
+
reset_password_payload = User.get_payload(user_with_client_info)
|
48
|
+
RestClient::Request.execute(method: :post,
|
49
|
+
url: @@reset_password_url,
|
50
|
+
payload: reset_password_payload,
|
51
|
+
headers: { 'Content-Type': 'application/json' })
|
52
|
+
end
|
45
53
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
54
|
+
def self.change_password(user, bearer_token)
|
55
|
+
user_data = get_user(user)
|
56
|
+
change_password_payload = User.get_payload(user_data)
|
57
|
+
RestClient::Request.execute(method: :post,
|
58
|
+
url: @@change_password_url,
|
59
|
+
payload: change_password_payload,
|
60
|
+
headers: { 'Content-Type': 'application/json',
|
61
|
+
'Authorization': bearer_token })
|
62
|
+
end
|
53
63
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
64
|
+
def self.show_logged_in_user(bearer_token)
|
65
|
+
RestClient::Request.execute(method: :get,
|
66
|
+
url: @@show_logged_in_user_url,
|
67
|
+
headers: { 'Content-Type': 'application/json',
|
68
|
+
'Authorization': bearer_token })
|
69
|
+
end
|
58
70
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
71
|
+
def self.show_user_id(user_id, bearer_token)
|
72
|
+
url_with_id = @@show_user_id_url + user_id.to_s
|
73
|
+
RestClient::Request.execute(method: :get,
|
74
|
+
url: url_with_id,
|
75
|
+
headers: { 'Content-Type': 'application/json',
|
76
|
+
'Authorization': bearer_token })
|
77
|
+
end
|
64
78
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
def self.get_user(user)
|
74
|
-
user_data = UserBase.new
|
75
|
-
user_data.user = user
|
76
|
-
return user_data
|
77
|
-
end
|
79
|
+
def self.get_user_with_client_info(user)
|
80
|
+
user_with_client_info = ClientInfoBase.new
|
81
|
+
user_with_client_info.client_id = ApplicationConfig.client_id
|
82
|
+
user_with_client_info.client_secret = ApplicationConfig.client_secret
|
83
|
+
user_with_client_info.user = user
|
84
|
+
user_with_client_info
|
85
|
+
end
|
78
86
|
|
87
|
+
def self.get_user(user)
|
88
|
+
user_data = UserBase.new
|
89
|
+
user_data.user = user
|
90
|
+
user_data
|
91
|
+
end
|
79
92
|
end
|
80
|
-
|
@@ -3,34 +3,46 @@ require 'json'
|
|
3
3
|
require_relative '../domain/application_config.rb'
|
4
4
|
|
5
5
|
class UserWidgetService
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def self.get_private_widgets(bearer_token)
|
10
|
-
return RestClient::Request.execute(method: :get, url: @@own_widgets_url,
|
11
|
-
headers: {'Content-Type': 'application/json', params: {:client_id => ApplicationConfig.get_client_id, :client_secret => ApplicationConfig.get_client_secret},
|
12
|
-
'Authorization': bearer_token})
|
13
|
-
end
|
6
|
+
@@own_widgets_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/me/widgets'
|
7
|
+
@@widgets_by_user_id_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/'
|
14
8
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
def self.private_widgets(bearer_token)
|
10
|
+
RestClient::Request.execute(method: :get,
|
11
|
+
url: @@own_widgets_url,
|
12
|
+
headers: { 'Content-Type': 'application/json',
|
13
|
+
params: { client_id: ApplicationConfig.client_id,
|
14
|
+
client_secret: ApplicationConfig.client_secret },
|
15
|
+
'Authorization': bearer_token })
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
def self.private_widgets_with_search_term(search_term, bearer_token)
|
19
|
+
RestClient::Request.execute(method: :get,
|
20
|
+
url: @@own_widgets_url,
|
21
|
+
headers: { 'Content-Type': 'application/json',
|
22
|
+
params: { client_id: ApplicationConfig.client_id,
|
23
|
+
client_secret: ApplicationConfig.client_secret,
|
24
|
+
term: search_term },
|
25
|
+
'Authorization': bearer_token })
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
def self.widgets_by_user_id(user_id, bearer_token)
|
29
|
+
url_with_id = @@widgets_by_user_id_url + user_id.to_s + '/widgets'
|
30
|
+
RestClient::Request.execute(method: :get,
|
31
|
+
url: url_with_id,
|
32
|
+
headers: { 'Content-Type': 'application/json',
|
33
|
+
params: { client_id: ApplicationConfig.client_id,
|
34
|
+
client_secret: ApplicationConfig.client_secret },
|
35
|
+
'Authorization': bearer_token })
|
36
|
+
end
|
34
37
|
|
38
|
+
def self.widgets_by_user_id_with_search_term(user_id, search_term, bearer_token)
|
39
|
+
url_with_id = @@widgets_by_user_id_url + user_id.to_s + '/widgets'
|
40
|
+
RestClient::Request.execute(method: :get,
|
41
|
+
url: url_with_id,
|
42
|
+
headers: { 'Content-Type': 'application/json',
|
43
|
+
params: { client_id: ApplicationConfig.client_id,
|
44
|
+
client_secret: ApplicationConfig.client_secret,
|
45
|
+
term: search_term },
|
46
|
+
'Authorization': bearer_token })
|
47
|
+
end
|
35
48
|
end
|
36
|
-
|
@@ -5,56 +5,66 @@ require_relative '../domain/widget.rb'
|
|
5
5
|
require_relative '../domain/application_config.rb'
|
6
6
|
|
7
7
|
class WidgetService
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
headers: {'Content-Type': 'application/json', 'Authorization': bearer_token})
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.get_public_widgets(bearer_token)
|
42
|
-
return RestClient::Request.execute(method: :get, url: @@list_widget_url,
|
43
|
-
headers: {'Content-Type': 'application/json', params: {:client_id => ApplicationConfig.get_client_id, :client_secret => ApplicationConfig.get_client_secret},
|
44
|
-
'Authorization': bearer_token})
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.get_public_widgets_with_search_term(search_term, bearer_token)
|
48
|
-
return RestClient::Request.execute(method: :get, url: @@list_widget_url,
|
49
|
-
headers: {'Content-Type': 'application/json', params: {:client_id => ApplicationConfig.get_client_id, :client_secret => ApplicationConfig.get_client_secret, :term => search_term},
|
50
|
-
'Authorization': bearer_token})
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.get_widget(widget)
|
54
|
-
widget_data = WidgetBase.new
|
55
|
-
widget_data.widget = widget
|
56
|
-
return widget_data
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
8
|
+
@@create_widget_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets'
|
9
|
+
@@update_destroy_widget_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets/'
|
10
|
+
@@list_widget_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets/visible'
|
11
|
+
|
12
|
+
def self.create_widget(widget, bearer_token)
|
13
|
+
widget_data = get_widget(widget)
|
14
|
+
create_widget_payload = Widget.get_payload(widget_data)
|
15
|
+
RestClient::Request.execute(method: :post, url: @@create_widget_url,
|
16
|
+
payload: create_widget_payload,
|
17
|
+
headers: { 'Content-Type': 'application/json',
|
18
|
+
'Authorization': bearer_token })
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.update_widget(widget, widget_id, bearer_token)
|
22
|
+
update_url_with_widget_id = @@update_destroy_widget_url + widget_id.to_s
|
23
|
+
widget_data = get_widget(widget)
|
24
|
+
update_widget_payload = Widget.get_payload(widget_data)
|
25
|
+
RestClient::Request.execute(method: :put, url: update_url_with_widget_id,
|
26
|
+
payload: update_widget_payload,
|
27
|
+
headers: { 'Content-Type': 'application/json',
|
28
|
+
'Authorization': bearer_token })
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.destroy_widget(widget_id, bearer_token)
|
32
|
+
destroy_url_with_widget_id = @@update_destroy_widget_url + widget_id.to_s
|
33
|
+
RestClient::Request.execute(method: :delete,
|
34
|
+
url: destroy_url_with_widget_id,
|
35
|
+
headers: { 'Content-Type': 'application/json',
|
36
|
+
'Authorization': bearer_token })
|
37
|
+
end
|
60
38
|
|
39
|
+
def self.get_private_widgets(bearer_token)
|
40
|
+
RestClient::Request.execute(method: :get,
|
41
|
+
url: @@create_widget_url,
|
42
|
+
headers: { 'Content-Type': 'application/json',
|
43
|
+
'Authorization': bearer_token })
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.get_public_widgets(bearer_token)
|
47
|
+
RestClient::Request.execute(method: :get,
|
48
|
+
url: @@list_widget_url,
|
49
|
+
headers: { 'Content-Type': 'application/json',
|
50
|
+
params: { client_id: ApplicationConfig.client_id,
|
51
|
+
client_secret: ApplicationConfig.client_secret },
|
52
|
+
'Authorization': bearer_token })
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.get_public_widgets_with_search_term(search_term, bearer_token)
|
56
|
+
RestClient::Request.execute(method: :get,
|
57
|
+
url: @@list_widget_url,
|
58
|
+
headers: { 'Content-Type': 'application/json',
|
59
|
+
params: { client_id: ApplicationConfig.client_id,
|
60
|
+
client_secret: ApplicationConfig.client_secret,
|
61
|
+
term: search_term },
|
62
|
+
'Authorization': bearer_token })
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.get_widget(widget)
|
66
|
+
widget_data = WidgetBase.new
|
67
|
+
widget_data.widget = widget
|
68
|
+
widget_data
|
69
|
+
end
|
70
|
+
end
|
data/lib/widgets_api_client.rb
CHANGED
@@ -7,116 +7,107 @@ require File.dirname(__FILE__) + '/services/user_widget_service'
|
|
7
7
|
require File.dirname(__FILE__) + '/domain/application_config'
|
8
8
|
|
9
9
|
class WidgetsApiClient
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
def self.get_public_widgets_with_search_term(search_term, bearer_token)
|
114
|
-
return WidgetService.get_public_widgets_with_search_term(search_term, bearer_token)
|
115
|
-
end
|
116
|
-
|
117
|
-
#Remove after tesing
|
118
|
-
def self.get_access_token
|
119
|
-
return ApplicationConfig.get_access_token
|
120
|
-
end
|
121
|
-
|
10
|
+
def self.set_config(client_id, client_secret)
|
11
|
+
ApplicationConfig.set_config(client_id, client_secret)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Create authentication token
|
15
|
+
def self.create_authentication_token(auth_data)
|
16
|
+
AuthenticationService.create_authentication(auth_data)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Refresh authentication token
|
20
|
+
def self.refresh_authentication_token(auth_data, bearer_token)
|
21
|
+
AuthenticationService.refresh_authentication_token(auth_data, bearer_token)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Revoke authentication token
|
25
|
+
def self.revoke_authentication_token(auth_data, bearer_token)
|
26
|
+
AuthenticationService.revoke_authentication_token(auth_data, bearer_token)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Create user
|
30
|
+
def self.create_user(user_data)
|
31
|
+
UserService.create_user(user_data)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Update user
|
35
|
+
def self.update_user(user_data, bearer_token)
|
36
|
+
UserService.update_user(user_data, bearer_token)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Check email
|
40
|
+
def self.check_email(user_data)
|
41
|
+
UserService.check_email(user_data)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Reset password
|
45
|
+
def self.reset_password(user_data)
|
46
|
+
UserService.reset_password(user_data)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Change password
|
50
|
+
def self.change_password(user_data, bearer_token)
|
51
|
+
UserService.change_password(user_data, bearer_token)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Show logged in user
|
55
|
+
def self.show_logged_in_user(bearer_token)
|
56
|
+
UserService.show_logged_in_user(bearer_token)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Show user id
|
60
|
+
def self.show_user_id(user_id, bearer_token)
|
61
|
+
UserService.show_user_id(user_id, bearer_token)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Get private widgets
|
65
|
+
def self.show_private_widgets(bearer_token)
|
66
|
+
UserWidgetService.private_widgets(bearer_token)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Get private widgets with search term
|
70
|
+
def self.show_private_widgets_with_search_term(search_term, bearer_token)
|
71
|
+
UserWidgetService.private_widgets_with_search_term(search_term, bearer_token)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Get widgets by user id
|
75
|
+
def self.show_widgets_by_user_id(user_id, bearer_token)
|
76
|
+
UserWidgetService.widgets_by_user_id(user_id, bearer_token)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Get widgets by user id with search term
|
80
|
+
def self.show_widgets_by_user_id_with_search_term(user_id, search_term, bearer_token)
|
81
|
+
UserWidgetService.widgets_by_user_id_with_search_term(user_id, search_term, bearer_token)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Create widget
|
85
|
+
def self.create_widget(widget_data, bearer_token)
|
86
|
+
WidgetService.create_widget(widget_data, bearer_token)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Update widget
|
90
|
+
def self.update_widget(widget_data, widget_id, bearer_token)
|
91
|
+
WidgetService.update_widget(widget_data, widget_id, bearer_token)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Destroy widget
|
95
|
+
def self.destroy_widget(widget_id, bearer_token)
|
96
|
+
WidgetService.destroy_widget(widget_id, bearer_token)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Get private widgets
|
100
|
+
def self.get_private_widgets(bearer_token)
|
101
|
+
WidgetService.get_private_widgets(bearer_token)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Get public widgets
|
105
|
+
def self.get_public_widgets(bearer_token)
|
106
|
+
WidgetService.get_public_widgets(bearer_token)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Get public widgets with serach term
|
110
|
+
def self.get_public_widgets_with_search_term(search_term, bearer_token)
|
111
|
+
WidgetService.get_public_widgets_with_search_term(search_term, bearer_token)
|
112
|
+
end
|
122
113
|
end
|