easy_api_operations 0.2 → 0.4.6
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 +4 -4
- data/easy_api_operations.gemspec +3 -1
- data/lib/easy_api_operations/version.rb +1 -1
- data/lib/easy_api_operations.rb +34 -17
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77759adde44079bc70bdc7a749e4371fdc064121
|
4
|
+
data.tar.gz: 2a898902cf673c6a602d793a0112046f565d8db9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 138e2cd64c5dbc0a250ab39523e3df58effb96b274ab0f0b70e15f2790834b20f286503e1a20d3d65e0e24e3de2b3c7136dec5c4a0fe47401b62f1acaf98455a
|
7
|
+
data.tar.gz: ff57717c759ed0410dbef1bad8eb6e61820a18b2bd14d18f712c05ba341f7feb904b5f80a10cbdcd867ce4dd78f9b5cc998d20dd32ead869451857f400914d5c
|
data/easy_api_operations.gemspec
CHANGED
@@ -18,5 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.add_development_dependency "bundler", "~> 1.9"
|
20
20
|
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
-
|
21
|
+
|
22
|
+
spec.add_dependency "easy_model_selects", "~> 0.9.9.1"
|
23
|
+
spec.add_dependency "indefinite_article", "~> 0.2.4"
|
22
24
|
end
|
data/lib/easy_api_operations.rb
CHANGED
@@ -1,7 +1,21 @@
|
|
1
|
-
|
1
|
+
require "easy_api_operations/version"
|
2
|
+
require "easy_model_selects"
|
3
|
+
require "indefinite_article"
|
2
4
|
|
3
5
|
module EasyApiOperations
|
4
|
-
|
6
|
+
|
7
|
+
def self.set_up_api(api, ressource_name, operations, options = {})
|
8
|
+
if options.include?(:db)
|
9
|
+
#db option gets through to easy_model_select gem
|
10
|
+
else
|
11
|
+
options[:db] = :normal
|
12
|
+
end
|
13
|
+
if options.include?(:primary_key)
|
14
|
+
@@primary_key = (defined? ressource_name.constantize.send(options[:primary_key])) == nil ? "id" : ressource_name.constantize.send(options[:primary_key])
|
15
|
+
else
|
16
|
+
@@primary_key = (defined? ressource_name.constantize.primary_key == nil) ? "id" : ressource_name.constantize.primary_key
|
17
|
+
end
|
18
|
+
|
5
19
|
operations.downcase
|
6
20
|
ressource_name.capitalize
|
7
21
|
|
@@ -36,9 +50,12 @@ module EasyApiOperations
|
|
36
50
|
desc "Returns a list of #{ressource_name}. Limited by 1000", params: (api_version + "::Entities::" + ressource_name.pluralize).constantize.documentation, entity: (api_version + "::Entities::" + ressource_name.pluralize).constantize#, entity: API::V1::Entities::Appointments
|
37
51
|
get do
|
38
52
|
if params.empty?
|
39
|
-
present "Choose something
|
53
|
+
present "Choose something dudesadf"
|
40
54
|
else
|
41
|
-
|
55
|
+
puts "hallo"
|
56
|
+
puts EasyModelSelects.get_where_statement_from_param(params, db: options[:db])
|
57
|
+
puts "fertsch"
|
58
|
+
results = ressource_name.constantize.where(EasyModelSelects.get_where_statement_from_param(params, db: options[:db])).order(@@primary_key => :desc).limit(1000)
|
42
59
|
present results, with: (api_version + "::Entities::" + ressource_name.pluralize).constantize
|
43
60
|
end
|
44
61
|
end
|
@@ -59,7 +76,7 @@ module EasyApiOperations
|
|
59
76
|
desc "Returns the primary key from #{ressource_name.pluralize}"
|
60
77
|
#!!! get then the path addition
|
61
78
|
get "primary_key" do
|
62
|
-
|
79
|
+
@@primary_key.to_sym
|
63
80
|
end
|
64
81
|
else
|
65
82
|
#no singular_primary_key
|
@@ -67,12 +84,12 @@ module EasyApiOperations
|
|
67
84
|
|
68
85
|
#___________get_______________start__________________
|
69
86
|
if operations.include?("singular_get") or operations.include?("all")
|
70
|
-
desc "Returns #{ressource_name.indefinitize} by #{
|
87
|
+
desc "Returns #{ressource_name.indefinitize} by #{@@primary_key}", entity: (api_version + "::Entities::" + ressource_name).constantize
|
71
88
|
params do
|
72
|
-
requires
|
89
|
+
requires @@primary_key, type: String, desc: "#{ressource_name} #{@@primary_key}"
|
73
90
|
end
|
74
|
-
get "#{
|
75
|
-
instance_variable = ressource_name.constantize.where(
|
91
|
+
get "#{@@primary_key.to_sym}", http_codes: http_codes_hash do
|
92
|
+
instance_variable = ressource_name.constantize.where(EasyModelSelects.get_where_statement_from_param(params, db: options[:db])).first
|
76
93
|
if instance_variable.nil?
|
77
94
|
error! http_codes_hash[404], 404
|
78
95
|
end
|
@@ -83,15 +100,15 @@ module EasyApiOperations
|
|
83
100
|
end
|
84
101
|
#___________put_______________start__________________
|
85
102
|
if operations.include?("singular_put") or operations.include?("all")
|
86
|
-
desc "Updates #{ressource_name.indefinitize} by #{
|
103
|
+
desc "Updates #{ressource_name.indefinitize} by #{@@primary_key}", entity: (api_version + "::Entities::" + ressource_name + "UpdateBody").constantize
|
87
104
|
params do
|
88
105
|
#!!!no need to require the primary_key as it is requested within the body already, change the body, change this part
|
89
106
|
#requires Appointment.primary_key, type: String, desc: "Appointment #{Appointment.primary_key}"
|
90
107
|
optional :body, type: (api_version + "::Entities::" + ressource_name + "UpdateBody").constantize, desc: 'Body to update params'
|
91
108
|
end
|
92
|
-
put
|
109
|
+
put @@primary_key, http_codes: http_codes_hash.merge(http_codes_hash_extra_creates) do
|
93
110
|
|
94
|
-
instance_variable = ressource_name.constantize.where(
|
111
|
+
instance_variable = ressource_name.constantize.where(EasyModelSelects.get_where_statement_from_param(params[@@primary_key], db: options[:db])).first
|
95
112
|
if instance_variable.nil?
|
96
113
|
error! http_codes_hash[404], 404
|
97
114
|
end
|
@@ -115,13 +132,13 @@ module EasyApiOperations
|
|
115
132
|
|
116
133
|
#___________delete_______________start__________________
|
117
134
|
if operations.include?("singular_delete") or operations.include?("all")
|
118
|
-
desc "Deletes #{ressource_name.indefinitize} by #{
|
135
|
+
desc "Deletes #{ressource_name.indefinitize} by #{@@primary_key}"
|
119
136
|
|
120
137
|
params do
|
121
|
-
requires
|
138
|
+
requires @@primary_key, type: String, desc: "#{ressource_name} #{@@primary_key}"
|
122
139
|
end
|
123
|
-
delete
|
124
|
-
instance_variable = ressource_name.constantize.where(
|
140
|
+
delete @@primary_key, http_codes: http_codes_hash do
|
141
|
+
instance_variable = ressource_name.constantize.where(EasyModelSelects.get_where_statement_from_param(params[@@primary_key], db: options[:db])).first
|
125
142
|
|
126
143
|
if instance_variable.nil?
|
127
144
|
error! http_codes_hash[404], 404
|
@@ -155,7 +172,7 @@ module EasyApiOperations
|
|
155
172
|
instance_variable = ressource_name.constantize.create(transformed_params)
|
156
173
|
if instance_variable.save
|
157
174
|
#status 204
|
158
|
-
body instance_variable.send("#{
|
175
|
+
body instance_variable.send("#{@@primary_key}")
|
159
176
|
else
|
160
177
|
error! http_codes_hash_extra_creates[500], 500
|
161
178
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_api_operations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bjoern Moeller / Christian Hentke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,16 +42,30 @@ dependencies:
|
|
42
42
|
name: easy_model_selects
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
type: :
|
47
|
+
version: 0.9.9.1
|
48
|
+
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.9.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: indefinite_article
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.4
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 0.2.4
|
55
69
|
description: call .set_up_api(self, ressource_name, operations) within grape api and
|
56
70
|
you will be able to get the api build for you.
|
57
71
|
email:
|