usman 0.2.11 → 0.3.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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/usman/api/v1/docs_controller.rb +84 -0
  3. data/app/controllers/usman/api/v1/profile_controller.rb +27 -2
  4. data/app/controllers/usman/api/v1/profile_picture_controller.rb +178 -0
  5. data/app/serializers/profile_picture_serializer.rb +19 -0
  6. data/app/serializers/profile_serializer.rb +6 -0
  7. data/app/uploaders/feature_image_uploader.rb +1 -0
  8. data/app/uploaders/profile_picture_uploader.rb +4 -0
  9. data/app/views/kuppayam/api/docs/_navigation.html.erb +24 -0
  10. data/app/views/usman/api/v1/docs/base64_profile_picture/_neg_case_1.html.erb +27 -0
  11. data/app/views/usman/api/v1/docs/base64_profile_picture/_neg_case_2.html.erb +28 -0
  12. data/app/views/usman/api/v1/docs/base64_profile_picture/_pos_case_1.html.erb +36 -0
  13. data/app/views/usman/api/v1/docs/create_profile/_pos_case_1.html.erb +15 -14
  14. data/app/views/usman/api/v1/docs/destroy_profile_picture/_neg_case_1.html.erb +27 -0
  15. data/app/views/usman/api/v1/docs/destroy_profile_picture/_neg_case_2.html.erb +27 -0
  16. data/app/views/usman/api/v1/docs/destroy_profile_picture/_pos_case_1.html.erb +27 -0
  17. data/app/views/usman/api/v1/docs/profile/_neg_case_1.html.erb +34 -0
  18. data/app/views/usman/api/v1/docs/profile/_neg_case_2.html.erb +27 -0
  19. data/app/views/usman/api/v1/docs/profile/_pos_case_1.html.erb +39 -0
  20. data/app/views/usman/api/v1/docs/profile_picture/_neg_case_1.html.erb +27 -0
  21. data/app/views/usman/api/v1/docs/profile_picture/_neg_case_2.html.erb +28 -0
  22. data/app/views/usman/api/v1/docs/profile_picture/_neg_case_3.html.erb +27 -0
  23. data/app/views/usman/api/v1/docs/profile_picture/_pos_case_1.html.erb +36 -0
  24. data/app/views/usman/api/v1/docs/update_profile/_neg_case_2.html.erb +3 -10
  25. data/app/views/usman/api/v1/docs/update_profile/_neg_case_3.html.erb +1 -1
  26. data/app/views/usman/api/v1/docs/update_profile/_pos_case_1.html.erb +7 -13
  27. data/app/views/usman/api/v1/docs/verify_otp/_pos_case_2.html.erb +2 -1
  28. data/config/locales/usman/api.en.yml +20 -1
  29. data/config/routes.rb +12 -0
  30. data/lib/usman/version.rb +1 -1
  31. metadata +65 -24
  32. data/app/uploaders/image_uploader.rb +0 -90
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b2112f5abecf2b7e9a3f96c68f96f1d10cce382
4
- data.tar.gz: 82b7fdf3aa9fda6dbff8b0af6fa7b4ae63959e4a
3
+ metadata.gz: da4ef048a641f75ac91c9ebcb697cd43c6f7fd9b
4
+ data.tar.gz: 53085820d81ef576b6b40b3a753d0d18fb40e039
5
5
  SHA512:
6
- metadata.gz: 9bcb588f538bee5cd3d386c49454f4969d39de1962f30fe240894e1a3761854d8fa7143827dc9db734a5ee5fce1c720b765a4fb4514798071d602be3440aca15
7
- data.tar.gz: 153befa09c258ef921cae756577f734d1380ed1759026ef3e30aec3e15b55a01dac73a42a4188ee0b9c4aa01f0aa5562a864818d99e1bf85c4cb092b8cd8fda8
6
+ metadata.gz: 1df87664bbe20cc17acf9814461719b98b4d74a2748faa9f3a0b9f0cc7cc20af53970c84043642310a87f797a1fb17c678d7738f2c018476c76212b3796a6aec
7
+ data.tar.gz: 1bb119d7386e8429368050aef3cf5c2463bc79a4b593546fc451ed110da28ee32f8d4ced1fb59dd990973d5c718198377cb4f08ac24c1dfae516061026be7a9e
@@ -161,6 +161,90 @@ module Usman
161
161
  render 'kuppayam/api/docs/show'
