usman 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62800b6f073efd50739af97e19089839e9356b0d
4
- data.tar.gz: 8aa69a51f5b800ae068f22a60fbc4d169a584913
3
+ metadata.gz: d22e2e3562f38ea5576027b67f5d2c82a9c36f39
4
+ data.tar.gz: c858c47f7b5e81396f5f0dfc887283f9e54cee8d
5
5
  SHA512:
6
- metadata.gz: 6bda771ec286d380b5d87f8661b559dc15c37d6b86b3b5ba3c9b3189f4acf5b19f95fff9179ee462efdaac5d84d57eddb01c4f9fb707bca372ee685fbb4e17b3
7
- data.tar.gz: c0f413d6bdadf9439fb047ba9b36a9cf26a432eb5f358d3d9738759a8a17ba6d47ab7289ca3a0ab35d9b4d2b0557536b706ecff74a5e63ca0c41acdac71390f9
6
+ metadata.gz: 4f832c806ddedb96aed37fcb2e80e29d48277ff36bb5c77f297493f9bf2d2dc3205cd0a28ea0f201cc28650c9192d1c487e0ca614b7713755a0c37638e976b33
7
+ data.tar.gz: abc03809d152fe4275f6741b2680fec4ea63087980d87473e6aca4c58a4547d9a110ed8e810c8644697f81db02beca0a89d9523766d310b1ca910e9d4357d8d5
@@ -144,7 +144,7 @@ module Usman
144
144
  }
145
145
 
146
146
  @example_path = "usman/api/v1/docs/"#
147
- @examples = ["pos_case_1", "neg_case_1", "neg_case_2", "neg_case_3"]
147
+ @examples = ["pos_case_1", "pos_case_2", "pos_case_3", "neg_case_1", "neg_case_2", "neg_case_3"]
148
148
 
149
149
  set_nav("docs/create_profile")
150
150
 
@@ -172,7 +172,7 @@ module Usman
172
172
  }
173
173
 
174
174
  @example_path = "usman/api/v1/docs/"#
175
- @examples = ["pos_case_1", "neg_case_1", "neg_case_2", "neg_case_3"]
175
+ @examples = ["pos_case_1", "pos_case_2", "pos_case_3", "neg_case_1", "neg_case_2", "neg_case_3"]
176
176
 
177
177
  set_nav("docs/update_profile")
178
178
 
@@ -3,6 +3,8 @@ module Usman
3
3
  module V1
4
4
  class ProfileController < Usman::Api::V1::BaseController
5
5
 
6
+ include ImageUploaderHelper
7
+
6
8
  def create_profile
7
9
  proc_code = Proc.new do
8
10
  if @current_registration
@@ -33,6 +35,31 @@ module Usman
33
35
 
34
36
  @current_registration.save
35
37
 
38
+ # Saving the profile image if passed
39
+ begin
40
+ if params[:image] && !params[:image].blank?
41
+ user_image = @user.profile_picture || Image::ProfilePicture.new(imageable: @user)
42
+ user_image.image = params[:image]
43
+ user_image.valid?
44
+ if user_image.errors.any?
45
+ @errors = {
46
+ heading: I18n.translate("api.profile_picture.image_save_failed.heading"),
47
+ message: I18n.translate("api.profile_picture.image_save_failed.message"),
48
+ details: user_image.errors.full_messages
49
+ }
50
+ else
51
+ user_image.save
52
+ @user.reload
53
+ end
54
+ end
55
+ rescue
56
+ @errors = {
57
+ heading: I18n.translate("api.profile_picture.image_save_failed.heading"),
58
+ message: I18n.translate("api.profile_picture.image_save_failed.message"),
59
+ details: user_image.errors.full_messages
60
+ }
61
+ end
62
+
36
63
  @current_user = @user
37
64
  @success = true
38
65
  @alert = {
@@ -87,6 +114,31 @@ module Usman
87
114
 
88
115
  @current_registration.save
89
116
 
117
+ # Saving the profile image if passed
118
+ begin
119
+ if params[:image] && !params[:image].blank?
120
+ user_image = @user.profile_picture || Image::ProfilePicture.new(imageable: @user)
121
+ user_image.image = params[:image]
122
+ user_image.valid?
123
+ if user_image.errors.any?
124
+ @errors = {
125
+ heading: I18n.translate("api.profile_picture.image_save_failed.heading"),
126
+ message: I18n.translate("api.profile_picture.image_save_failed.message"),
127
+ details: user_image.errors.full_messages
128
+ }
129
+ else
130
+ user_image.save
131
+ @user.reload
132
+ end
133
+ end
134
+ rescue
135
+ @errors = {
136
+ heading: I18n.translate("api.profile_picture.image_save_failed.heading"),
137
+ message: I18n.translate("api.profile_picture.image_save_failed.message"),
138
+ details: user_image.errors.full_messages
139
+ }
140
+ end
141
+
90
142
  @success = true
91
143
  @alert = {
92
144
  heading: I18n.translate("api.profile.profile_created.heading"),
@@ -15,6 +15,8 @@ POST #{request.base_url}/api/v1/create_profile
15
15
  "country_id": "1",
16
16
  "city_id": "2"
17
17
  }
18
+
19
+ It create a new user/profile entry in the system and will return its data including the user_id (also called profile_id)
18
20
  eos
19
21
 
20
22
  api_output = <<-eos
@@ -31,15 +33,9 @@ api_output = <<-eos
31
33
  "date_of_birth": "1984-10-27",
32
34
  "username": "d0dca578",
33
35
  "email": "nayan.tara@yopmail.com",
34
- "phone": null
35
- "profile_picture":
36
- {
37
- "id": 1,
38
- "created_at": "22-09-2017 07:32:51",
39
- "user_id": 1,
40
- "image_large_path": "/uploads/profile_pictures/1/large_test.jpeg",
41
- "image_small_path": "/uploads/profile_pictures/1/small_test.jpeg"}}
42
- }
36
+ "phone": ,
37
+ "profile_picture":""
38
+ }
43
39
  }
44
40
  eos
45
41
 
@@ -0,0 +1,59 @@
1
+ <%
2
+
3
+ api_title = "Positive Case - 2 - should create the profile and save a profile picture"
4
+
5
+ api_input = <<-eos
6
+ Example:
7
+
8
+ Authorization: Token token="87b01adbba90824b57add8cc06ad8738"
9
+ POST #{request.base_url}/api/v1/create_profile
10
+ {
11
+ "name": "Name",
12
+ "gender": "male",
13
+ "date_of_birth": "10/10/1980",
14
+ "email": "name@domain.com",
15
+ "country_id": "1",
16
+ "city_id": "2",
17
+ "image": "<Uploaded File in Binary Format>"
18
+ }
19
+
20
+ It create a new user/profile entry in the system and will return its data including the user_id (also called profile_id)
21
+ It will also save the profile picture (A user/profile can have only one profile picture at a time)
22
+ eos
23
+
24
+ api_output = <<-eos
25
+ {
26
+ "success": true,
27
+ "alert": {
28
+ "heading": "The Profile has been created successfully",
29
+ "message": "You may access the profile API with API token to get the profile details in future"
30
+ },
31
+ "data": {
32
+ "id": 9,
33
+ "name": "Nayan Tara",
34
+ "gender": "female",
35
+ "date_of_birth": "1984-10-27",
36
+ "username": "d0dca578",
37
+ "email": "nayan.tara@yopmail.com",
38
+ "phone": null
39
+ "profile_picture":
40
+ {
41
+ "id": 1,
42
+ "created_at": "22-09-2017 07:32:51",
43
+ "user_id": 1,
44
+ "image_large_path": "/uploads/profile_pictures/1/large_test.jpeg",
45
+ "image_small_path": "/uploads/profile_pictures/1/small_test.jpeg"
46
+ }
47
+ }
48
+ }
49
+ eos
50
+
51
+ %>
52
+
53
+ <%= render partial: "kuppayam/api/docs/example", locals: {
54
+ negative_case: false,
55
+ example_id: "pos_case_2",
56
+ api_title: api_title,
57
+ api_input: api_input,
58
+ api_output: api_output
59
+ } %>
@@ -0,0 +1,56 @@
1
+ <%
2
+
3
+ api_title = "Positive Case - 3 - should create the profile even if profile picture is invalid"
4
+
5
+ api_input = <<-eos
6
+ Example:
7
+
8
+ Authorization: Token token="87b01adbba90824b57add8cc06ad8738"
9
+ POST #{request.base_url}/api/v1/create_profile
10
+ {
11
+ "name": "Name",
12
+ "gender": "male",
13
+ "date_of_birth": "10/10/1980",
14
+ "email": "name@domain.com",
15
+ "country_id": "1",
16
+ "city_id": "2",
17
+ "image": "<Uploaded File - Not Support. e.g: CSV>"
18
+ }
19
+
20
+ It create a new user/profile entry in the system and will return its data including the user_id (also called profile_id)
21
+ Since the uploaded image is not of supported type, it is ignored and the profile data is updated.
22
+ eos
23
+
24
+ api_output = <<-eos
25
+ {
26
+ "success": true,
27
+ "alert": {
28
+ "heading": "The Profile has been created successfully",
29
+ "message": "You may access the profile API with API token to get the profile details in future"
30
+ },
31
+ "errors": {
32
+ "heading": "Saving user/profile image was failed",
33
+ "message": "Make sure that the arguments are passed according to the API documentation. Please check the API Documentation for more details."
34
+ },
35
+ "data": {
36
+ "id": 9,
37
+ "name": "Nayan Tara",
38
+ "gender": "female",
39
+ "date_of_birth": "1984-10-27",
40
+ "username": "d0dca578",
41
+ "email": "nayan.tara@yopmail.com",
42
+ "phone": null,
43
+ "profile_picture": ""
44
+ }
45
+ }
46
+ eos
47
+
48
+ %>
49
+
50
+ <%= render partial: "kuppayam/api/docs/example", locals: {
51
+ negative_case: false,
52
+ example_id: "pos_case_3",
53
+ api_title: api_title,
54
+ api_input: api_input,
55
+ api_output: api_output
56
+ } %>
@@ -15,6 +15,8 @@ PUT #{request.base_url}/api/v1/update_profile
15
15
  "country_id": "1",
