Created
February 12, 2025 19:25
-
-
Save ysim-precich/905b886e24daec9eec8cd3496c7f73dc to your computer and use it in GitHub Desktop.
Revisions
-
ysim-precich created this gist
Feb 12, 2025 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ require 'uri' require 'net/http' require 'JSON' class EasyBrokerReader attr_reader :titles def initialize(url) @titles = [] @url = url @http = nil setup_http manage_titles end def setup_http uri = URI(@url) @http = Net::HTTP.new(uri.host, uri.port) @http.use_ssl = true end def manage_titles body = request_properties body["content"].each { |property| @titles << property["title"] } @url = body["pagination"]["next_page"] manage_titles unless @url.nil? end def request_properties request = Net::HTTP::Get.new(URI(@url)) request["accept"] = 'application/json' request["X-Authorization"] = 'l7u502p8v46ba3ppgvj5y2aad50lb9' response = @http.request(request) JSON.parse(response.body) end end # Testing with native Minitest require "minitest/autorun" class TestApi < Minitest::Test def setup # Using class variable to run the api call only once per suite @@titles ||= EasyBrokerReader.new("https://api.stagingeb.com/v1/properties?limit=50").titles end def test_amount_of_records assert_equal 1107, @@titles.count end def test_first_title assert_equal 'Casa bien bonita', @@titles.first end end