162
162
  end
163
163
 
164
+ def profile
165
+ set_title("Profile API")
166
+ @request_type = "GET"
167
+ @end_point = "/api/v1/profile/base64_profile_picture"
168
+ @description = "This API will return the details of the profile requested including image urls."
169
+
170
+ @input_headers = {
171
+ "Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " },
172
+ "Authorization" => { value: "Token token=\"87b01adbba90824b57add8cc06ad8738\"", description: "Put the API Token here. You shall get the API token after registering your device" }
173
+ }
174
+
175
+ @input_params = {}
176
+
177
+ @example_path = "usman/api/v1/docs/"
178
+ @examples = ["pos_case_1", "neg_case_1", "neg_case_2"]
179
+
180
+ set_nav("docs/profile")
181
+
182
+ render 'kuppayam/api/docs/show'
183
+ end
184
+
185
+ def base64_profile_picture
186
+ set_title("Upload Profile Picture API (base64)")
187
+ @request_type = "POST"
188
+ @end_point = "/api/v1/profile/base64_profile_picture"
189
+ @description = "This API will return the details of the profile requested including image urls."
190
+
191
+ @input_headers = {
192
+ "Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " },
193
+ "Authorization" => { value: "Token token=\"87b01adbba90824b57add8cc06ad8738\"", description: "Put the API Token here. You shall get the API token after registering your device" }
194
+ }
195
+
196
+ @input_params = {}
197
+
198
+ @example_path = "usman/api/v1/docs/"
199
+ @examples = ["pos_case_1", "neg_case_1", "neg_case_2"]
200
+
201
+ set_nav("docs/base64_profile_picture")
202
+
203
+ render 'kuppayam/api/docs/show'
204
+ end
205
+
206
+ def profile_picture
207
+ set_title("Upload Profile Picture API")
208
+ @request_type = "POST"
209
+ @end_point = "/api/v1/profile/profile_picture"
210
+ @description = "This API will return the details of the profile requested including image urls."
211
+
212
+ @input_headers = {
213
+ "Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " },
214
+ "Authorization" => { value: "Token token=\"87b01adbba90824b57add8cc06ad8738\"", description: "Put the API Token here. You shall get the API token after registering your device" }
215
+ }
216
+
217
+ @input_params = {}
218
+
219
+ @example_path = "usman/api/v1/docs/"
220
+ @examples = ["pos_case_1", "neg_case_1", "neg_case_2", "neg_case_3"]
221
+
222
+ set_nav("docs/profile_picture")
223
+
224
+ render 'kuppayam/api/docs/show'
225
+ end
226
+
227
+ def destroy_profile_picture
228
+ set_title("Delete Profile Picture API")
229
+ @request_type = "DELETE"
230
+ @end_point = "/api/v1/profile"
231
+ @description = "This API will return the details of the profile requested including image urls."
232
+
233
+ @input_headers = {
234
+ "Content-Type" => { value: "application/json", description: "The MIME media type for JSON text is application/json. This is to make sure that a valid json is returned. The default encoding is UTF-8. " },
235
+ "Authorization" => { value: "Token token=\"87b01adbba90824b57add8cc06ad8738\"", description: "Put the API Token here. You shall get the API token after registering your device" }
236
+ }
237
+
238
+ @input_params = {}
239
+
240
+ @example_path = "usman/api/v1/docs/"
241
+ @examples = ["pos_case_1", "neg_case_1", "neg_case_2", "neg_case_3"]
242
+
243
+ set_nav("docs/destroy_profile_picture")
244
+
245
+ render 'kuppayam/api/docs/show'
246
+ end
247
+
164
248
  end
165
249
  end
166
250
  end
@@ -38,7 +38,7 @@ module Usman
38
38
  heading: I18n.translate("api.profile.profile_created.heading"),
39
39
  message: I18n.translate("api.profile.profile_created.message")
40
40
  }
41
- @data = { user: @user }
41
+ @data = ActiveModelSerializers::SerializableResource.new(@user, serializer: ProfileSerializer)
42
42
  else
