Class: RateCenter::DataSource::SimpleMaps::Client
- Inherits:
-
Object
- Object
- RateCenter::DataSource::SimpleMaps::Client
- Defined in:
- lib/rate_center/data_source/simple_maps.rb
Constant Summary collapse
- HOST =
"https://simplemaps.com/".freeze
- DATA_FILES =
{ us: OpenStruct.new( path: "static/data/us-cities/1.79/basic/simplemaps_uscities_basicv1.79.zip", database_filename: "uscities.csv", ), ca: OpenStruct.new( path: "static/data/canada-cities/1.8/basic/simplemaps_canadacities_basicv1.8.zip", database_filename: "canadacities.csv" ) }.freeze
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#response_parser ⇒ Object
readonly
Returns the value of attribute response_parser.
Instance Method Summary collapse
- #fetch_data(**options) ⇒ Object
-
#initialize(**options) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(**options) ⇒ Client
Returns a new instance of Client.
52 53 54 55 56 |
# File 'lib/rate_center/data_source/simple_maps.rb', line 52 def initialize(**) @host = .fetch(:host, HOST) @http_client = .fetch(:http_client) { default_http_client } @response_parser = .fetch(:response_parser) { ResponseParser.new } end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
50 51 52 |
# File 'lib/rate_center/data_source/simple_maps.rb', line 50 def host @host end |
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
50 51 52 |
# File 'lib/rate_center/data_source/simple_maps.rb', line 50 def http_client @http_client end |
#response_parser ⇒ Object (readonly)
Returns the value of attribute response_parser.
50 51 52 |
# File 'lib/rate_center/data_source/simple_maps.rb', line 50 def response_parser @response_parser end |
Instance Method Details
#fetch_data(**options) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/rate_center/data_source/simple_maps.rb', line 58 def fetch_data(**) path = .fetch(:path) { DATA_FILES.fetch(.fetch(:country)).path } database_filename = .fetch(:database_filename) { DATA_FILES.fetch(.fetch(:country)).database_filename } uri = URI(path) response = http_client.get(uri) response_parser.parse(response.body, database_filename:) end |