Class: MusicTodayApiWrapper::Services::ProductServices

Inherits:
Object
  • Object
show all
Defined in:
lib/services/product_services.rb

Instance Method Summary collapse

Constructor Details

#initializeProductServices

Returns a new instance of ProductServices.



7
8
9
10
11
# File 'lib/services/product_services.rb', line 7

def initialize
  @common_response =
    MusicTodayApiWrapper::RestClients::CommonResponse.new
  @rest_client = MusicTodayApiWrapper::RestClient.new
end

Instance Method Details

#all_products(per_page = 1000, page_number = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/services/product_services.rb', line 13

def all_products(per_page = 1000, page_number = nil)
  results = @rest_client.all_products(per_page, page_number)
  return results unless results.success?

  @common_response.data[:products] = []
  @common_response.work do
    results.data[:products].each { |product| product_mapper(product) }
  end
end

#find_product(id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/services/product_services.rb', line 23

def find_product(id)
  results = @rest_client.find_product(id)
  return results unless results.success?

  @common_response.work do
    @common_response.data[:product] =
      MusicTodayApiWrapper::Resources::Product
      .from_hash(results.data[:product])
  end
end