-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3309 - Update pender to use twitter's v2 API (#371)
* add a TwitterClient class to deal with requests to the v2 api - I used Rack::Utils.build_nested_query(params) instead of Rails' to_query because the first one keeps the order of hash when it converts to the query. I think that will make it easier to read when debugging. - We have a provider_instagram that also does the api call, it's very similar to what we were doing in the class. So I followed the structure we used for that provider, making it a Concern, instead of adding a new Class. - The url the new api returns is the url linked in the profile, not the twitter url. So for now I'm only combining the twitter url with the username to get the author url. * move twitter parser integration test to a dedicated folder - We want to separate the integration tests from the unit tests, so that in the future it can be easier for us to choose when we want to run them. We want to do this to all parsers * update twitter item tests - We don't need that many integration tests, so we are moving some of them back to test/models/parser/twitter_item_test.rb, and updating them to not make live requests, instead they will be stubbed. - I added tests to check the basic request functionality that we now have. And removed "assigns values to hash from the API response" since that is already being tested in "it makes a get request to the tweet lookup endpoint successfully" - "should decode html entities" was removed because that happens inside Media and is not done by the individual parser, which means the test actually fails (as it should) - fake_tweet and fake_twitter_user were removed, since they used methods from the old Twitter gem. Now we are stubbing a response from our new method: tweet_lookup - added .squish to parsed_data['raw']['api']['data'][0]['text'] to clean up line breaks from title and description. Our test was failling because it was not being removed. also since title and description are the same, I just set the description to be the same as the title instead of parsing twice. - removed the test for truncated text, that behavior is no longer present in the v2 api, only retweets might be truncated (we don't fetch those), and the way to deal with it is different. It does not take truncated as a query param. - removed storing oembed test because that happens inside Media and not the twitter profile parser - removed old error handling behavior tests and added new ones * remove twitter spec I think this was relying on the twitter gem error handling, so I don't think it makes sense to keep this for now. * update twitter config on config.example * remove twitter gem * update archiver_worker_test now they work with the twitter links, but since twitter is a bit unstable regarding changes, we should probably avoid using twitter links where it isn't absolutely needed * update according to Christa's review main notes: - instead of re-raising the error inside the provider, we are notifying sentry and returning an errors hash. #371 (comment) - we re-wrote the parsers according to what we feel is 'safer' moving forward: using merge! to set the defaults. - I had to update some of page_item_tests, so I used this as an opportunity to move the integration tests to their own file. (we are working on moving all the integration tests to their own files, separated from the unit ones) - Updated the error tests, now we test 3 scenarios: 200 response with error in json, non-200 response, exception in Net::HTTP - Updated to use dig, ie. parsed_data.dig('raw','api','data',0). this will return nil if data is missing, before it would raise an error for invalid access * update test shouldn't error when cannot get twitter author url when we get_twitter_metadata in the base parser, we check if there is a twitter username, if there is an username, we get the twitter author_url. if there isn't an username, there won't be an author_url, it shouldn't error when that happens * update errors hash and error testing I think it's better if we return the same keys inside errors as the twitter api, it will make it easier to test. * update how we deal with picture inside twitter item if there is no picture, it should be an empty string but it doesn't always make sense to test for it's presence, because if we get an error, it will be set to a string inside Media and not the parser --------- Co-authored-by: Caio Almeida <[email protected]>
- Loading branch information
1 parent
5ffd289
commit 293c11c
Showing
24 changed files
with
654 additions
and
931 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.