Skip to content

feat: Strict keyword handling in request methods#65

Merged
jgraichen merged 2 commits intomainfrom
f/strict-keywords
Feb 14, 2025
Merged

feat: Strict keyword handling in request methods#65
jgraichen merged 2 commits intomainfrom
f/strict-keywords

Conversation

@jgraichen
Copy link
Copy Markdown
Owner

@jgraichen jgraichen commented Feb 14, 2025

All request methods on Relation accept parameters and headers as keyword arguments. This clearly separates them from any data. They continue to take either params or data as a positional argument too, to support shorter call invocations.

This needs changes to users, for example:

get({}, {headers: ...})         ->  get(headers: ...)
head(id: 1)                     ->  head({id: 1})
delete(params, {headers: ...})  ->  delete(params, headers: ...)

These can stay:

get(params)
head(params)
delete(params)

The methods #post, #put, and #patch still take an optional first positional data/body argument:

put(body)                       ->  put(body)
post(body, {}, {headers: ...})  ->  post(body, headers: ...)
patch(body, {q: 1})             ->  post(body, params: {q: 1})
All request methods on Relation accept params and headers as keyword
arguments only. This clearly separates them from any data.

This needs changes to users, for example:

    get({}, {headers: ...})  ->  get(headers: ...)
    head(params)             ->  head(params:)

The methods #post, #put, and #patch still take an optional first
positional data/body argument:

    post(body, {}, {headers: ...})  ->  post(body, headers: ...)
    patch(body, {q: 1})             ->  post(body, params: {q: 1})
@jgraichen jgraichen self-assigned this Feb 14, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.87%. Comparing base (e09d9b6) to head (96b9abc).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #65      +/-   ##
==========================================
+ Coverage   95.40%   95.87%   +0.46%     
==========================================
  Files          21       21              
  Lines         675      678       +3     
==========================================
+ Hits          644      650       +6     
+ Misses         31       28       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

These are merged with the keyword argument params, with the latter being
preferred. This allows writing shorter methods, such as:

    gh.rel(:user).get({user: 'jgraichen'}).value!

The commit further expands the testing on the request methods, for
params and data handling.
@jgraichen jgraichen merged commit c7dc315 into main Feb 14, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant