-
Notifications
You must be signed in to change notification settings - Fork 2
Service layer
cavalle edited this page Jan 7, 2013
·
1 revision
http://slides.jcoglan.com/di-eurucamp
class Services::ConcertsClient
def initialize(http_client)
@http = http_client
end
def find(id)
data = @http.get("/concerts/#{id}").json_data
Models::Concert.new(data)
end
endclass Models::Concert
def initialize(data)
@json_data = data
end
def name
@json_data['name']
end
def headliners
@json_data['performances'].
select { |p| p['billing'] == 'headline' }.
map { |p| Models::Artist.new(p['artist']) }
end
endmodule Services
def self.concerts
@concerts ||= begin
uri = 'http://concerts-service'
http = HTTPClient.new(uri)
ConcertsClient.new(http)
end
end
endconcert = Services.concerts.find(params[:id])