-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from akurashev/feature/extract-http-client
Extract HTTP client
- Loading branch information
Showing
4 changed files
with
43 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
require 'open-uri' | ||
|
||
module InstagramTagsSearcher | ||
# This is a simple HTTP client which relies on Ruby StdLib OpenURI module: | ||
# https://ruby-doc.org/stdlib-2.6.3/libdoc/open-uri/rdoc/OpenURI.html | ||
# | ||
# This wrapper supports custom User-Agent header values. | ||
# It expects JSON in response. | ||
class HttpClient | ||
HEADER = { | ||
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) ' \ | ||
'AppleWebKit/537.36 (KHTML, like Gecko) ' \ | ||
'Chrome/53.0.2785.104 Safari/537.36 Core/1.53.3357.400 ' \ | ||
'QQBrowser/9.6.11858.400' | ||
}.freeze | ||
|
||
def read_hash(url) | ||
JSON.parse(make_request(url)) | ||
end | ||
|
||
private | ||
|
||
def make_request(url) | ||
URI.parse(url).open(HEADER).read | ||
end | ||
end | ||
end |