rails_api_response 1.1.0 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e3485708caa34322f2416eed7749890e004f44d
4
- data.tar.gz: 3fb33a780733351f370219949e5cfa7bd52f064d
3
+ metadata.gz: c6d9be4a0aaa2bf0b0e478d2936fddcc5630779c
4
+ data.tar.gz: 82144d92f08778ce572927128fe5e73e01ddadc0
5
5
  SHA512:
6
- metadata.gz: c40a93ef967a197e5bb44e5fe5567507439c0a89e72aed3e260074f1fdea928b3a891ecedcbd30bb7342177afe304a25c15a3fde027b4ec19818d68e9ff01392
7
- data.tar.gz: b495356b589b14e63ff0322756927c48fee8eb194523dfa1b58f788f71ef5d59c6dbe4fcda76bcaab86f064afe6f8b381bc31aa8363b0b3dbaafd5304023d396
6
+ metadata.gz: 10de55f39939989213d726cb1c88d86af60924b106b7dd0366a4b861444a4413cea0e2af8976b32058276e69c5029e5711124a4d2a97a8af8b40b28a8f37f9cc
7
+ data.tar.gz: 6ac818c31773010cea83b8f81c8964553c51dd42b97e1b1b80be8a270a78b5e1088e793d7c6d45c6f043bdab4cc9e25e3034c3856fe6657ec9fac93a320e0579
data/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_api_response`. To experiment with that code, run `bin/console` for an interactive prompt.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
@@ -22,7 +20,15 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ Add the line `include RailsApiResponse::ControllerHelpers::Responses` to the controller where you want to you response format. (Recommended: base or application controller).
24
+
25
+ Response success: `respond_success message: "Create user successfully", data: {}`.
26
+
27
+ Response error: `respond_error message: "Create user failed", data: {}` or `respond_error instance: @user, data: {}` (with instance param, the format will be got from errors and full message from instance.
28
+
29
+ Response with customer code: `respond_json code: 200, message: "", data: {}`.
30
+
31
+ The last format will be always `{ code: 200, metadata: { message: '' }, data: {} }`
26
32
 
27
33
  ## Development
28
34
 
@@ -12,6 +12,10 @@ module RailsApiResponse
12
12
  render json: ResponseTemplate.error(metadata, data)
13
13
  end
14
14
 
15
+ def respond_exception_error(exception:, data: {})
16
+ render json: ResponseTemplate.error(error_exception_metadata(exception), data)
17
+ end
18
+
15
19
  def respond_create_success(message: "", data: {})
16
20
  render json: ResponseTemplate.create_success(message_metadata(message), data)
17
21
  end
@@ -45,6 +49,14 @@ module RailsApiResponse
45
49
  }
46
50
  end
47
51
 
52
+ # Convert exception to metadata
53
+ def error_exception_metadata(exception)
54
+ {
55
+ message: exception.message,
56
+ error_details: exception.backtrace
57
+ }
58
+ end
59
+
48
60
  # Convert message text to error metadata
49
61
  def message_metadata(message)
50
62
  { message: message }
@@ -1,3 +1,3 @@
1
1
  module RailsApiResponse
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_api_response
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinh Chau
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-02 00:00:00.000000000 Z
11
+ date: 2016-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler