apiql 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -11
- data/apiql.gemspec +1 -1
- data/assets/javascripts/apiql.js +18 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: def514d5f185be467c6fe1d3cb0a45f1713ff47950d366f40c4830268064cf6b
|
4
|
+
data.tar.gz: 6e23322d7c596b40ebd2740bdd3e98ec961b88f1d2825bec8ecc829bb01e63b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c4253fe05c60846ddb813e7c09ef431d6d21d6574ecb9f3660a1d6a9cdc4ef128debe34fa1d601bd42eec8eb64a218a06e55f14eb29ef72b682bd97c7d7e6c4
|
7
|
+
data.tar.gz: c93a2ffeafe521a9eccf3e27bd6b452fd1878ad2aff2d18652f71e0597e09981e3ef8059d3f8173d94312c535d3afb986eac184929d2835c939789b8e65e6d66
|
data/README.md
CHANGED
@@ -36,17 +36,17 @@ def user
|
|
36
36
|
end
|
37
37
|
|
38
38
|
```
|
39
|
-
variables `session`, `current_user` and `params` will be stored into context you can use in presenters and handlers
|
39
|
+
variables `session`, `current_user` and `params` (you can list any you need) will be stored into context you can use in presenters and handlers
|
40
40
|
|
41
41
|
Define presenters for your models:
|
42
42
|
|
43
43
|
```ruby
|
44
44
|
class User < ApplicationRecord
|
45
45
|
class Entity < ::APIQL::Entity
|
46
|
-
attributes :full_name, :email, :token, :role, :roles
|
46
|
+
attributes :full_name, :email, :token, :role, :roles # any attributes, methods or associations
|
47
47
|
|
48
|
-
def token
|
49
|
-
object.token if object == current_user
|
48
|
+
def token # if defined, method will be called instead of attribute
|
49
|
+
object.token if object == current_user # directly access to current_user from context
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -66,28 +66,34 @@ APIQL.endpoint = "/"
|
|
66
66
|
```
|
67
67
|
|
68
68
|
```javascript
|
69
|
+
// function apiql(endpoint, schema, params = {}, form = null) -- schema is cached, so entire request is passed only for first time, later - short hashes only
|
70
|
+
|
69
71
|
authenticate(email, password) {
|
70
|
-
|
71
|
-
api.call(`
|
72
|
+
apiql("user", `
|
72
73
|
logout()
|
73
|
-
|
74
|
+
|
75
|
+
authenticate(email, password) {
|
74
76
|
token
|
75
77
|
}
|
78
|
+
|
76
79
|
me {
|
77
80
|
email full_name role token
|
81
|
+
|
82
|
+
roles {
|
83
|
+
id title
|
84
|
+
}
|
78
85
|
}
|
79
86
|
`, {
|
80
|
-
email: email,
|
87
|
+
email: email, // these var will be passed into methods on the server side
|
81
88
|
password: password
|
82
89
|
})
|
83
|
-
.then(response => {
|
90
|
+
.then(response => { // response contains results of called methods
|
84
91
|
let user = response.me
|
85
92
|
})
|
86
93
|
}
|
87
94
|
|
88
95
|
logout() {
|
89
|
-
|
90
|
-
api.call(`
|
96
|
+
apiql("user", `
|
91
97
|
logout
|
92
98
|
`)
|
93
99
|
.then(response => {
|
data/apiql.gemspec
CHANGED
data/assets/javascripts/apiql.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
}
|
1
|
+
const APIQL = {
|
2
|
+
on_error: null,
|
3
|
+
endpoint: '',
|
5
4
|
|
6
5
|
hash(s) {
|
7
6
|
let hash = 0, i, chr
|
@@ -12,9 +11,9 @@ class APIQL {
|
|
12
11
|
hash |= 0
|
13
12
|
}
|
14
13
|
return hash
|
15
|
-
}
|
14
|
+
},
|
16
15
|
|
17
|
-
call(schema, params = {}, form = null) {
|
16
|
+
call(endpoint, schema, params = {}, form = null) {
|
18
17
|
return new Promise((resolve, reject) => {
|
19
18
|
if(params instanceof FormData) {
|
20
19
|
form = params
|
@@ -33,13 +32,14 @@ class APIQL {
|
|
33
32
|
params.apiql = this.hash(schema)
|
34
33
|
}
|
35
34
|
|
36
|
-
Vue.http.post(`${APIQL.endpoint}${
|
35
|
+
Vue.http.post(`${APIQL.endpoint}${endpoint}`, params)
|
37
36
|
.then(response => {
|
38
37
|
resolve(response.body)
|
39
38
|
})
|
40
39
|
.catch(response => {
|
41
|
-
if(response.status == 401 && APIQL.
|
42
|
-
APIQL.
|
40
|
+
if(response.status == 401 && APIQL.on_error) {
|
41
|
+
APIQL.on_error(response)
|
42
|
+
return
|
43
43
|
}
|
44
44
|
|
45
45
|
if(form) {
|
@@ -48,17 +48,22 @@ class APIQL {
|
|
48
48
|
params.apiql_request = schema
|
49
49
|
}
|
50
50
|
|
51
|
-
Vue.http.post(`${APIQL.endpoint}${
|
51
|
+
Vue.http.post(`${APIQL.endpoint}${endpoint}`, form || params)
|
52
52
|
.then(response => {
|
53
53
|
resolve(response.body)
|
54
54
|
})
|
55
55
|
.catch(response => {
|
56
|
-
|
56
|
+
if(APIQL.on_error) {
|
57
|
+
APIQL.on_error(response)
|
58
|
+
} else {
|
59
|
+
alert(response.body)
|
60
|
+
}
|
57
61
|
})
|
58
62
|
})
|
59
63
|
})
|
60
64
|
}
|
61
65
|
}
|
62
66
|
|
63
|
-
|
64
|
-
APIQL.endpoint
|
67
|
+
function apiql(endpoint, schema, params = {}, form = null) {
|
68
|
+
return APIQL.call(endpoint, schema, params, form)
|
69
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Silchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|