widgets_api_client 0.2.0.1 → 0.2.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '018faf4958b920d634bd273a30ad791a94c77dd3'
4
- data.tar.gz: 433c9831d21ef07f944f34f34e92479ed53e0ba9
3
+ metadata.gz: b8a33b70b243fa7d2421fb28b4cf5b2c774ce7d3
4
+ data.tar.gz: 218218f461ba3096a5e1445e53b24408033c41e8
5
5
  SHA512:
6
- metadata.gz: e160c6b1f5d31f24573439aec554fbf8a708374d813bbd9f240c874fcfdb59b69f8224d60c87bc5f0cbb70f9b8a23c5f9a2d7db57ddb84011145fa50cf924349
7
- data.tar.gz: 889de8c50d7304113778f01d7bcac87d3cca9d4e22f0eadd39b943a35bc8a2166d6d225222b833e59afd5dfec80313d002981cc1f5fe43391b67724f9e62c979
6
+ metadata.gz: 58153cf80012217ffefcac576d76a2ebabb4136199d91820e08797bdcafd8e31eed3aa4842b9ae3bb1acdb8995f0b46c49f4dc5301c5aaaeecddbac8e26e6e9c
7
+ data.tar.gz: 5bcab61761acf1bb84671b8a43fa6672e8da88771eb645e94be4e8991a16410382649b0d6697494ac8d597a81033e658a196d5951017cae9d3fe59c8f4d405c3
data/lib/domain/user.rb CHANGED
@@ -3,7 +3,7 @@ require 'json'
3
3
  #
4
4
  # User model conatining user create and update attributes
5
5
  #
6
- class User
6
+ class User
7
7
  attr_accessor :first_name
8
8
  attr_accessor :last_name
9
9
  attr_accessor :password
@@ -28,6 +28,7 @@ class User
28
28
  def initialize(first_name: nil, last_name: nil, password: nil,
29
29
  current_password: nil, new_password: nil,
30
30
  date_of_birth: nil, email: nil, image_url: nil)
31
+
31
32
  self.first_name = first_name
32
33
  self.last_name = last_name
33
34
  self.password = password
@@ -38,15 +39,9 @@ class User
38
39
  self.image_url = image_url
39
40
  end
40
41
 
41
- #
42
- # Converts User object to Json object
43
- #
44
- # @param [Refrence] *data user object refrence
45
- #
46
- # @return [Json] Json represenatation of user object
47
- #
48
- def to_json(*data)
49
- hash = {
42
+ def as_json(options={})
43
+ hash_data = {
44
+ self.class.name.downcase => {
50
45
  first_name: @first_name,
51
46
  last_name: @last_name,
52
47
  password: @password,
@@ -55,10 +50,12 @@ class User
55
50
  date_of_birth: @date_of_birth,
56
51
  email: @email,
57
52
  image_url: @image_url
58
- }
59
- hash.delete_if { |k, v| v.nil? }
60
- hash.to_json(*data)
61
- end
53
+ }
54
+ }
55
+
56
+ hash_data.each {|k,v| v.delete_if { |k, v| v.nil? || v.empty? }}
57
+ hash_data
58
+ end
62
59
 
63
60
  #
64
61
  # Gets Json represenatation of user object
@@ -68,6 +65,10 @@ class User
68
65
  # @return [Json] Json represenatation of user object
69
66
  #
70
67
  def self.get_payload(user)
71
- user.to_json
68
+ user.as_json.to_json
69
+ end
70
+
71
+ def self.get_payload_with_client_info(user)
72
+ user.as_json.merge({'client_id' => ApplicationConfig.client_id, 'client_secret' => ApplicationConfig.client_secret}).to_json
72
73
  end
73
74
  end
@@ -1,9 +1,7 @@
1
1
  require 'rest-client'
2
2
  require 'json'
3
3
  require_relative '../domain/application_config.rb'
4
- require_relative '../domain/client_info_base.rb'
5
4
  require_relative '../domain/user.rb'
6
- require_relative '../domain/user_base.rb'
7
5
 
8
6
  #
9
7
  # User Service for CRUD operation related to user
@@ -17,8 +15,8 @@ class UserService
17
15
  # @return [Json] Response of create user
18
16
  #
19
17
  def self.create_user(user)
20
- user_with_client_info = get_user_with_client_info(user)
21
- create_user_payload = User.get_payload(user_with_client_info)
18
+ create_user_payload = User.get_payload_with_client_info(user)
19
+ puts create_user_payload
22
20
  RestClient::Request.execute(method: :post,
23
21
  url: ApplicationConfig.get_url('create_user_path'),
24
22
  payload: create_user_payload,
@@ -34,8 +32,7 @@ class UserService
34
32
  # @return [Json] Response of update user
35
33
  #
36
34
  def self.update_user(user, bearer_token)
37
- user_data = get_user(user)
38
- update_user_payload = User.get_payload(user_data)
35
+ update_user_payload = User.get_payload(user)
39
36
  RestClient::Request.execute(method: :put,
40
37
  url: ApplicationConfig.get_url('update_user_path'),
41
38
  payload: update_user_payload,
@@ -67,8 +64,7 @@ class UserService
67
64
  # @return [Json] Response of reset password
68
65
  #
69
66
  def self.reset_password(user)
70
- user_with_client_info = get_user_with_client_info(user)
71
- reset_password_payload = User.get_payload(user_with_client_info)
67
+ reset_password_payload = User.get_payload_with_client_info(user)
72
68
  RestClient::Request.execute(method: :post,
73
69
  url: ApplicationConfig.get_url('reset_password_path'),
74
70
  payload: reset_password_payload,
@@ -84,8 +80,7 @@ class UserService
84
80
  # @return [Json] Response of change password
85
81
  #
86
82
  def self.change_password(user, bearer_token)
87
- user_data = get_user(user)
88
- change_password_payload = User.get_payload(user_data)
83
+ change_password_payload = User.get_payload(user)
89
84
  RestClient::Request.execute(method: :post,
90
85
  url: ApplicationConfig.get_url('change_password_path'),
91
86
  payload: change_password_payload,
@@ -122,32 +117,4 @@ class UserService
122
117
  headers: { 'Content-Type': 'application/json',
123
118
  'Authorization': bearer_token })
124
119
  end
125
-
126
- #
127
- # Sets Client information to user object
128
- #
129
- # @param [Object] user User Object
130
- #
131
- # @return [Object] User with client details
132
- #
133
- def self.get_user_with_client_info(user)
134
- user_with_client_info = ClientInfoBase.new
135
- user_with_client_info.client_id = ApplicationConfig.client_id
136
- user_with_client_info.client_secret = ApplicationConfig.client_secret
137
- user_with_client_info.user = user
138
- user_with_client_info
139
- end
140
-
141
- #
142
- # Sets Parent to User object
143
- #
144
- # @param [Object] user User Object
145
- #
146
- # @return [Object] User as child object
147
- #
148
- def self.get_user(user)
149
- user_data = UserBase.new
150
- user_data.user = user
151
- user_data
152
- end
153
120
  end
@@ -265,10 +265,3 @@ class WidgetsApiClient
265
265
  WidgetService.get_public_widgets_with_search_term(search_term, bearer_token)
266
266
  end
267
267
  end
268
-
269
- #WidgetsApiClient.set_config("a","b", "c")
270
- #widget = Widget.new
271
- #widget.name ='name'
272
- #widget.description ='desc'
273
- #widget.kind ='hidden'
274
- #WidgetsApiClient.create_widget(widget, "Bearer xxxxxxxxxxxxxxxxxxx")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: widgets_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.1
4
+ version: 0.2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sachin Murthy
@@ -35,9 +35,7 @@ files:
35
35
  - lib/config.yml
36
36
  - lib/domain/application_config.rb
37
37
  - lib/domain/authentication.rb
38
- - lib/domain/client_info_base.rb
39
38
  - lib/domain/user.rb
40
- - lib/domain/user_base.rb
41
39
  - lib/domain/widget.rb
42
40
  - lib/services/authentication_service.rb
43
41
  - lib/services/user_service.rb
@@ -1,25 +0,0 @@
1
- require 'json'
2
-
3
- #
4
- # Client Base model conatining client information
5
- #
6
- class ClientInfoBase
7
- attr_accessor :client_id
8
- attr_accessor :client_secret
9
- attr_accessor :user
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
- #
18
- def to_json(*data)
19
- {
20
- client_id: @client_id,
21
- client_secret: @client_secret,
22
- user: @user
23
- }.to_json(*data)
24
- end
25
- end
@@ -1,21 +0,0 @@
1
- require 'json'
2
-
3
- #
4
- # User Base class containing user object
5
- #
6
- class UserBase
7
- attr_accessor :user
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
- #
16
- def to_json(*data)
17
- {
18
- user: @user
19
- }.to_json(*data)
20
- end
21
- end