43
43
  @success = false
44
44
  @errors = {
@@ -91,7 +91,7 @@ module Usman
91
91
  heading: I18n.translate("api.profile.profile_created.heading"),
92
92
  message: I18n.translate("api.profile.profile_created.message")
93
93
  }
94
- @data = { user: @user }
94
+ @data = ActiveModelSerializers::SerializableResource.new(@user, serializer: ProfileSerializer)
95
95
  else
96
96
  @success = false
97
97
  @errors = {
@@ -112,6 +112,31 @@ module Usman
112
112
  render_json_response(proc_code)
113
113
  end
114
114
 
115
+ def profile
116
+ proc_code = Proc.new do
117
+ if @current_registration
118
+ unless @current_user
119
+ @success = false
120
+ @errors = {
121
+ heading: I18n.translate("api.profile.user_does_not_exists.heading"),
122
+ message: I18n.translate("api.profile.user_does_not_exists.message")
123
+ }
124
+ else
125
+ @current_user
126
+ @success = true
127
+ @data = ActiveModelSerializers::SerializableResource.new(@current_user, serializer: ProfileSerializer)
128
+ end
129
+ else
130
+ @success = false
131
+ @errors = {
132
+ heading: I18n.translate("api.profile.registration_details_missing.heading"),
133
+ message: I18n.translate("api.profile.registration_details_missing.message")
134
+ }
135
+ end
136
+ end
137
+ render_json_response(proc_code)
138
+ end
139
+
115
140
  private
116
141
 
117
142
  def permitted_params
@@ -0,0 +1,178 @@
1
+ module Usman
2
+ module Api
3
+ module V1
4
+ class ProfilePictureController < BaseController
5
+
6
+ include ImageUploaderHelper
7
+
8
+ def base64_profile_picture
9
+ proc_code = Proc.new do
10
+ if @current_registration
11
+ unless @current_user
12
+ @success = false
13
+ @errors = {
14
+ heading: I18n.translate("api.profile.user_does_not_exists.heading"),
15
+ message: I18n.translate("api.profile.user_does_not_exists.message")
16
+ }
17
+ else
18
+ user_image = @current_user.profile_picture || Image::ProfilePicture.new(imageable: @current_user)
19
+ begin
20
+ if params[:image] && !params[:image].blank?
21
+ user_image.image = image_params[:image_path]
22
+ user_image.valid?
23
+ if user_image.errors.any?
24
+ @success = false
25
+ @errors = {
26
+ heading: I18n.translate("api.profile_picture.image_save_failed.heading"),
27
+ message: I18n.translate("api.profile_picture.image_save_failed.message"),
28
+ details: user_image.errors.full_messages
29
+ }
30
+ else
31
+ @success = true
32
+ @alert = {
33
+ heading: I18n.translate("api.profile_picture.image_saved.heading"),
34
+ message: I18n.translate("api.profile_picture.image_saved.message")
35
+ }
36
+ @data = ActiveModelSerializers::SerializableResource.new(user_image, serializer: ProfilePictureSerializer)
37
+ user_image.save
38
+ end
39
+ else
40
+ @success = false
41
+ @errors = {
42
+ heading: I18n.translate("api.profile_picture.image_save_failed.heading"),
43
+ message: I18n.translate("api.profile_picture.image_save_failed.message"),
44
+ details: "Image can't be blank"
45
+ }
46
+ end
47
+ rescue Exception => e
48
+ @success = false
49
+ @errors = {
50
+ heading: I18n.translate("api.profile_picture.image_save_failed.heading"),
51
+ message: I18n.translate("api.profile_picture.image_save_failed.message"),
52
+ details: "Unable to parse the base64 image data"
53
+ }
54
+ end
55
+ end
56
+ else
57
+ @success = false
58
+ @errors = {
59
+ heading: I18n.translate("api.profile.registration_details_missing.heading"),
60
+ message: I18n.translate("api.profile.registration_details_missing.message")
61
+ }
62
+ end
63
+ end
64
+ render_json_response(proc_code)
65
+ end
66
+
67
+ def profile_picture
68
+ proc_code = Proc.new do
69
+ if @current_registration
70
+ unless @current_user
71
+ @success = false
72
+ @errors = {
73
+ heading: I18n.translate("api.profile.user_does_not_exists.heading"),
74
+ message: I18n.translate("api.profile.user_does_not_exists.message")
75
+ }
76
+ else
77
+ user_image = @current_user.profile_picture || Image::ProfilePicture.new(imageable: @current_user)
78
+ begin
79
+ if params[:image] && !params[:image].blank?
80
+ user_image.image = params[:image]
81
+ user_image.valid?
82
+ if user_image.errors.any?
83
+ @success = false
84
+ @errors = {
85
+ heading: I18n.translate("api.profile_picture.image_save_failed.heading"),
86
+ message: I18n.translate("api.profile_picture.image_save_failed.message"),
87
+ details: user_image.errors.full_messages
88
+ }
89
+ else
90
+ @success = true
91
+ @alert = {
92
+ heading: I18n.translate("api.profile_picture.image_saved.heading"),
93
+ message: I18n.translate("api.profile_picture.image_saved.message")
94
+ }
95
+ @data = ActiveModelSerializers::SerializableResource.new(user_image, serializer: ProfilePictureSerializer)
96
+ user_image.save
97
+ end
98
+ else
99
+ @success = false
100
+ @errors = {
101
+ heading: I18n.translate("api.profile_picture.image_save_failed.heading"),
102
+ message: I18n.translate("api.profile_picture.image_save_failed.message"),
103
+ details: "Image can't be blank"
104
+ }
105
+ end
106
+ rescue Exception => e
107
+ @success = false
108
+ @errors = {
109
+ heading: I18n.translate("api.profile_picture.image_save_failed.heading"),
110
+ message: I18n.translate("api.profile_picture.image_save_failed.message"),
111
+ details: "Unable to parse the base64 image data"
112
+ }
113
+ end
114
+ end
115
+ else
116
+ @success = false
117
+ @errors = {
118
+ heading: I18n.translate("api.profile.registration_details_missing.heading"),
119
+ message: I18n.translate("api.profile.registration_details_missing.message")
120
+ }
121
+ end
122
+ end
123
+ render_json_response(proc_code)
124
+ end
125
+
126
+ def destroy_profile_picture
127
+ proc_code = Proc.new do
128
+ if @current_registration
129
+ unless @current_user
130
+ @success = false
131
+ @errors = {
132
+ heading: I18n.translate("api.profile.user_does_not_exists.heading"),
133
+ message: I18n.translate("api.profile.user_does_not_exists.message")
134
+ }
135
+ else
136
+ user_image = @current_user.profile_picture
137
+ unless user_image
138
+ @success = false
139
+ @errors = {
140
+ heading: I18n.translate("api.profile_picture.profile_picture_does_not_exists.heading"),
141
+ message: I18n.translate("api.profile_picture.profile_picture_does_not_exists.message")
142
+ }
143
+ else
144
+ begin
145
+ @success = true
146
+ @alert = {
147
+ heading: I18n.translate("api.profile_picture.image_deleted.heading"),
148
+ message: I18n.translate("api.profile_picture.image_deleted.message")
149
+ }
150
+ user_image.destroy
151
+ rescue Exception => e
152
+ @success = false
153
+ @errors = {
154
+ heading: I18n.translate("api.profile_picture.image_delete_failed.heading"),
155
+ message: I18n.translate("api.profile_picture.image_delete_failed.message"),
156
+ details: "Unable to parse the base64 image data"
157
+ }
158
+ end
159
+ end
160
+ end
161
+ else
162
+ @success = false
163
+ @errors = {
164
+ heading: I18n.translate("api.profile.registration_details_missing.heading"),
165
+ message: I18n.translate("api.profile.registration_details_missing.message")
166
+ }
167
+ end
168
+ end
169
+ render_json_response(proc_code)
170
+ end
171
+
172
+ private
173
+
174
+ end
175
+ end
176
+ end
177
+ end
178
+
@@ -0,0 +1,19 @@
1
+ class ProfilePictureSerializer < ActiveModel::Serializer
2
+ include NullAttributeReplacer
3
+
4
+ attributes :id, :created_at, :profile_id
5
+ attributes :image_large_path, :image_small_path
6
+
7
+ def profile_id
8
+ object.imageable_id
9
+ end
10
+
11
+ def image_large_path
12
+ object.image_url :large
13
+ end
14
+
15
+ def image_small_path
16
+ object.image_url :small
17
+ end
18
+
19
+ end
@@ -0,0 +1,6 @@
1
+ class ProfileSerializer < ActiveModel::Serializer
2
+ include NullAttributeReplacer
3
+ attributes :id, :name, :gender, :date_of_birth, :username, :email, :phone
4
+
5
+ has_one :profile_picture, class_name: "Image::ProfilePicture", serializer: ProfilePictureSerializer
6
+ end
@@ -1,4 +1,5 @@
1
1
  class FeatureImageUploader < ImageUploader
2
+
2
3
  def store_dir
3
4
  "uploads/feature_images/#{model.id}"
4
5
  end
@@ -11,5 +11,9 @@ class ProfilePictureUploader < ImageUploader
11
11
  version :small do
12
12
  process :resize_to_fill => [100, 100]
13
13
  end
14
+
15
+ def default_url
16
+ 'default.png'
17
+ end
14
18
 
15
19
  end
@@ -35,6 +35,30 @@
35
35
  <span class="hidden-xs">Update Profile</span>
36
36
  </a>
37
37
  </li>
38
+ <li class="<%= nav_active?('docs/profile') ? 'active' : '' %>">
39
+ <a href="/docs/api/v1/profile">
40
+ <i class="fa-globe visible-xs"></i>
41
+ <span class="hidden-xs">Profile</span>
42
+ </a>
43
+ </li>
44
+ <li class="<%= nav_active?('docs/base64_profile_picture') ? 'active' : '' %>">
45
+ <a href="/docs/api/v1/base64_profile_picture">
46
+ <i class="fa-globe visible-xs"></i>
47
+ <span class="hidden-xs">Upload Profile Picture (Base64)</span>
48
+ </a>
49
+ </li>
50
+ <li class="<%= nav_active?('docs/profile_picture') ? 'active' : '' %>">
51
+ <a href="/docs/api/v1/profile_picture">
52
+ <i class="fa-globe visible-xs"></i>
53
+ <span class="hidden-xs">Upload Profile Picture</span>
54
+ </a>
55
+ </li>
56
+ <li class="<%= nav_active?('docs/destroy_profile_picture') ? 'active' : '' %>">
57
+ <a href="/docs/api/v1/destroy_profile_picture">
58
+ <i class="fa-globe visible-xs"></i>
59
+ <span class="hidden-xs">Delete Profile Picture</span>
60
+ </a>
61
+ </li>
38
62
  </ul>
39
63
 
40
64
  <style type="text/css">
@@ -0,0 +1,27 @@
1
+ <%
2
+
3
+ api_title = "Negative Case - 1 - should set proper errors if no api token"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": false,
12
+ "errors": {
13
+ "heading": "Invalid API Token",
14
+ "message": "Use the API Token you have received after accepting the terms and agreement"
15
+ }
16
+ }
17
+ eos
18
+
19
+ %>
20
+
21
+ <%= render partial: "kuppayam/api/docs/example", locals: {
22
+ negative_case: true,
23
+ example_id: "neg_case_1",
24
+ api_title: api_title,
25
+ api_input: api_input,
26
+ api_output: api_output
27
+ } %>
@@ -0,0 +1,28 @@
1
+ <%
2
+
3
+ api_title = "Negative Case - 1 - should respond with proper errors for invalid arguments"
4
+
5
+ api_input = <<-eos
6
+ {}
7
+ eos
8
+
9
+ api_output = <<-eos
10
+ {
11
+ "success": false,
12
+ "errors": {
13
+ "heading": "Saving user/profile image was failed",
14
+ "message": "Make sure that the arguments are passed according to the API documentation. Please check the API Documentation for more details.",
15
+ "details": "Image can't be blank"
16
+ }
17
+ }
18
+ eos
19
+
20
+ %>
21
+
22
+ <%= render partial: "kuppayam/api/docs/example", locals: {
23
+ negative_case: true,
24
+ example_id: "neg_case_2",
25
+ api_title: api_title,
26
+ api_input: api_input,
27
+ api_output: api_output
28
+ } %>