16
16
  "city_id": "2"
17
17
  }
18
+
19
+ It update the new user/profile entry in the system and will return its data including the user_id (also called profile_id)
18
20
  eos
19
21
 
20
22
  api_output = <<-eos
@@ -0,0 +1,59 @@
1
+ <%
2
+
3
+ api_title = "Positive Case - 2 - should update the profile and save a profile picture"
4
+
5
+ api_input = <<-eos
6
+ Example:
7
+
8
+ Authorization: Token token="87b01adbba90824b57add8cc06ad8738"
9
+ PUT #{request.base_url}/api/v1/update_profile
10
+ {
11
+ "name": "Name",
12
+ "gender": "male",
13
+ "date_of_birth": "10/10/1980",
14
+ "email": "name@domain.com",
15
+ "country_id": "1",
16
+ "city_id": "2",
17
+ "image": "<Uploaded File in Binary Format>"
18
+ }
19
+
20
+ It update the user/profile entry in the system and will return its data including the user_id (also called profile_id)
21
+ It will also save the profile picture (A user/profile can have only one profile picture at a time and hence it may update the existing one if any)
22
+ eos
23
+
24
+ api_output = <<-eos
25
+ {
26
+ "success": true,
27
+ "alert": {
28
+ "heading": "The Profile has been updated successfully",
29
+ "message": "You may access the profile API with API token to get the profile details in future"
30
+ },
31
+ "data": {
32
+ "id": 9,
33
+ "name": "Nayan Tara",
34
+ "gender": "female",
35
+ "date_of_birth": "1984-10-27",
36
+ "username": "d0dca578",
37
+ "email": "nayan.tara@yopmail.com",
38
+ "phone": null,
39
+ "profile_picture":
40
+ {
41
+ "id": 1,
42
+ "created_at": "22-09-2017 07:32:51",
43
+ "user_id": 1,
44
+ "image_large_path": "/uploads/profile_pictures/1/large_test.jpeg",
45
+ "image_small_path": "/uploads/profile_pictures/1/small_test.jpeg"
46
+ }
47
+ }
48
+ }
49
+ eos
50
+
51
+ %>
52
+
53
+ <%= render partial: "kuppayam/api/docs/example", locals: {
54
+ negative_case: false,
55
+ example_id: "pos_case_2",
56
+ api_title: api_title,
57
+ api_input: api_input,
58
+ api_output: api_output
59
+ } %>
@@ -0,0 +1,56 @@
1
+ <%
2
+
3
+ api_title = "Positive Case - 3 - should set proper errors if the inputs are not correct"
4
+
5
+ api_input = <<-eos
6
+ Example:
7
+
8
+ Authorization: Token token="87b01adbba90824b57add8cc06ad8738"
9
+ PUT #{request.base_url}/api/v1/update_profile
10
+ {
11
+ "name": "Name",
12
+ "gender": "male",
13
+ "date_of_birth": "10/10/1980",
14
+ "email": "name@domain.com",
15
+ "country_id": "1",
16
+ "city_id": "2",
17
+ "image": "<Uploaded File - Not Support. e.g: CSV>"
18
+ }
19
+
20
+ It update the user/profile entry in the system and will return its data including the user_id (also called profile_id)
21
+ Since the uploaded image is not of supported type, it is ignored and the profile data is updated.
22
+ eos
23
+
24
+ api_output = <<-eos
25
+ {
26
+ "success": true,
27
+ "alert": {
28
+ "heading": "The Profile has been updated successfully",
29
+ "message": "You may access the profile API with API token to get the profile details in future"
30
+ },
31
+ "errors": {
32
+ "heading": "Saving user/profile image was failed",
33
+ "message": "Make sure that the arguments are passed according to the API documentation. Please check the API Documentation for more details."
34
+ },
35
+ "data": {
36
+ "id": 9,
37
+ "name": "Nayan Tara",
38
+ "gender": "female",
39
+ "date_of_birth": "1984-10-27",
40
+ "username": "d0dca578",
41
+ "email": "nayan.tara@yopmail.com",
42
+ "phone": null,
43
+ "profile_picture": ""
44
+ }
45
+ }
46
+ eos
47
+
48
+ %>
49
+
50
+ <%= render partial: "kuppayam/api/docs/example", locals: {
51
+ negative_case: false,
52
+ example_id: "pos_case_3",
53
+ api_title: api_title,
54
+ api_input: api_input,
55
+ api_output: api_output
56
+ } %>
data/lib/usman/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Usman
2
- VERSION = '0.3.4'
2
+ VERSION = '0.3.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kpvarma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-25 00:00:00.000000000 Z
11
+ date: 2017-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -127,7 +127,7 @@ dependencies:
127
127
  version: '0.1'
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
- version: 0.1.10
130
+ version: 0.1.11
131
131
  type: :runtime
132
132
  prerelease: false
133
133
  version_requirements: !ruby/object:Gem::Requirement
@@ -137,7 +137,7 @@ dependencies:
137
137
  version: '0.1'
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
- version: 0.1.10
140
+ version: 0.1.11
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: bcrypt
143
143
  requirement: !ruby/object:Gem::Requirement
@@ -424,6 +424,8 @@ files:
424
424
  - app/views/usman/api/v1/docs/create_profile/_neg_case_2.html.erb
425
425
  - app/views/usman/api/v1/docs/create_profile/_neg_case_3.html.erb
426
426
  - app/views/usman/api/v1/docs/create_profile/_pos_case_1.html.erb
427
+ - app/views/usman/api/v1/docs/create_profile/_pos_case_2.html.erb
428
+ - app/views/usman/api/v1/docs/create_profile/_pos_case_3.html.erb
427
429
  - app/views/usman/api/v1/docs/delete_profile_picture/_neg_case_1.html.erb
428
430
  - app/views/usman/api/v1/docs/delete_profile_picture/_neg_case_2.html.erb
429
431
  - app/views/usman/api/v1/docs/delete_profile_picture/_pos_case_1.html.erb
@@ -446,6 +448,8 @@ files:
446
448
  - app/views/usman/api/v1/docs/update_profile/_neg_case_2.html.erb
447
449
  - app/views/usman/api/v1/docs/update_profile/_neg_case_3.html.erb
448
450
  - app/views/usman/api/v1/docs/update_profile/_pos_case_1.html.erb
451
+ - app/views/usman/api/v1/docs/update_profile/_pos_case_2.html.erb
452
+ - app/views/usman/api/v1/docs/update_profile/_pos_case_3.html.erb
449
453
  - app/views/usman/api/v1/docs/upload_profile_picture/_neg_case_1.html.erb
450
454
  - app/views/usman/api/v1/docs/upload_profile_picture/_neg_case_2.html.erb
451
455
  - app/views/usman/api/v1/docs/upload_profile_picture/_neg_case_3.html.erb