baseapi 0.1.14 → 0.1.15

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: d1ac2404b4884ee42c68800050820c341feafe49
4
- data.tar.gz: b8930c62ce6d395b5ac38bdd9548494cce2f4fc1
3
+ metadata.gz: 3cf4b65936ece8958b33861dd6d8c21e9211bfde
4
+ data.tar.gz: a20432a8f37c3f56e21590b51cbaf826bfda2f86
5
5
  SHA512:
6
- metadata.gz: 7a852691317a1f3ce4f9aad6a18b99d4de5197ce168d39dd0546a9ce2e60b1da354db4f583a0c5b5c7380aaa84934bba5f7161dc443db81b34b0b1f41287a82b
7
- data.tar.gz: e739f489132ae7893998034657b0b902e2f30a84bc80849d2ea1a73fba141c69d09b90d28e2cabd02ff89a2724abf1588af4f1bcd60f92c43ea657bf25cbc2cc
6
+ metadata.gz: fcb30fd3e064b46386a2e11119f54cc974b1213c48f01a61be3c30a4ffe086b46f3b3d0ef6a6bf5daf0d98eb8fac664b1a781b00eb0e6535ac20dd390355abfa
7
+ data.tar.gz: 9dbce156cd1f36bdc4a3255df45f3e643b7aa0f7451a5a0ee44c9d05e1463992b9d27d2e8fe04f1214866196434932ca55ccea9094ac5a3661e126652068dd45
data/README.md CHANGED
@@ -38,12 +38,7 @@ Extend the BaseApiController is when you create a Controller (app/controllers/us
38
38
  Routing configuration (config/routes.rb):
39
39
 
40
40
  constraints(:format => /json/) do
41
- get "users" => "users#index"
42
- get "users/:id" => "users#show"
43
- post "users" => "users#create"
44
- patch "users/:id" => "users#update"
45
- put "users/:id" => "users#update"
46
- delete "users/:id" => "users#destroy"
41
+ resources :users, only:[:index, :show, :create, :update, :destroy]
47
42
  end
48
43
 
49
44
  Corresponding API:
@@ -88,94 +83,115 @@ Company table data
88
83
  Get all
89
84
 
90
85
  GET /users.json
86
+ SQL => SELECT DISTINCT `users`.* FROM `users`
91
87
 
92
88
  Specify the count
93
89
 
94
90
  GET /users.json?count=10
91
+ SQL => SELECT DISTINCT `users`.* FROM `users` LIMIT 10 OFFSET 0
95
92
 
96
93
  Specify the page
97
94
 
98
95
  GET /users.json?count=10&page=2
96
+ SQL => SELECT DISTINCT `users`.* FROM `users` LIMIT 10 OFFSET 10
99
97
 
100
98
  Specify the sorting order
101
99
 
102
100
  GET /users.json?order=desc&orderby=name
101
+ SQL => SELECT DISTINCT `users`.* FROM `users` ORDER BY `users`.`name` DESC
103
102
 
104
103
  Specify the name
105
104
 
106
105
  GET /users.json?name=hoge
106
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE ( users.name = 'hoge')
107
107
 
108
108
  Specify multiple possible
109
109
 
110
110
  GET /users.json?name[]=hoge&name[]=huga
111
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE ( users.name = 'hoge' or users.name = 'huga')
111
112
 
112
113
  Specify the not id (v0.1.7~)
113
114
 
114
115
  GET /users.json?id=!1
116
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE (NOT users.id = '1')
115
117
 
116
118
  Of course the other is also possible (v0.1.7~)
117
119
 
118
120
  GET /users.json?name=!hoge
121
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE (NOT users.name = 'hoge')
119
122
 
120
123
  Specify the null name (v0.1.7~)
121
124
 
122
125
  GET /users.json?name=null
126
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE ( users.name IS NULL)
123
127
 
124
128
  Specify the not null name (v0.1.7~)
125
129
 
126
130
  GET /users.json?name=!null
131
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE (NOT users.name IS NULL)
127
132
 
128
133
  Specify the empty string and null name (v0.1.8~)
129
134
 
130
135
  GET /users.json?name=empty
136
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE ( users.name IS NULL OR users.name = '')
131
137
 
132
138
  Specify the not empty string and null name (v0.1.8~)
133
139
 
134
140
  GET /users.json?name=!empty
141
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE (NOT users.name IS NULL AND NOT users.name = '')
135
142
 
136
143
  Specify search for simply string 'empty' (v0.1.8~)
137
144
 
138
145
  It can also be in double quotes "empty"
139
146
 
140
147
  GET /users.json?name='empty'
148
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE ( workers.name = 'empty')
141
149
 
142
150
  Specify the belongs to company name
143
151
 
144
152
  Note that this is a single
145
153
 
146
154
  GET /users.json?company[name]=Google
155
+ SQL => SELECT DISTINCT `users`.* FROM `users` ...JOIN... WHERE ( companies.name = 'Google')
147
156
 
148
157
  Specify the has many users name
149
158
 
150
159
  Note that this is a multiple
151
160
 
152
161
  GET /companies.json?users[name]=hoge
162
+ SQL => SELECT DISTINCT `companies`.* FROM `companies` ...JOIN... WHERE ( users.name = 'hoge')
153
163
 
154
164
  Relationships can now specify multiple (v0.1.9~)
155
165
 
156
166
  Specify the User belong to a development part company
157
167
 
158
168
  GET /users.json?company[units][name]=development
169
+ SQL => SELECT DISTINCT `users`.* FROM `users` ...JOIN... WHERE ( units.name = 'development')
159
170
 
160
171
  Specify it more 20~ (v0.1.12~)
161
172
 
162
173
  GET /users.json?age=>=20
174
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE ( users.age >= 20)
163
175
 
164
176
  Specify the excess (v0.1.14~)
165
177
 
166
178
  GET /users.json?age=>20
179
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE ( users.age > 20)
167
180
 
168
181
  Specify it less ~20 (v0.1.12~)
169
182
 
170
183
  GET /users.json?age=<=20
184
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE ( users.age <= 20)
171
185
 
172
186
  Specify the less than (v0.1.14~)
173
187
 
174
188
  GET /users.json?age=<20
189
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE ( users.age < 20)
175
190
 
176
191
  Specify between 2015/09/01 ~ 2015/09/31 (v0.1.12~)
177
192
 
178
193
  GET /users.json?created_at[]=>=20150901&created_at[]=<=20150931
194
+ SQL => SELECT DISTINCT `users`.* FROM `users` WHERE ( users.created_at >= 20150901 and users.created_at <= 20150931)
179
195
 
180
196
  Multiple conditions is "OR Search" by default
181
197
 
@@ -194,12 +210,14 @@ Specify between 2015/09/01 ~ 2015/09/31 (v0.1.12~)
194
210
  Get id 1
195
211
 
196
212
  GET /users/1.json
213
+ SQL => SELECT `users`.* FROM `users` WHERE `users`.`id` = 1
197
214
 
198
215
  #### action create
199
216
 
200
217
  Create a user name is 'hoge'
201
218
 
202
219
  POST /users.json?name=hoge
220
+ SQL => INSERT INTO `example`.`users` (`id`, `name`) VALUES (NULL, 'hoge')
203
221
 
204
222
  #### action update
205
223
 
@@ -207,15 +225,19 @@ Update the name to 'huga'
207
225
 
208
226
  PATCH /users/1.json?name=huga
209
227
  PUT /users/1.json?name=huga
228
+ SQL => UPDATE `example`.`users` SET `name` = 'huga' WHERE `users`.`id` = 1
210
229
 
211
230
  #### action delete
212
231
 
213
232
  Delete the id to 1
214
233
 
215
234
  DELETE /users/1.json
235
+ SQL => DELETE FROM `example`.`users` WHERE `users`.`id` = 1
216
236
 
217
237
  #### return json format
218
238
 
239
+ index
240
+
219
241
  {
220
242
  error: false,
221
243
  message: "",
@@ -231,6 +253,17 @@ Delete the id to 1
231
253
  ]
232
254
  }
233
255
 
256
+ show, create, update, destroy
257
+
258
+ {
259
+ error: false,
260
+ message: "",
261
+ data: {
262
+ id: 1,
263
+ name: "hoge"
264
+ }
265
+ }
266
+
234
267
  ### reserved word (v0.1.13~)
235
268
 
236
269
  We are using the following as a reserved word.
@@ -128,13 +128,14 @@ module ActiveRecordBaseExtension extend ActiveSupport::Concern
128
128
  # @return String operator
129
129
  def getOperator(value, default = '=')
130
130
  operator = default
131
- value.slice!(0) if value[0] == '!'
132
- if ['NULL', 'EMPTY'].include?(value.upcase)
131
+ val = value.clone
132
+ val.slice!(0) if val[0] == '!'
133
+ if ['NULL', 'EMPTY'].include?(val.upcase)
133
134
  operator = 'IS'
134
- elsif value.length >= 2 and ['<=', '>='].include?(value[0..1])
135
- operator = value[0..1]
136
- elsif ['<', '>'].include?(value[0])
137
- operator = value[0]
135
+ elsif val.length >= 2 and ['<=', '>='].include?(val[0..1])
136
+ operator = val[0..1]
137
+ elsif ['<', '>'].include?(val[0])
138
+ operator = val[0]
138
139
  end
