Skip to content

Get highlight#10

Merged
joshbeckman merged 7 commits intojoshbeckman:mainfrom
ajistrying:get-highlight-method
Mar 19, 2023
Merged

Get highlight#10
joshbeckman merged 7 commits intojoshbeckman:mainfrom
ajistrying:get-highlight-method

Conversation

@ajistrying
Copy link
Copy Markdown
Contributor

Aims to take care of #9

@ajistrying ajistrying changed the title WIP - Get highlight WIP: Get highlight Mar 1, 2023
res = make_readwise_request(url)
rescue => exception
raise exception
end
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andjosh wondering if a begin rescue is the best way to handle errors that might bubble up when we raise them within the enclosed method.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to begin/rescue if we're just going to raise again - this can just be: res = make_readwise_request(url)

@ajistrying ajistrying requested a review from joshbeckman March 5, 2023 00:36
res = make_readwise_request(url)
rescue => exception
raise exception
end
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to begin/rescue if we're just going to raise again - this can just be: res = make_readwise_request(url)

)
end

def make_readwise_request(url)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def make_readwise_request(url)
def get_readwise_request(url)

I would name this to signify that it's a GET request (because we'll want to support other methods in the future) - or make the HTTP verb a parameter.

http.request(export_req)
url = BASE_URL + 'export/?' + URI.encode_www_form(params)

begin
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, no need to begin/rescue here.

@ajistrying ajistrying requested a review from joshbeckman March 7, 2023 02:09
@ajistrying ajistrying marked this pull request as ready for review March 7, 2023 02:09
@ajistrying ajistrying requested a review from joshbeckman March 9, 2023 01:33
@ajistrying ajistrying changed the title WIP: Get highlight Get highlight Mar 12, 2023

subject.get_highlight
end
end
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this is within the realm of what's needed

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do better :)

Currently, this test doesn't do anything - it stubs the get_highlight method and a dummy return value and then calls that stubbed method.

I think it would be better to stub out the underlying API call with a mocked HTTP body/response (e.g. https://github.com/andjosh/readwise-ruby/blob/054f040acccdce26ef52d9fbd250995918b1b313/spec/readwise/client_spec.rb#L13-L22) and then test that:

  • the method does the validation that a highlight ID is passed as an argument
  • The method actually makes the intended underlying API call
  • The method correctly parses the HTTP response body and returns an instance of Highlight

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what I just pushed accomplishes at least a bit of what you prescribed, thank you for the suggestions! Writing good tests is something I'm definitely still working on.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


subject.get_highlight
end
end
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do better :)

Currently, this test doesn't do anything - it stubs the get_highlight method and a dummy return value and then calls that stubbed method.

I think it would be better to stub out the underlying API call with a mocked HTTP body/response (e.g. https://github.com/andjosh/readwise-ruby/blob/054f040acccdce26ef52d9fbd250995918b1b313/spec/readwise/client_spec.rb#L13-L22) and then test that:

  • the method does the validation that a highlight ID is passed as an argument
  • The method actually makes the intended underlying API call
  • The method correctly parses the HTTP response body and returns an instance of Highlight

@ajistrying ajistrying requested a review from joshbeckman March 19, 2023 01:04

subject.get_highlight
end
end
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@joshbeckman joshbeckman merged commit 9011052 into joshbeckman:main Mar 19, 2023
@joshbeckman
Copy link
Copy Markdown
Owner

Published in v0.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants