hub_kernel-api 0.3.0 → 0.4.0
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/README.md +10 -0
- data/app/controllers/hub_kernel/api/hub_calls_controller.rb +1 -10
- data/app/controllers/hub_kernel/api/hub_controller.rb +17 -0
- data/app/controllers/hub_kernel/api/hubs_controller.rb +13 -0
- data/config/routes.rb +1 -0
- data/lib/hub_kernel/api/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e54d19b67798c82119ecff94f0f294353cd927da83a55282b2f61ffbf111061d
|
|
4
|
+
data.tar.gz: 1d48fc7eb9520cb6300315462a74159b68a0e236c797f87d97964c4455eefce1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa3f514ecb094b92a30e80fc390414abf616e68c8b479485462d5f7298d77cab57f3d813ced143fbafc58330f8685a7cac2d94aad14693a006730ff0c0ba6060
|
|
7
|
+
data.tar.gz: 07c3ae8786feb3ad091474071d2dc7699ee8cc0b7ebb798f95cd53c7afaac53096e7df8d261bbd5c1e01ba4f13a613998b40cea868c4afccabcc12a0789c0fe9
|
data/README.md
CHANGED
|
@@ -38,6 +38,16 @@ A hub listed this way answers only at the name given, and the permission check i
|
|
|
38
38
|
asked about it by its own name, such as `ledger:record_spend`. A read answers GET and a write answers POST, and the answer is the method's
|
|
39
39
|
return value under `answer`.
|
|
40
40
|
|
|
41
|
+
A GET at a served hub's own address, `/<hub>`, lists the methods the caller may call on
|
|
42
|
+
the account the host names, each with its name, the values it takes and its verb:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
[{ "name": "price_of", "takes": ["item"], "verb": "GET" }]
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
A hub that is not served is answered as not found, and a caller the host's sign-in refuses
|
|
49
|
+
is shown nothing.
|
|
50
|
+
|
|
41
51
|
| Case | Status | Body |
|
|
42
52
|
| --- | --- | --- |
|
|
43
53
|
| The method answers | 200 | `{"answer": ...}` |
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
module HubKernel
|
|
2
2
|
module Api
|
|
3
|
-
class HubCallsController <
|
|
3
|
+
class HubCallsController < HubController
|
|
4
4
|
wrap_parameters false
|
|
5
5
|
|
|
6
|
-
rescue_from ActionController::RoutingError, HubKernel::NotAllowed, with: :not_found
|
|
7
6
|
rescue_from HubKernel::Refused, HubKernel::MissingArgumentError, with: :refused
|
|
8
7
|
rescue_from ActiveRecord::RecordNotFound, with: :missing_record
|
|
9
8
|
|
|
@@ -16,8 +15,6 @@ module HubKernel
|
|
|
16
15
|
|
|
17
16
|
private
|
|
18
17
|
|
|
19
|
-
def hub = @hub ||= HubKernel::Api.find(params[:hub]) || raise(ActionController::RoutingError, "Not found")
|
|
20
|
-
|
|
21
18
|
def asked_with_the_right_verb? = hub.exposed(params[:name])&.writes == request.post?
|
|
22
19
|
|
|
23
20
|
def refuse_unlisted_values
|
|
@@ -32,12 +29,6 @@ module HubKernel
|
|
|
32
29
|
|
|
33
30
|
def values = request.query_parameters.merge(request.request_parameters).deep_symbolize_keys
|
|
34
31
|
|
|
35
|
-
def caller_person = send(HubKernel::Api.person_method)
|
|
36
|
-
|
|
37
|
-
def caller_account = send(HubKernel::Api.account_method)
|
|
38
|
-
|
|
39
|
-
def not_found = render(json: { error: "Not found" }, status: :not_found)
|
|
40
|
-
|
|
41
32
|
def refused(refusal) = render(json: { error: refusal.message }, status: :unprocessable_content)
|
|
42
33
|
|
|
43
34
|
def missing_record(missing)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module HubKernel
|
|
2
|
+
module Api
|
|
3
|
+
class HubController < HubKernel::Api.base_controller.constantize
|
|
4
|
+
rescue_from ActionController::RoutingError, HubKernel::NotAllowed, with: :not_found
|
|
5
|
+
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def hub = @hub ||= HubKernel::Api.find(params[:hub]) || raise(ActionController::RoutingError, "Not found")
|
|
9
|
+
|
|
10
|
+
def caller_person = send(HubKernel::Api.person_method)
|
|
11
|
+
|
|
12
|
+
def caller_account = send(HubKernel::Api.account_method)
|
|
13
|
+
|
|
14
|
+
def not_found = render(json: { error: "Not found" }, status: :not_found)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module HubKernel
|
|
2
|
+
module Api
|
|
3
|
+
class HubsController < HubController
|
|
4
|
+
def show
|
|
5
|
+
render json: hub.exposures_for(person: caller_person, account: caller_account).map { |exposure| listed(exposure) }
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
def listed(exposure) = { name: exposure.name, takes: exposure.takes, verb: exposure.writes ? "POST" : "GET" }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/config/routes.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hub_kernel-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- tylercschneider
|
|
@@ -50,6 +50,8 @@ files:
|
|
|
50
50
|
- README.md
|
|
51
51
|
- Rakefile
|
|
52
52
|
- app/controllers/hub_kernel/api/hub_calls_controller.rb
|
|
53
|
+
- app/controllers/hub_kernel/api/hub_controller.rb
|
|
54
|
+
- app/controllers/hub_kernel/api/hubs_controller.rb
|
|
53
55
|
- config/routes.rb
|
|
54
56
|
- lib/hub_kernel-api.rb
|
|
55
57
|
- lib/hub_kernel/api.rb
|