139
140
  operator
140
141
  end
@@ -143,37 +144,39 @@ module ActiveRecordBaseExtension extend ActiveSupport::Concern
143
144
  # @param String column
144
145
  # @param String value
145
146
  # @param String wraps ' or %
146
- # @return String value or sql
147
+ # @return String val or sql
147
148
  def getValue(column, value, *wraps)
148
149
  original = value.clone
149
- value.slice!(0) if value[0] == '!'
150
- if value.upcase == 'NULL'
151
- value = 'NULL'
152
- elsif value.upcase == 'EMPTY'
150
+ val = value.clone
151
+ val.slice!(0) if val[0] == '!'
152
+ if val.upcase == 'NULL'
153
+ val = 'NULL'
154
+ elsif val.upcase == 'EMPTY'
153
155
  prefix = getPrefix(original)
154
156
  operator = prefix == 'NOT' ? 'AND' : 'OR'
155
- value = "NULL #{operator} #{prefix} #{column} = ''"
156
- elsif value.length >= 2 and ['<=', '>='].include?(value[0..1])
157
- value = value.sub(value[0..1], '')
157
+ val = "NULL #{operator} #{prefix} #{column} = ''"
158
+ elsif val.length >= 2 and ['<=', '>='].include?(val[0..1])
159
+ val.sub!(val[0..1], '')
158
160
  elsif ['<', '>'].include?(value[0])
159
- value = value.sub(value[0], '')
161
+ val.sub!(val[0], '')
160
162
  else
161
- value = getNaturalValue(value)
163
+ val = getNaturalValue(val)
162
164
  wraps.each do |wrap|
163
- value = "#{wrap}#{value}#{wrap}"
165
+ val = "#{wrap}#{val}#{wrap}"
164
166
  end
165
167
  end
166
- return value
168
+ return val
167
169
  end
168
170
 
169
171
  # removal of the enclosing
170
172
  # @param String value
171
- # @return String value
173
+ # @return String val
172
174
  def getNaturalValue(value)
173
- if ((/^[\'].+?[\']$/ =~ value) != nil) and ((/^[\"].+?[\"]$/ =~ value) != nil)
174
- value.gsub!(/^[\'\"]/, '').gsub!(/[\'\"]$/, '')
175
+ val = value.clone
176
+ if ((/^[\'].+?[\']$/ =~ val) != nil) or ((/^[\"].+?[\"]$/ =~ val) != nil)
177
+ val = val[1..val.length-2]
175
178
  end
176
- value
179
+ val
177
180
  end
178
181
 
179
182
 
@@ -1,3 +1,3 @@
1
1
  module Baseapi
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baseapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moriyuki Arakawa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-02 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler