Module: ApiBackend::APIRequests
- Defined in:
- lib/api_backend/spec_support/requests/api_requests.rb
Instance Method Summary collapse
- #api_get(endpoint, data = {}) ⇒ Object
- #api_headers ⇒ Object
- #api_patch(endpoint, data = {}) ⇒ Object
- #api_post(endpoint, data = {}) ⇒ Object
- #current_user ⇒ Object
- #login(user = User.last) ⇒ Object
Instance Method Details
#api_get(endpoint, data = {}) ⇒ Object
3 4 5 |
# File 'lib/api_backend/spec_support/requests/api_requests.rb', line 3 def api_get(endpoint, data={}) get endpoint, data.to_json, api_headers end |
#api_headers ⇒ Object
15 16 17 18 19 20 |
# File 'lib/api_backend/spec_support/requests/api_requests.rb', line 15 def api_headers headers = { 'Content-Type' => 'application/json' } headers["Authorization"] = "Token token=#{@auth_token}" if @auth_token headers end |
#api_patch(endpoint, data = {}) ⇒ Object
11 12 13 |
# File 'lib/api_backend/spec_support/requests/api_requests.rb', line 11 def api_patch(endpoint, data = {}) patch endpoint, data.to_json, api_headers end |
#api_post(endpoint, data = {}) ⇒ Object
7 8 9 |
# File 'lib/api_backend/spec_support/requests/api_requests.rb', line 7 def api_post(endpoint, data = {}) post endpoint, data.to_json, api_headers end |
#current_user ⇒ Object
28 29 30 |
# File 'lib/api_backend/spec_support/requests/api_requests.rb', line 28 def current_user @current_user end |
#login(user = User.last) ⇒ Object
22 23 24 25 26 |
# File 'lib/api_backend/spec_support/requests/api_requests.rb', line 22 def login(user = User.last) user = create(:user) unless user @current_user = user @auth_token = user.auth_token end |