thecore_api 1.5.3 → 1.5.4

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
  SHA256:
3
- metadata.gz: ef4dd5d929116a0a118c11a83e42ba970971fc201e805eb76d339720836e92f0
4
- data.tar.gz: 135782a0bd2680c138f93f41e15f0d91b009ff28bf2700cb9f88d2347db00b91
3
+ metadata.gz: e29bf20eaab50f4da38e392dc458d33560b5f087856ac9e7d3e79ff2f0e0c45f
4
+ data.tar.gz: 2a96cb5fc7f67dc8fac29ad2c00d441d7bed3ea2ac863239eb126da3cfe2647a
5
5
  SHA512:
6
- metadata.gz: b734dea0448a3ef3a1031bc1c0e928ce6c96233d99b578327425e2dd4ad8c3a5b7fe61d18c93c120523b2e6f896c8bc328c9e364bec7fc3948636b6a501a5e40
7
- data.tar.gz: 8b2a95a3b22430087865a4596e9efc2fae9f2918a03a2b74f1e27257d3fd25772055c771599bfe0b1cc9994ead4c58b27c4b2e95e78a91aa44ab78acc0e05140
6
+ metadata.gz: e6034ec12f1163d590c58b3f7160a2338c4c059603355d38ea8ed8568e22588cbdea63062257c7db54219e7a1c210ebce40538d08f9e64127ff33d090272c668
7
+ data.tar.gz: 8c9b905d3fa7de808b27baffbf55de9fbb4e2eca373a57a20e58d6ae21e29f47c2b35914350681d6dc5b3bee6bd0f303f14843fdf7a1d34baaccdf1ae2f3534c
@@ -29,8 +29,8 @@ class Api::V1::BaseController < ActionController::API
29
29
  rescue_from ActiveRecord::RecordInvalid, with: :invalid!
30
30
  rescue_from CanCan::AccessDenied, with: :unauthorized!
31
31
  rescue_from ActiveRecord::RecordNotFound, with: :not_found!
32
- rescue_from NameError, with: :not_found!
33
- rescue_from NoMethodError, with: :not_found!
32
+ rescue_from NameError, with: :name_error!
33
+ rescue_from NoMethodError, with: :no_method_error!
34
34
  # rescue_from ::RubySpark::Device::ApiError, with: :fivehundred!
35
35
 
36
36
  attr_accessor :current_user
@@ -49,6 +49,7 @@ class Api::V1::BaseController < ActionController::API
49
49
  # So, if it's not an activerecord, the find model makes no sense at all
50
50
  # Thus must return 404
51
51
  path = params[:path].split("/")
52
+ puts "CHECK"
52
53
  return not_found! if (!path.first.classify.constantize.new.is_a? ActiveRecord::Base rescue false)
53
54
  find_model path.first
54
55
  if request.get?
@@ -62,6 +63,7 @@ class Api::V1::BaseController < ActionController::API
62
63
  elsif path.second.to_i.zero?
63
64
  # String, so it's a custom action I must find in the @model (as a singleton method)
64
65
  # GET :controller/:custom_action
66
+ puts "SECOND ZERO?"
65
67
  return not_found! unless @model.respond_to?(path.second)
66
68
  return render json: MultiJson.dump(@model.send(path.second, params)), status: 200
67
69
  elsif !path.second.to_i.zero? && path.third.blank?
@@ -73,6 +75,7 @@ class Api::V1::BaseController < ActionController::API
73
75
  show
74
76
  elsif !path.second.to_i.zero? && !path.third.blank?
75
77
  # GET :controller/:id/:custom_action
78
+ puts "SECOND AND THIRD"
76
79
  return not_found! unless @model.respond_to?(path.third)
77
80
  return render json: MultiJson.dump(@model.send(path.third, path.second.to_i, params)), status: 200
78
81
  end
@@ -82,6 +85,7 @@ class Api::V1::BaseController < ActionController::API
82
85
  create
83
86
  elsif path.second.to_i.zero?
84
87
  # POST :controller/:custom_action
88
+ puts "NO SECOND"
85
89
  return not_found! unless @model.respond_to?(path.second)
86
90
  return render json: MultiJson.dump(@model.send(path.second, params)), status: 200
87
91
  end
@@ -95,6 +99,7 @@ class Api::V1::BaseController < ActionController::API
95
99
  update
96
100
  elsif !path.second.to_i.zero? && !path.third.blank?
97
101
  # PUT :controller/:id/:custom_action
102
+ puts "ANOTHER SECOND AND THIRD"
98
103
  return not_found! unless @model.respond_to?(path.third)
99
104
  return render json: MultiJson.dump(@model.send(path.third, path.second.to_i, params)), status: 200
100
105
  end
@@ -131,14 +136,17 @@ class Api::V1::BaseController < ActionController::API
131
136
  current_page_number: @records.current_page
132
137
  }) if !pages_info.blank?
133
138
 
134
- puts @records_all.inspect
139
+ puts "ALL RECORDS FOUND: #{@records_all.inspect}"
135
140
  status = @records_all.blank? ? 404 : 200
136
141
  puts "If it's asked for page number, then paginate"
137
142
  return render json: MultiJson.dump(@records, json_attrs), status: status if !page.blank? # (@json_attrs || {})
138
143
  puts "if you ask for count, then return a json object with just the number of objects"
139
144
  return render json: MultiJson.dump({count: @records_all.count}) if !count.blank?
140
145
  puts "Default"
141
- render json: MultiJson.dump(@records_all, json_attrs), status: status #(@json_attrs || {})
146
+ json_out = MultiJson.dump(@records_all, json_attrs)
147
+ puts "JSON ATTRS: #{json_attrs}"
148
+ puts "JSON OUT: #{json_out}"
149
+ render json: json_out, status: status #(@json_attrs || {})
142
150
  end
143
151
 
144
152
  # def count
@@ -202,6 +210,14 @@ class Api::V1::BaseController < ActionController::API
202
210
  return api_error(status: 404, errors: [I18n.t("api.errors.not_found", default: "Not Found")])
203
211
  end
204
212
 
213
+ def name_error!
214
+ api_error(status: 501, errors: [I18n.t("api.errors.name_error", default: "Name Error")])
215
+ end
216
+
217
+ def no_method_error!
218
+ api_error(status: 501, errors: [I18n.t("api.errors.no_method_error", default: "No Method Error")])
219
+ end
220
+
205
221
  def invalid! exception
206
222
  # puts "ISPEZIONI: #{exception.record.errors.inspect}"
207
223
  # render json: { error: exception }, status: 422
@@ -4,4 +4,6 @@ en:
4
4
  bad_credentials: Bad Credentials
5
5
  unauthorized: Unauthorized Action
6
6
  not_found: Resource not found
7
- fivehundred: Internal server error, please contact service provider.
7
+ fivehundred: Internal server error, please contact service provider.
8
+ name_error: Name Error, method not found
9
+ no_method_error: No Method Error, action not found
@@ -4,4 +4,6 @@ it:
4
4
  bad_credentials: Credenziali errate
5
5
  unauthorized: Operazione non autorizzata
6
6
  not_found: Risorsa non trovata
7
- fivehundred: Errore interno del server, prego contattare il fornitore del servizio.
7
+ fivehundred: Errore interno del server, prego contattare il fornitore del servizio.
8
+ name_error: Errore di Nome, metodo non trovato
9
+ no_method_error: Metodo non trovato, azione non trovata
@@ -1,3 +1,3 @@
1
1
  module ThecoreApi
2
- VERSION = "1.5.3".freeze
2
+ VERSION = "1.5.4".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-16 00:00:00.000000000 Z
11
+ date: 2019-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thecore
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
- rubygems_version: 3.0.1
164
+ rubygems_version: 3.0.6
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: Taris API.