Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 2.6.6
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ gem 'dry-validation', '~> 1.5.0'
gem 'activesupport', '~> 6.0.0', require: false
gem 'fast_jsonapi', '~> 1.5'

gem 'faraday'
gem 'faraday_middleware'

group :test do
gem 'rspec', '~> 3.9.0'
gem 'factory_bot', '~> 5.2.0'
Expand Down
29 changes: 29 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,37 @@ GEM
dry-schema (~> 1.5)
factory_bot (5.2.0)
activesupport (>= 4.2.0)
faraday (1.10.2)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday_middleware (1.2.0)
faraday (~> 1.0)
fast_jsonapi (1.5)
activesupport (>= 4.2)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
minitest (5.14.1)
multipart-post (2.2.3)
rake (13.0.1)
rspec (3.9.0)
rspec-core (~> 3.9.0)
Expand All @@ -75,6 +101,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
ruby2_keywords (0.0.5)
thread_safe (0.3.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)
Expand All @@ -90,6 +117,8 @@ DEPENDENCIES
dry-initializer (~> 3.0.3)
dry-validation (~> 1.5.0)
factory_bot (~> 5.2.0)
faraday
faraday_middleware
fast_jsonapi (~> 1.5)
i18n (~> 1.8.2)
rake (~> 13.0.1)
Expand Down
8 changes: 8 additions & 0 deletions app/lib/ads_service/api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module GeocoderService
module Api
def update_coordinates(id, coordinates)
payload = { id: id, coordinates: coordinates }.to_json
connection.post('update_coordinates', payload)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для обновления логичней было бы использовать patch.

end
end
end
22 changes: 22 additions & 0 deletions app/lib/ads_service/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'dry/initializer'
require_relative 'api'

module GeocoderService
class Client
extend Dry::Initializer[undefined: false]
include Api

option :url, default: proc { 'http://localhost:3000/ads/v1' }
option :connection, default: proc { build_connection }

private

def build_connection
Faraday.new(@url) do |conn|
conn.request :json
conn.response :json, content_type: /\bjson$/
conn.adapter Faraday.default_adapter
end
end
end
end
2 changes: 1 addition & 1 deletion app/lib/geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def load_data!
city = row['city']
lat = row['geo_lat'].to_f
lon = row['geo_lon'].to_f
result[city] = [lat, lon]
result[city] = { lat: lat, lon: lon }
result
end
end
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
coordinates = Geocoder.geocode(payload['city'])

if coordinates.present?
client = AdsService::RpcClient.fetch
client = GeocoderService::Client.new
client.update_coordinates(payload['id'], coordinates)
end

ensure
channel.ack(delivery_info.delivery_tag)
end