ctws 0.1.12.alpha → 0.1.13.alpha

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: 5be817a0afed3eba6a2644b0ca2e7f9d19a78f0b
4
- data.tar.gz: cc5d76993f3549ed7d3cf0441a1dcc7185c93d28
3
+ metadata.gz: 2f86a86cc1af9c424b2349bad827b752cce5ad87
4
+ data.tar.gz: 167ea2979b16ea75af0ba49790e30a69765ee58f
5
5
  SHA512:
6
- metadata.gz: 2d0ee407f5fd1ccfa1d689ad4238af538a1dffd444a70bb2e7d98c91f2f24a905426aea31b9eaab0eabbd2ba701b49f50e729615f08051fc374da55f97d7e94c
7
- data.tar.gz: c6907f7c9be5f43774dcf437c7a19e11bd1a942e5a38dc6e0cc2e8923e43e9aeb614e6e3c8413265d171a3a0e643271a96c4e376a404c440f298ef5d662d926c
6
+ metadata.gz: 78997a0717a48effc5370641eec6d86d16b0069c640d762e246dd2e4dbe6ff69729adbdfa2fde10b36f741defc9f1caf884aeafce351d3655aec9794afcc05bd
7
+ data.tar.gz: af4cf13d78a02772d22c650841d7dab03e9b342df78b2cdc52a3a48d4894594a5b9aea2d331b6d35bc3a642b661ffd40f13d90fe7642ea0fcc5ec9f38e541f17
data/README.md CHANGED
@@ -36,13 +36,13 @@ server. It can be whatever you want.
36
36
 
37
37
  ## Engine setup
38
38
 
39
- The engine contains migrations for the `ctws_min_app_version` and `xxx` table which need to be created in the application's database so that the engine's models can query them correctly.
39
+ The engine contains migrations for the `ctws_min_app_version` and `xxx` table which need to be created in the application's database so that the engine's models can query them correctly.
40
40
  To copy these migrations into the application run the following command from the Rails App root, then run these migrations:
41
41
 
42
42
  ```bash
43
43
  rails ctws:install:migrations
44
44
  rails db:migrate
45
- ```
45
+ ```
46
46
 
47
47
  If you want to revert engine's migrations before removing it. To revert all migrations from blorgh engine you can run code such as:
48
48
 
@@ -54,7 +54,7 @@ bin/rails db:migrate SCOPE=ctws VERSION=0
54
54
 
55
55
  By default the user model is `User` but you can change it by creating or editing the `ctws.rb` initializer file in `config/initializers` and put this content in it:
56
56
 
57
- ```ruby
57
+ ```ruby
58
58
  Ctws.user_class = "Account"
59
59
  ```
60
60
 
@@ -64,12 +64,12 @@ The **`password` is optional** by default a user is validated with password, for
64
64
 
65
65
  To opt out the user validation with the password change it by creating or editing the `ctws.rb` initializer file in `config/initializers` and put this content in it:
66
66
 
67
- ```ruby
67
+ ```ruby
68
68
  Ctws.user_validate_with_password = false
69
69
  ```
70
70
  You can edit your app's required fields for signup by creating or editing the `ctws.rb` initializer file in `config/initializers` and put your strong parameters:
71
71
 
72
- ```ruby
72
+ ```ruby
73
73
  Ctws.user_class_strong_params = [:email, :password, :password_confirmation]
74
74
  ```
75
75
 
@@ -77,7 +77,7 @@ Ctws.user_class_strong_params = [:email, :password, :password_confirmation]
77
77
 
78
78
  By default the token expiry time is 24h but you can change it by creating or editing the `ctws.rb` initializer file in `config/initializers` and put this content in it:
79
79
 
80
- ```ruby
80
+ ```ruby
81
81
  Ctws.jwt_expiration_time = 24.hours.from_now
82
82
  ```
83
83
 
@@ -93,6 +93,14 @@ end
93
93
  ```
94
94
  -->
95
95
 
96
+ ### Response messages in users' locale (i18n)
97
+
98
+ In your app set your accepted languages, add to `application.rb`:
99
+
100
+ ```
101
+ config.i18n.available_locales = %w(en es fr ca)
102
+ ```
103
+
96
104
  ## Endpoints
97
105
 
98
106
  | Endpoint | Functionality | Requires Authentication? |
@@ -133,26 +141,26 @@ X-XSS-Protection: 1; mode=block
133
141
  {
134
142
  "data": [
135
143
  {
136
- "id": 3,
144
+ "id": 3,
137
145
  "type": "min_app_version",
138
146
  "attributes": {
139
- "codename": "Second release",
140
- "description": "Second release Description text",
141
- "min_version": "0.0.2",
142
- "platform": "android",
143
- "store_uri": "htttps://fdsafdsafdsaf.cot",
147
+ "codename": "Second release",
148
+ "description": "Second release Description text",
149
+ "min_version": "0.0.2",
150
+ "platform": "android",
151
+ "store_uri": "htttps://fdsafdsafdsaf.cot",
144
152
  "updated_at": "2017-06-22T17:53:31.252+02:00"
145
153
  }
146
- },
154
+ },
147
155
  {
148
156
  "type": "min_app_version",
149
- "id": 1,
157
+ "id": 1,
150
158
  "attributes": {
151
- "codename": "First Release",
152
- "description": "You need to update your app. You will be redirected to the corresponding store",
153
- "min_version": "0.0.1",
154
- "platform": "ios",
155
- "store_uri": "https://itunes.apple.com/",
159
+ "codename": "First Release",
160
+ "description": "You need to update your app. You will be redirected to the corresponding store",
161
+ "min_version": "0.0.1",
162
+ "platform": "ios",
163
+ "store_uri": "https://itunes.apple.com/",
156
164
  "updated_at": "2017-06-21T14:29:59.348+02:00"
157
165
  }
158
166
  }
@@ -184,10 +192,10 @@ X-XSS-Protection: 1; mode=block
184
192
  {
185
193
  "data": {
186
194
  "type": "user",
187
- "id": 20,
195
+ "id": 20,
188
196
  "attributes": {
189
197
  "message": "Account created successfully",
190
- "auth_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyMCwiZXhwIjoxNDk5ODU1MjQ5fQ.H9ljjShWOAv8b9xn9ZLKv-zgmH8xkPe6dkdhH4JrJPw",
198
+ "auth_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyMCwiZXhwIjoxNDk5ODU1MjQ5fQ.H9ljjShWOAv8b9xn9ZLKv-zgmH8xkPe6dkdhH4JrJPw",
191
199
  "created_at": "2017-07-11T12:27:27.916+02:00"
192
200
  }
193
201
  }
@@ -271,7 +279,7 @@ X-XSS-Protection: 1; mode=block
271
279
 
272
280
  running `rspec` will run tests and output a report, first run migrations the tests:
273
281
 
274
- ```bash
282
+ ```bash
275
283
  rails db:migrate RAILS_ENV=test
276
284
  rspec
277
285
  ```
@@ -1,13 +1,13 @@
1
1
  module Ctws
2
- # In the case where the record does not exist,
3
- # ActiveRecord will throw an exception ActiveRecord::RecordNotFound.
2
+ # In the case where the record does not exist,
3
+ # ActiveRecord will throw an exception ActiveRecord::RecordNotFound.
4
4
  # We'll rescue from this exception and return a 404 message.
5
5
  # List of Rails Status Code Symbols http://billpatrianakos.me/blog/2013/10/13/list-of-rails-status-code-symbols
6
-
6
+
7
7
  module ExceptionHandler
8
8
  # provides the more graceful `included` method
9
9
  extend ActiveSupport::Concern
10
-
10
+
11
11
  # Define custom error subclasses - rescue catches `StandardErrors`
12
12
  class AuthenticationError < StandardError; end
13
13
  class MissingToken < StandardError; end
@@ -15,6 +15,7 @@ module Ctws
15
15
  class ExpiredSignature < StandardError; end
16
16
  class UnprocessableEntity < StandardError; end
17
17
  class RoutingError < StandardError; end
18
+ class NotConfirmed < StandardError; end
18
19
 
19
20
  included do
20
21
  # Define custom handlers
@@ -27,19 +28,23 @@ module Ctws
27
28
  rescue_from ExceptionHandler::RoutingError, with: :not_found
28
29
  rescue_from ActiveRecord::RecordNotFound, with: :not_found
29
30
  rescue_from ActionController::RoutingError, with: :not_found
30
-
31
+ rescue_from ExceptionHandler::NotConfirmed, with: :not_confirmed
31
32
  end
32
-
33
+
33
34
  # JSON response with message; Status code 401 - Unauthorized
34
35
  def unauthorized_request(e)
35
36
  json_response([{ message: e.message, error_code: "401"}], :unauthorized)
36
37
  end
37
-
38
+
38
39
  # JSON response with message; Status code 404 - Not Found
39
40
  def not_found(e)
40
41
  json_response([{ message: e.message, error_code: "404" }], :not_found)
41
42
  end
42
-
43
+
44
+ def not_confirmed(e)
45
+ json_response([{ message: e.message, error_code: "403" }], :unauthorized)
46
+ end
47
+
43
48
  # JSON response with message; Status code 422 - unprocessable entity
44
49
  def four_twenty_two(e)
45
50
  json_response([{ message: e.message, error_code: "422" }], :unprocessable_entity)
@@ -49,6 +54,6 @@ module Ctws
49
54
  def four_ninety_eight(e)
50
55
  json_response([{ message: e.message, error_code: "498" }], :invalid_token)
51
56
  end
52
-
57
+
53
58
  end
54
59
  end
@@ -10,11 +10,11 @@ module Ctws
10
10
  self.data_payload(object)
11
11
  end
12
12
  end
13
-
13
+
14
14
  def json_response(object = {}, status = :ok)
15
15
  render json: self.payload?(object, status), status: status
16
16
  end
17
-
17
+
18
18
  def data_payload(object)
19
19
  {data: object}
20
20
  end
@@ -4,13 +4,15 @@ module Ctws
4
4
  class CtwsController < ApplicationController
5
5
  include Response
6
6
  include ExceptionHandler
7
+ include HttpAcceptLanguage::AutoLocale
8
+
7
9
  # Generic API stuff here
8
-
10
+
9
11
  # called before every action on controllers
10
12
  before_action :authorize_request
11
13
  skip_before_action :authorize_request, only: [:raise_not_found!]
12
14
  attr_reader :current_user
13
-
15
+
14
16
  def raise_not_found!
15
17
  raise Ctws::ExceptionHandler::RoutingError, ("#{Ctws::Message.unmatched_route(params[:unmatched_route])}")
16
18
  end
@@ -1,47 +1,51 @@
1
1
  module Ctws
2
2
  class Message
3
3
  def self.not_found(record = 'record')
4
- "Sorry, #{record} not found."
4
+ I18n.t('ctws.not_found', record: record)
5
5
  end
6
6
 
7
7
  def self.unmatched_route(route = 'route')
8
- "No route matches #{route}"
8
+ I18n.t('ctws.unmatched_route', route: route)
9
9
  end
10
10
 
11
11
  def self.invalid_credentials
12
- 'Invalid credentials'
12
+ I18n.t('ctws.invalid_credentials')
13
13
  end
14
14
 
15
15
  def self.invalid_token
16
- 'Invalid token'
16
+ I18n.t('ctws.invalid_token')
17
17
  end
18
18
 
19
19
  def self.missing_token
20
- 'Missing token'
20
+ I18n.t('ctws.missing_token')
21
21
  end
22
22
 
23
23
  def self.unauthorized
24
- 'Unauthorized request'
24
+ I18n.t('ctws.unauthorized')
25
25
  end
26
26
 
27
27
  def self.account_created
28
- 'Account created successfully'
28
+ I18n.t('ctws.account_created')
29
29
  end
30
30
 
31
31
  def self.account_not_created
32
- 'Account could not be created'
32
+ I18n.t('ctws.account_not_created')
33
33
  end
34
34
 
35
35
  def self.account_doesnt_exist
36
- "Account doesn't exist"
36
+ I18n.t('ctws.account_doesnt_exist')
37
37
  end
38
38
 
39
39
  def self.authenticated_user_success
40
- 'Authenticated user successfully'
40
+ I18n.t('ctws.authenticated_user_success')
41
41
  end
42
42
 
43
43
  def self.expired_token
44
- 'Sorry, your token has expired. Please login to continue.'
44
+ I18n.t('ctws.expired_token')
45
+ end
46
+
47
+ def self.record_not_confirmed(record = 'record')
48
+ I18n.t('ctws.record_not_confirmed', record: record)
45
49
  end
46
50
  end
47
51
  end
@@ -0,0 +1,14 @@
1
+ ca:
2
+ ctws:
3
+ account_created: "S'ha creat el compte amb èxit."
4
+ account_doesnt_exist: "El compte no existeix."
5
+ account_not_created: "No s'ha pogut crear el compte."
6
+ authenticated_user_success: "Usuari autenticat amb èxit."
7
+ expired_token: "Ho sentim, el vostre token ha caducat. Inicieu sessió per continuar."
8
+ invalid_credentials: "Credencials no vàlides."
9
+ invalid_token: "Token invàlid."
10
+ missing_token: "Falta token."
11
+ not_found: "No s'ha trobat %{record}."
12
+ record_not_confirmed: "%{record} no confirmat."
13
+ unauthorized: "Sol·licitud no autoritzada."
14
+ unmatched_route: "Cap ruta coincideix amb %{route}."
@@ -0,0 +1,14 @@
1
+ en:
2
+ ctws:
3
+ account_created: "Account created successfully."
4
+ account_doesnt_exist: "Account doesn't exist."
5
+ account_not_created: "Account could not be created."
6
+ authenticated_user_success: "Authenticated user successfully."
7
+ expired_token: "Sorry, your token has expired. Please login to continue."
8
+ invalid_credentials: "Invalid credentials."
9
+ invalid_token: "Invalid token."
10
+ missing_token: "Missing token."
11
+ not_found: "Sorry, %{record} not found."
12
+ record_not_confirmed: "%{record} not confirmed."
13
+ unauthorized: "Unauthorized request."
14
+ unmatched_route: "No route matches %{route}."
@@ -0,0 +1,14 @@
1
+ es:
2
+ ctws:
3
+ account_created: "Cuenta creada con éxito."
4
+ account_doesnt_exist: "La cuenta no existe."
5
+ account_not_created: "La cuenta no pudo ser creada."
6
+ authenticated_user_success: "Usuario autenticado con éxito."
7
+ expired_token: "Tu token ha expirado, por favor inicie sesión para continuar."
8
+ invalid_credentials: "Credenciales no válidas."
9
+ invalid_token: "Token no valido."
10
+ missing_token: "Falta token."
11
+ not_found: "Lo sentimos, %{record} no encontrado."
12
+ record_not_confirmed: "%{record} not confirmado."
13
+ unauthorized: "Solicitud no autorizada."
14
+ unmatched_route: "Ninguna ruta coincide con %{route}."
data/lib/ctws/engine.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  module Ctws
2
2
  class Engine < ::Rails::Engine
3
+ require "http_accept_language"
4
+
3
5
  engine_name "ctws"
4
6
  isolate_namespace Ctws
5
7
  config.generators.api_only = true
6
-
8
+
7
9
  config.generators do |g|
8
10
  g.test_framework :rspec, :fixture => false
9
11
  g.fixture_replacement :factory_girl_rails, :dir => 'spec/factories'
data/lib/ctws/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ctws
2
- VERSION = '0.1.12.alpha'
2
+ VERSION = '0.1.13.alpha'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ctws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12.alpha
4
+ version: 0.1.13.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agustí B.R.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,26 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: http_accept_language
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.0.5
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '2.0'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.0.5
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: sqlite3
57
77
  requirement: !ruby/object:Gem::Requirement
@@ -183,6 +203,9 @@ files:
183
203
  - app/models/ctws/min_app_version.rb
184
204
  - config/initializers/ctws.rb
185
205
  - config/initializers/mime_types.rb
206
+ - config/locales/ctws_messages_ca.yml
207
+ - config/locales/ctws_messages_en.yml
208
+ - config/locales/ctws_messages_es.yml
186
209
  - config/routes.rb
187
210
  - db/migrate/20170425110839_create_ctws_min_app_versions.rb
188
211
  - db/migrate/20170425110933_add_values_to_ctws_min_app_versions.rb