Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON API with specs for data #233

Open
wants to merge 2 commits into
base: jsonapi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ RSpec/MultipleExpectations:
RSpec/ExampleLength:
Enabled: false

RSpec/ImplicitSubject:
Enabled: false

RSpec/RepeatedDescription:
Enabled: false

Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ group :development, :test do
gem "bundler-audit"
gem "byebug"
gem "dotenv-rails"
gem "rspec-its"
gem "pry-rails"
gem "rspec-rails"
gem "rubocop"
gem "rubocop-rspec"
end

group :test do
gem "email_spec"
gem "json_matchers"
gem "rspec_api_documentation"
gem "shoulda-matchers", require: false
gem "timecop"
gem "webmock", require: false
end

Expand Down
17 changes: 9 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ GEM
case_transform (0.2)
activesupport
choice (0.2.0)
coderay (1.1.2)
concurrent-ruby (1.0.5)
crack (0.4.3)
safe_yaml (~> 1.0.0)
Expand Down Expand Up @@ -100,9 +101,6 @@ GEM
concurrent-ruby (~> 1.0)
interactor (3.1.1)
jaro_winkler (1.5.1)
json_matchers (0.10.0)
json_schema
json_schema (0.19.1)
jsonapi-renderer (0.2.0)
jwt (1.5.6)
kaminari (1.1.1)
Expand Down Expand Up @@ -152,6 +150,11 @@ GEM
ast (~> 2.4.0)
pg (1.1.3)
powerpack (0.1.2)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.6)
pry (>= 0.10.4)
public_suffix (3.0.3)
puma (3.12.0)
rack (2.0.5)
Expand Down Expand Up @@ -206,9 +209,6 @@ GEM
rspec-expectations (3.8.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-its (1.2.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
Expand Down Expand Up @@ -258,6 +258,7 @@ GEM
sprockets (>= 3.0.0)
thor (0.19.4)
thread_safe (0.3.6)
timecop (0.9.1)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.4.0)
Expand Down Expand Up @@ -288,18 +289,17 @@ DEPENDENCIES
faker
health_check
interactor
json_matchers
kaminari
knock
letter_opener
pg
pry-rails
puma
rack-cors
rails (= 5.2.1)
rails-erd
responders
rollbar
rspec-its
rspec-rails
rspec_api_documentation
rubocop
Expand All @@ -309,6 +309,7 @@ DEPENDENCIES
spring
spring-commands-rspec
spring-watcher-listen
timecop
webmock

RUBY VERSION
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/v1/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class BaseController < ActionController::API
include Knock::Authenticable

before_action :authenticate_user!
before_action :setup_currents

rescue_from ActiveRecord::RecordNotFound do |_exception|
respond_with_error(:record_not_found)
Expand All @@ -18,6 +19,10 @@ def current_user
@current_user ||= token && authenticate_for(User)
end

def setup_currents
Current.user = current_user
end

def respond_with_resource(resource, status: :ok, location: resource, include: nil, fields: nil)
render jsonapi: resource, include: include, status: status, location: location, fields: fields
end
Expand Down
Empty file removed app/models/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions app/models/current.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Current < ActiveSupport::CurrentAttributes
attribute :user
end
2 changes: 1 addition & 1 deletion bin/ci
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

set -e

bin/rspec spec
bin/quality
bin/rspec spec
14 changes: 7 additions & 7 deletions doc/api/v1/profiles/delete_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@

<pre>Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExODgsInN1YiI6MTY2fQ.qgWchRvG9luv0IVp-sl-xfmFaIPtwTKcwttUozDUdcI</pre>
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzgxMjk4MDMsInN1YiI6MzM3fQ.mtEM7fCTtzOE4U8ga4EJlDR-1h8Wul-0pwP1qULyn78</pre>

#### Route

<pre>DELETE /v1/profile</pre>

#### Body

<pre>{"data":{"type":"profile_requests","attributes":{"full_name":null,"email":null,"password":null}}}</pre>
<pre>{}</pre>

#### cURL

<pre class="request">curl &quot;http://localhost:5000/v1/profile&quot; -d &#39;{&quot;data&quot;:{&quot;type&quot;:&quot;profile_requests&quot;,&quot;attributes&quot;:{&quot;full_name&quot;:null,&quot;email&quot;:null,&quot;password&quot;:null}}}&#39; -X DELETE \
<pre class="request">curl &quot;http://localhost:5000/v1/profile&quot; -d &#39;{}&#39; -X DELETE \
-H &quot;Content-Type: application/vnd.api+json&quot; \
-H &quot;Accept: application/vnd.api+json&quot; \
-H &quot;Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExODgsInN1YiI6MTY2fQ.qgWchRvG9luv0IVp-sl-xfmFaIPtwTKcwttUozDUdcI&quot;</pre>
-H &quot;Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzgxMjk4MDMsInN1YiI6MzM3fQ.mtEM7fCTtzOE4U8ga4EJlDR-1h8Wul-0pwP1qULyn78&quot;</pre>

### Response

Expand All @@ -40,11 +40,11 @@ Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExO

<pre>{
"data": {
"id": "166",
"id": "337",
"type": "users",
"attributes": {
"email": "user4@example.com",
"full_name": "Dr. Joana Heathcote"
"email": "john.smith@example.com",
"full_name": "John Smith"
}
}
}</pre>
12 changes: 6 additions & 6 deletions doc/api/v1/profiles/retrive_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@

<pre>Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExODcsInN1YiI6MTYzfQ.S1ejGuAOao-cIYvsSnbaETAG-1UCEtDZcDsdV-SeETs</pre>
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzgxMjk4MDMsInN1YiI6MzM0fQ.KXLuWGfolqLxJID0sHfTsSB__K-Mg6w8fJZosAO1Ca8</pre>

#### Route

<pre>GET /v1/profile</pre>

#### Query Parameters

<pre>{&quot;data&quot;:{&quot;type&quot;:&quot;profile_requests&quot;,&quot;attributes&quot;:{&quot;full_name&quot;:null,&quot;email&quot;:null,&quot;password&quot;:null}}}: </pre>
<pre>{}: </pre>

#### cURL

<pre class="request">curl -g &quot;http://localhost:5000/v1/profile&quot; -X GET \
-H &quot;Content-Type: application/vnd.api+json&quot; \
-H &quot;Accept: application/vnd.api+json&quot; \
-H &quot;Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExODcsInN1YiI6MTYzfQ.S1ejGuAOao-cIYvsSnbaETAG-1UCEtDZcDsdV-SeETs&quot;</pre>
-H &quot;Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzgxMjk4MDMsInN1YiI6MzM0fQ.KXLuWGfolqLxJID0sHfTsSB__K-Mg6w8fJZosAO1Ca8&quot;</pre>

### Response

Expand All @@ -40,11 +40,11 @@ Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExO

<pre>{
"data": {
"id": "163",
"id": "334",
"type": "users",
"attributes": {
"email": "user1@example.com",
"full_name": "Joe Marks II"
"email": "john.smith@example.com",
"full_name": "John Smith"
}
}
}</pre>
18 changes: 9 additions & 9 deletions doc/api/v1/profiles/update_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@

| Name | Description | Required | Scope |
|------|-------------|----------|-------|
| full_name | full name | false | |
| email | email | false | |
| password | password | false | |
| full_name | full name | false | data[attributes] |
| email | email | false | data[attributes] |
| password | password | false | data[attributes] |

### Request

#### Headers

<pre>Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExODcsInN1YiI6MTY0fQ.khNxDZk0-l7OVUIJEdr7JVmYE8oCmrH8WaorMAWk9Oc</pre>
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzgxMjk4MDMsInN1YiI6MzM1fQ.ywxsXPwLpOAce6cJ13fAabrqzKrvnWeMS2dDCw7dHlc</pre>

#### Route

<pre>PATCH /v1/profile</pre>

#### Body

<pre>{"data":{"type":"profile_requests","attributes":{"full_name":"Example User Updated","email":"[email protected]","password":"new_password"}}}</pre>
<pre>{"data":{"attributes":{"full_name":"Updated Name","email":"[email protected]","password":"new_password"}}}</pre>

#### cURL

<pre class="request">curl &quot;http://localhost:5000/v1/profile&quot; -d &#39;{&quot;data&quot;:{&quot;type&quot;:&quot;profile_requests&quot;,&quot;attributes&quot;:{&quot;full_name&quot;:&quot;Example User Updated&quot;,&quot;email&quot;:&quot;[email protected]&quot;,&quot;password&quot;:&quot;new_password&quot;}}}&#39; -X PATCH \
<pre class="request">curl &quot;http://localhost:5000/v1/profile&quot; -d &#39;{&quot;data&quot;:{&quot;attributes&quot;:{&quot;full_name&quot;:&quot;Updated Name&quot;,&quot;email&quot;:&quot;[email protected]&quot;,&quot;password&quot;:&quot;new_password&quot;}}}&#39; -X PATCH \
-H &quot;Content-Type: application/vnd.api+json&quot; \
-H &quot;Accept: application/vnd.api+json&quot; \
-H &quot;Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExODcsInN1YiI6MTY0fQ.khNxDZk0-l7OVUIJEdr7JVmYE8oCmrH8WaorMAWk9Oc&quot;</pre>
-H &quot;Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzgxMjk4MDMsInN1YiI6MzM1fQ.ywxsXPwLpOAce6cJ13fAabrqzKrvnWeMS2dDCw7dHlc&quot;</pre>

### Response

Expand All @@ -49,11 +49,11 @@ Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExO

<pre>{
"data": {
"id": "164",
"id": "335",
"type": "users",
"attributes": {
"email": "[email protected]",
"full_name": "Example User Updated"
"full_name": "Updated Name"
}
}
}</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@

| Name | Description | Required | Scope |
|------|-------------|----------|-------|
| full_name | full name | false | |
| email | email | false | |
| password | password | false | |
| full_name | full name | false | data[attributes] |
| email | email | false | data[attributes] |
| password | password | false | data[attributes] |

### Request

#### Headers

<pre>Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExODgsInN1YiI6MTY1fQ.AoMwSorPTETdEFEM1CUTKbEKEQzKhTGRW_yxh4KDPL0</pre>
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzgxMjk4MDMsInN1YiI6MzM2fQ.AyXUoKLR8wF8zTvflSC1r_hWtUy3EhpbzaxA095JhPs</pre>

#### Route

<pre>PATCH /v1/profile</pre>

#### Body

<pre>{"data":{"type":"profile_requests","attributes":{"full_name":"Example User Updated","email":"invalid","password":""}}}</pre>
<pre>{"data":{"attributes":{"full_name":"Updated Name","email":"invalid","password":""}}}</pre>

#### cURL

<pre class="request">curl &quot;http://localhost:5000/v1/profile&quot; -d &#39;{&quot;data&quot;:{&quot;type&quot;:&quot;profile_requests&quot;,&quot;attributes&quot;:{&quot;full_name&quot;:&quot;Example User Updated&quot;,&quot;email&quot;:&quot;invalid&quot;,&quot;password&quot;:&quot;&quot;}}}&#39; -X PATCH \
<pre class="request">curl &quot;http://localhost:5000/v1/profile&quot; -d &#39;{&quot;data&quot;:{&quot;attributes&quot;:{&quot;full_name&quot;:&quot;Updated Name&quot;,&quot;email&quot;:&quot;invalid&quot;,&quot;password&quot;:&quot;&quot;}}}&#39; -X PATCH \
-H &quot;Content-Type: application/vnd.api+json&quot; \
-H &quot;Accept: application/vnd.api+json&quot; \
-H &quot;Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExODgsInN1YiI6MTY1fQ.AoMwSorPTETdEFEM1CUTKbEKEQzKhTGRW_yxh4KDPL0&quot;</pre>
-H &quot;Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzgxMjk4MDMsInN1YiI6MzM2fQ.AyXUoKLR8wF8zTvflSC1r_hWtUy3EhpbzaxA095JhPs&quot;</pre>

### Response

Expand Down
12 changes: 6 additions & 6 deletions doc/api/v1/registration/create_user.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

| Name | Description | Required | Scope |
|------|-------------|----------|-------|
| full_name | full name | false | |
| email | email | true | |
| password | password | true | |
| full_name | full name | false | data[attributes] |
| email | email | true | data[attributes] |
| password | password | true | data[attributes] |

### Request

Expand All @@ -25,11 +25,11 @@ Accept: application/vnd.api+json</pre>

#### Body

<pre>{"data":{"type":"registration_requests","attributes":{"full_name":"Example User","email":"[email protected]","password":"123456"}}}</pre>
<pre>{"data":{"attributes":{"full_name":"Example User","email":"[email protected]","password":"123456"}}}</pre>

#### cURL

<pre class="request">curl &quot;http://localhost:5000/v1/registrations&quot; -d &#39;{&quot;data&quot;:{&quot;type&quot;:&quot;registration_requests&quot;,&quot;attributes&quot;:{&quot;full_name&quot;:&quot;Example User&quot;,&quot;email&quot;:&quot;[email protected]&quot;,&quot;password&quot;:&quot;123456&quot;}}}&#39; -X POST \
<pre class="request">curl &quot;http://localhost:5000/v1/registrations&quot; -d &#39;{&quot;data&quot;:{&quot;attributes&quot;:{&quot;full_name&quot;:&quot;Example User&quot;,&quot;email&quot;:&quot;[email protected]&quot;,&quot;password&quot;:&quot;123456&quot;}}}&#39; -X POST \
-H &quot;Content-Type: application/vnd.api+json&quot; \
-H &quot;Accept: application/vnd.api+json&quot;</pre>

Expand All @@ -47,7 +47,7 @@ Accept: application/vnd.api+json</pre>

<pre>{
"data": {
"id": "167",
"id": "338",
"type": "users",
"attributes": {
"email": "[email protected]",
Expand Down
12 changes: 6 additions & 6 deletions doc/api/v1/tokens/create_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

| Name | Description | Required | Scope |
|------|-------------|----------|-------|
| email | email | true | |
| password | password | true | |
| email | email | true | data[attributes] |
| password | password | true | data[attributes] |

### Request

Expand All @@ -24,11 +24,11 @@ Accept: application/vnd.api+json</pre>

#### Body

<pre>{"data":{"type":"token_requests","attributes":{"email":"[email protected]","password":"123456"}}}</pre>
<pre>{"data":{"attributes":{"email":"[email protected]","password":"123456"}}}</pre>

#### cURL

<pre class="request">curl &quot;http://localhost:5000/v1/tokens&quot; -d &#39;{&quot;data&quot;:{&quot;type&quot;:&quot;token_requests&quot;,&quot;attributes&quot;:{&quot;email&quot;:&quot;[email protected]&quot;,&quot;password&quot;:&quot;123456&quot;}}}&#39; -X POST \
<pre class="request">curl &quot;http://localhost:5000/v1/tokens&quot; -d &#39;{&quot;data&quot;:{&quot;attributes&quot;:{&quot;email&quot;:&quot;[email protected]&quot;,&quot;password&quot;:&quot;123456&quot;}}}&#39; -X POST \
-H &quot;Content-Type: application/vnd.api+json&quot; \
-H &quot;Accept: application/vnd.api+json&quot;</pre>

Expand All @@ -46,10 +46,10 @@ Accept: application/vnd.api+json</pre>

<pre>{
"data": {
"id": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExODgsInN1YiI6MTY4fQ.42J7f4PUabczP3pmUpQNcmtG4GFmXpHA17VaWmnQqK0",
"id": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzgxMjk4MDMsInN1YiI6MzM5fQ.JcMnxgvF9ysWq7nUpnoDHS4GhCCkTxiERPr6JQQGsHA",
"type": "jwt_tokens",
"attributes": {
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzY3NjExODgsInN1YiI6MTY4fQ.42J7f4PUabczP3pmUpQNcmtG4GFmXpHA17VaWmnQqK0"
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzgxMjk4MDMsInN1YiI6MzM5fQ.JcMnxgvF9ysWq7nUpnoDHS4GhCCkTxiERPr6JQQGsHA"
}
}
}</pre>
Loading