Last active
December 19, 2023 19:31
-
-
Save MarinGarcia/4db8e55025e35e164f5bda027c8752e8 to your computer and use it in GitHub Desktop.
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
# frozen_string_literal: true | |
class EasyBroker::Request | |
def initialize(app_key = nil, country_code = nil) | |
@app_key = app_key | |
@url = Rails.env.production? ? 'https://api.easybroker.com/v1/' : EasyBroker::STAGING_API_ROOT_URL | |
@country_code = country_code | |
initialize_parameters | |
end | |
def property_titles | |
results = fetch_properties | |
titles = results.map { |property| property.title } | |
titles | |
end | |
private | |
attr_reader :app_key, :url, :country_code | |
def fetch_properties | |
client.properties | |
end | |
def client | |
@client ||= EasyBroker.client | |
end | |
def initialize_parameters | |
EasyBroker::Config.api_key = app_key || ENV.fetch('EASY_BROKER_KEY') | |
EasyBroker::Config.api_root_url = url | |
EasyBroker::Config.country_code = country_code || 'MX' | |
end | |
end |
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
# frozen_string_literal: true | |
require 'rails_helper' | |
RSpec.describe EasyBroker::Request do | |
subject { described_class.new(api_key, country_code) } | |
let(:api_key) { 'test_api_key' } | |
describe '#fetch_properties' do | |
context 'when country_code is US' do | |
let(:country_code) { 'US' } | |
it "returns List properties" do | |
expect(subject.titles_properties).to be(["title1", "title2", "title3"]) | |
end | |
end | |
context 'when country_code is MX' do | |
it "returns List properties" do | |
expect(subject.titles_properties).to be(["title1", "title2", "title3"]) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment