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
Initial inoreader implementation #22
Conversation
Coverage decreased (-0.6%) to 35.74% when pulling 2e0de94ae6cc22be136f649c739f69b8aa4a66cc on bartlibert:master into f40d5eb on newsboat:master. |
1 similar comment
Coverage decreased (-0.6%) to 35.74% when pulling 2e0de94ae6cc22be136f649c739f69b8aa4a66cc on bartlibert:master into f40d5eb on newsboat:master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot! I'm still not sure how comfortable you are with C++, so if any of my comments seem overwhelming, just say so.
I'm generally in favour of this PR, but I don't like the hard-coded tokens. Will you be interested in porting this to OAuth? Newsboat don't have any existing code for such APIs, though, and I don't have any experience with OAuth, but I'm ready to discuss things with you and help with tying this into Newsboat nicely.
Another thing: if someone reports a problem with Newsboat and Inoreader, can I ping you to take a look? I'm asking because I'm not using Inoreader and I won't notice if something breaks; and since I don't use it, I might not fully comprehend user's reports. In other words: will you maintain this particular class, handling bugs reported against it and aiding in implementing features?
Speaking of users: please write some docs! You'll probably be able to base them off The Old Reader's doc entry.
I didn't test the code yet, but I will—on the weekend, hopefully.
include/inoreader_api.h
Outdated
@@ -0,0 +1,48 @@ | |||
#ifndef NEWSBEUTER_INOREADER_API_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recently reworked all headers to use another format, so this should say "NEWSBOAT_INOREADER_API_H_
".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. I started this out on Newsbeuter still at the time, so that's the reason probably :)
@@ -31,7 +31,7 @@ src/cache.o: src/cache.cpp include/controller.h include/urlreader.h \ | |||
include/matcher.h filter/FilterParser.h include/utils.h include/logger.h \ | |||
config.h include/strprintf.h include/cache.h include/filtercontainer.h \ | |||
include/colormanager.h include/regexmanager.h include/remote_api.h \ | |||
include/exceptions.h | |||
include/fslock.h include/exceptions.h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's my bad! Forgot to run make depslist
after adding FSLock
.
If you are comfortable with git rebase
, I'd rather see this little change as a separate commit—i.e. check out master
, run make depslist
, commit, rebase your PR on top of the resulting commit.
If rebase isn't something you can do easily, don't bother; it's just a tiny detail, nothing show-stopping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, I'll rebase this.
@@ -65,6 +65,9 @@ configcontainer::configcontainer() | |||
{ "ignore-mode", | |||
configdata("download", std::unordered_set<std::string>({ | |||
"download", "display" })) }, | |||
{ "inoreader-login", configdata("", configdata_t::STR) }, | |||
{ "inoreader-password", configdata("", configdata_t::STR) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All our remote APIs support -passwordfile
and -passwordeval
, so Inoreader should, too.
src/inoreader_api.cpp
Outdated
|
||
std::string inoreader_api::retrieve_auth() { | ||
CURL * handle = curl_easy_init(); | ||
credentials cred = get_credentials("inoreader", "inoreader"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other APIs use capitals in second argument here, because it's the name of the service; please change it to "Inoreader".
src/inoreader_api.cpp
Outdated
curl_slist_free_all(list); | ||
|
||
std::vector<std::string> lines = utils::tokenize(result); | ||
for (auto line : lines) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You aren't modifying those strings, so make it const auto
. Then, it also doesn't make sense to ask for a copy, so change it to const auto&
to use references. (Just as with ++i
vs. i++
in for
loops, it doesn't matter in this particular case because items are few and quite short, but you better cultivate the right habit for the times when this stuff does matter.)
src/inoreader_api.cpp
Outdated
std::vector<std::string> lines = utils::tokenize(result); | ||
for (auto line : lines) { | ||
LOG(level::DEBUG, "inoreader_api::retrieve_auth: line = %s", line); | ||
if (line.substr(0,5)=="Auth=") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add spaces around ==
? Easier to read this way, especially since the string ends with =
too.
src/inoreader_api.cpp
Outdated
for (auto line : lines) { | ||
LOG(level::DEBUG, "inoreader_api::retrieve_auth: line = %s", line); | ||
if (line.substr(0,5)=="Auth=") { | ||
std::string auth = line.substr(5, line.length()-5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the second argument to substr
—it's npos
by default, i.e. the whole "tail" of the string will be returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as with some of the things above, I just kept it this way based on the existing code because I could not find any contribution guidelines, but if you're open to improving the code, I'll certainly do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I'm all for improving the code! Modernize everything you see :)
Opened #28 regarding guidelines; thanks for a prod. Never knew what I should write there, but seems like I should make an effort and figure it out if I want to see more PRs coming my way.
src/inoreader_api.cpp
Outdated
json_object_object_get_ex(sub, "title", &node); | ||
const char * title = json_object_get_string(node); | ||
|
||
// Ignore URLs where ID start with given prefix - those never load, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this even apply to Inoreader?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to check actually.
src/inoreader_api.cpp
Outdated
} | ||
|
||
bool inoreader_api::mark_all_read(const std::string& feedurl) { | ||
std::string real_feedurl = feedurl.substr(strlen(INOREADER_FEED_PREFIX), feedurl.length() - strlen(INOREADER_FEED_PREFIX)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as earlier comment: no need for second argument here, substr
got a useful default.
Some general answers: I have about 8 years of professional c++ expercience, so don't worry about getting technical :) I have a full-time job and a family, so I won't be able to respond to queries/bugs immediately, but if some delay is not an issue, I'm willing to have a look at those. As for the oauth: I have no experience at all with that, but I'm willing to have a look. As for the hardcoded tokens: even with oauth, they will still be there, as they are needed to identify the application itself. We might make them user-configurable, but I don't know it this will be useful. |
6edc829
to
dfdb7c5
Compare
Coverage decreased (-1.3%) to 35.105% when pulling dfdb7c52eb248eafb0fb59b3c4820f74e6042bde on bartlibert:master into f40d5eb on newsboat:master. |
Coverage decreased (-0.6%) to 35.768% when pulling dfdb7c52eb248eafb0fb59b3c4820f74e6042bde on bartlibert:master into f40d5eb on newsboat:master. |
Delay shouldn't be an issue; thanks! The volume is generally low, I think I saw less than 10 remote API-related bugs in Newsbeuter over 2 years.
Hmm, Inoreader's help page made me think otherwise. I'll look more closely into this in about 18 hours. |
doc/newsboat.txt
Outdated
~~~~~~~~~~~~~~~~~ | ||
|
||
http://inoreader.com/[Inoreader] is another successor to Google Reader. | ||
Newsboat provides functionality to use The Inoreader as its |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The Inoreader"? I'm not sure the article is necessary there.
doc/newsboat.txt
Outdated
so that it can authenticate with Inoreader. | ||
Note that this is NOT your login with your Google or Facebook account. If you | ||
use one of those to login to Inoreader, you have to create a username and | ||
password in Inoreader Preferences > Profile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing period at the end. Perhaps the "Preferences > Profile" bit should be in italics to make it clearer these are names of the menu items, not just general directions.
After that, use these flags when you edit flags for an article, and these | ||
articles will be starred resp. shared. | ||
|
||
By default, newsboat also shows Inoreader "special feeds": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The names of special feeds are self-explanatory, so I'd just enumerate them without any explanations.
If you do want to make a list, add an empty line before it otherwise it isn't rendered as a list at all. (If you have asciidoc installed, you can make doc
and preview the result in doc/xhtml/newsboat.html
.)
doc/newsboat.txt
Outdated
|
||
inoreader-show-special-feeds no | ||
|
||
Inoreader's folders are converted into Newsboat tags. You can select and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already mentioned on lines 816-820. Let's combine these two paragraphs.
include/inoreader_api.h
Outdated
@@ -0,0 +1,48 @@ | |||
#ifndef NEWSBOAT_INOREADER_API_H | |||
#define NEWSBOAT_INOREADER_API_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, these two lines still miss the underscore at the end: it should be NEWSBOAT_INOREADER_API_H_
.
Upon re-reading their OAuth docs, I see you're right—we'll need to submit CLIENT_ID which we obtain by registering an app. I agree with you that it doesn't make sense to make the ID configurable. I'll register an app and we'll use the token I get. |
Coverage decreased (-0.6%) to 35.768% when pulling 3b49e950229a1a4d1ae66bcc8cf541a1af2e2384 on bartlibert:master into b6c3eb5 on newsboat:master. |
Looks good! Have you looked into OAuth yet? In the future, I expect to add more remote APIs that use it, so I looked around for a C++ library that will handle OAuth-specific bits for us, but the only standalone solution I could find (liboauthcpp) doesn't support OAuth 2.0. Looking forward to see what if find or come up with on this front. (I'm not hurrying you, I promise!) |
I had a quick look at oauth, but did not find anything useful yet, so I fear it'll have to be implemented from scratch. I can have a look, but don't expect any results soon :( |
Okay, let's split OAuth into a separate task then (see #35). I'll definitely-certainly-absolutely will test this tomorrow and merge it. Thank you for the work you've already done! |
Merged! Thank you very much for implementing this! I've replaced the ID and key with mine, so you can delete yours now. Did 70 requests just during testing; hope users won't set their reload-time to something silly like 1 minute. :) |
Thanks for merging! |
I'll just keep an eye on the stats and request an increase when we approach the limit. It also makes sense to check if we're using the API in the best possible way—perhaps we can get rid of some requests by caching things? |
Pull request to get feedback / help on this.
Currently using API keys under my account, if necessary this can be changed.