ctws 0.1.13.alpha → 0.1.14.beta

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: 2f86a86cc1af9c424b2349bad827b752cce5ad87
4
- data.tar.gz: 167ea2979b16ea75af0ba49790e30a69765ee58f
3
+ metadata.gz: 42cf1778d44f1e0fc1b9c0be34387d7746070979
4
+ data.tar.gz: d5948630771004880418c9164559198bfc0a937a
5
5
  SHA512:
6
- metadata.gz: 78997a0717a48effc5370641eec6d86d16b0069c640d762e246dd2e4dbe6ff69729adbdfa2fde10b36f741defc9f1caf884aeafce351d3655aec9794afcc05bd
7
- data.tar.gz: af4cf13d78a02772d22c650841d7dab03e9b342df78b2cdc52a3a48d4894594a5b9aea2d331b6d35bc3a642b661ffd40f13d90fe7642ea0fcc5ec9f38e541f17
6
+ metadata.gz: '08c94533c262016260efd779fae227de4a2eb5adf1a3d8cc8cca412106d31a768eb9bb152d2a6655da7aa995328a603221c6bd2d63d7ff491af38cd42eef4eb7'
7
+ data.tar.gz: 05d48c75a9ea212fb9bb583ded70685bda1e87c00ecac427bfccf34ddb811414725e97a2af43db67e42bba55b0ef8b417c32cf9555325c958097c212766b1ebd
@@ -16,6 +16,7 @@ module Ctws
16
16
  class UnprocessableEntity < StandardError; end
17
17
  class RoutingError < StandardError; end
18
18
  class NotConfirmed < StandardError; end
19
+ class VerificationError < StandardError; end
19
20
 
20
21
  included do
21
22
  # Define custom handlers
@@ -29,6 +30,7 @@ module Ctws
29
30
  rescue_from ActiveRecord::RecordNotFound, with: :not_found
30
31
  rescue_from ActionController::RoutingError, with: :not_found
31
32
  rescue_from ExceptionHandler::NotConfirmed, with: :not_confirmed
33
+ rescue_from ExceptionHandler::VerificationError, with: :four_ninety_eight
32
34
  end
33
35
 
34
36
  # JSON response with message; Status code 401 - Unauthorized
@@ -1,26 +1,25 @@
1
1
  module Ctws
2
2
  class AuthenticationController < CtwsController
3
3
  skip_before_action :authorize_request, only: :authenticate
4
-
4
+
5
5
  # return auth token once user is authenticated
6
6
  def authenticate
7
7
  auth_token = Ctws::AuthenticateUser.new(auth_params[:email], auth_params[:password]).call
8
8
  json_response auth_as_jsonapi(auth_token)
9
-
10
9
  end
11
-
10
+
12
11
  private
13
-
12
+
14
13
  def auth_as_jsonapi auth_token
15
14
  [{
16
15
  type: controller_name,
17
16
  attributes: {
18
- message: Ctws::Message.authenticated_user_success,
19
- auth_token: auth_token,
17
+ message: Ctws::Message.authenticated_user_success,
18
+ auth_token: auth_token
20
19
  }
21
20
  }]
22
21
  end
23
-
22
+
24
23
  def auth_params
25
24
  params.permit(:email, :password)
26
25
  end
@@ -8,12 +8,12 @@ module Ctws
8
8
  min_app_versions = []
9
9
  MinAppVersion.all.order(updated_at: :desc).group_by(&:platform).each do |platforms|
10
10
  platforms[1].each_with_index do |platform, index|
11
- min_app_versions << {platforms[0] => platform.as_jsonapi} if index == 0
11
+ min_app_versions.push(platform.as_jsonapi) if index == 0
12
12
  end
13
13
  end
14
14
  json_response min_app_versions
15
15
  end
16
-
16
+
17
17
  # GET /min_app_versions
18
18
  def index
19
19
  json_response MinAppVersion.all
@@ -1,7 +1,7 @@
1
1
  module Ctws
2
2
  class JsonWebToken
3
3
  require 'jwt'
4
-
4
+
5
5
  # secret to encode and decode token
6
6
  HMAC_SECRET = Rails.application.secrets.secret_key_base
7
7
 
@@ -17,9 +17,13 @@ module Ctws
17
17
  body = JWT.decode(token, HMAC_SECRET)[0]
18
18
  HashWithIndifferentAccess.new body
19
19
  # rescue from expiry exception
20
- rescue JWT::ExpiredSignature, JWT::VerificationError => e
21
- # raise custom error to be handled by custom handler
22
- raise Ctws::ExceptionHandler::ExpiredSignature, e.message
20
+ rescue JWT::ExpiredSignature => e
21
+ # raise custom error to be handled by custom handler
22
+ raise Ctws::ExceptionHandler::ExpiredSignature, e.message
23
+ rescue JWT::VerificationError => e
24
+ # raise custom error to be handled by custom handler
25
+ raise Ctws::ExceptionHandler::VerificationError, Ctws::Message.invalid_token
26
+
23
27
  end
24
28
  end
25
29
  end
@@ -24,16 +24,20 @@ module Ctws
24
24
  I18n.t('ctws.unauthorized')
25
25
  end
26
26
 
27
- def self.account_created
28
- I18n.t('ctws.account_created')
27
+ def self.resource_created(resource)
28
+ I18n.t('ctws.resource_created', resource: resource)
29
29
  end
30
30
 
31
- def self.account_not_created
32
- I18n.t('ctws.account_not_created')
31
+ def self.resource_updated(resource: resource)
32
+ I18n.t('ctws.resource_updated', resource: resource)
33
33
  end
34
34
 
35
- def self.account_doesnt_exist
36
- I18n.t('ctws.account_doesnt_exist')
35
+ def self.resource_not_created(resource: resource)
36
+ I18n.t('ctws.resource_not_created', resource: resource)
37
+ end
38
+
39
+ def self.resource_doesnt_exist(resource: resource)
40
+ I18n.t('ctws.resource_doesnt_exist', resource: resource)
37
41
  end
38
42
 
39
43
  def self.authenticated_user_success
@@ -47,5 +51,9 @@ module Ctws
47
51
  def self.record_not_confirmed(record = 'record')
48
52
  I18n.t('ctws.record_not_confirmed', record: record)
49
53
  end
54
+
55
+ def self.signature_verification_raised
56
+ I18n.t('ctws.signature_verification_raised')
57
+ end
50
58
  end
51
59
  end
@@ -1,22 +1,20 @@
1
1
  module Ctws
2
2
  class MinAppVersion < ApplicationRecord
3
3
  validates_presence_of :codename, :description, :platform, :min_version, :store_uri
4
-
4
+
5
5
  def as_jsonapi(options={})
6
6
  {
7
7
  type: ActiveModel::Naming.param_key(self),
8
8
  id: self.id,
9
9
  attributes: {
10
- codename: self.codename,
11
- description: self.description,
12
- min_version: self.min_version,
13
- platform: self.platform,
10
+ codename: self.codename,
11
+ description: self.description,
12
+ min_version: self.min_version,
13
+ platform: self.platform,
14
14
  store_uri: self.store_uri,
15
15
  updated_at: self.updated_at
16
16
  }
17
17
  }
18
18
  end
19
19
  end
20
-
21
-
22
20
  end
@@ -1,14 +1,15 @@
1
1
  ca:
2
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."
3
+ authenticated_user_success: "usuari autenticat amb èxit."
7
4
  expired_token: "Ho sentim, el vostre token ha caducat. Inicieu sessió per continuar."
8
5
  invalid_credentials: "Credencials no vàlides."
9
6
  invalid_token: "Token invàlid."
10
7
  missing_token: "Falta token."
11
8
  not_found: "No s'ha trobat %{record}."
12
9
  record_not_confirmed: "%{record} no confirmat."
10
+ resource_created: "S'ha creat el %{resource} amb èxit."
11
+ resource_doesnt_exist: "El %{resource} no existeix."
12
+ resource_not_created: "No s'ha pogut crear el %{resource}."
13
+ resource_updated: "S'ha actualitzat el %{resource} amb èxit."
13
14
  unauthorized: "Sol·licitud no autoritzada."
14
15
  unmatched_route: "Cap ruta coincideix amb %{route}."
@@ -1,14 +1,15 @@
1
1
  en:
2
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."
3
+ authenticated_user_success: "Authenticated %{resource} successfully."
7
4
  expired_token: "Sorry, your token has expired. Please login to continue."
8
5
  invalid_credentials: "Invalid credentials."
9
6
  invalid_token: "Invalid token."
10
7
  missing_token: "Missing token."
11
8
  not_found: "Sorry, %{record} not found."
12
9
  record_not_confirmed: "%{record} not confirmed."
10
+ resource_created: "%{resource} created successfully."
11
+ resource_doesnt_exist: "%{resource} doesn't exist."
12
+ resource_not_created: "%{resource} could not be created."
13
+ resource_updated: "%{resource} created successfully."
13
14
  unauthorized: "Unauthorized request."
14
15
  unmatched_route: "No route matches %{route}."
@@ -1,8 +1,5 @@
1
1
  es:
2
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
3
  authenticated_user_success: "Usuario autenticado con éxito."
7
4
  expired_token: "Tu token ha expirado, por favor inicie sesión para continuar."
8
5
  invalid_credentials: "Credenciales no válidas."
@@ -10,5 +7,9 @@ es:
10
7
  missing_token: "Falta token."
11
8
  not_found: "Lo sentimos, %{record} no encontrado."
12
9
  record_not_confirmed: "%{record} not confirmado."
10
+ resource_created: "%{resource} creado con éxito."
11
+ resource_doesnt_exist: "%{resource} no existe."
12
+ resource_not_created: "%{resource} no pudo ser creada."
13
+ resource_updated: "%{resource} actualizado con éxito."
13
14
  unauthorized: "Solicitud no autorizada."
14
15
  unmatched_route: "Ninguna ruta coincide con %{route}."
data/lib/ctws/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ctws
2
- VERSION = '0.1.13.alpha'
2
+ VERSION = '0.1.14.beta'
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.13.alpha
4
+ version: 0.1.14.beta
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-11-10 00:00:00.000000000 Z
11
+ date: 2018-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.5'
47
+ version: '2.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.5'
54
+ version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: http_accept_language
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -307,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
307
  version: 1.3.1
308
308
  requirements: []
309
309
  rubyforge_project:
310
- rubygems_version: 2.5.1
310
+ rubygems_version: 2.6.13
311
311
  signing_key:
312
312
  specification_version: 4
313
313
  summary: Rails gem to be used as Webservice base.