app/models/service_api_search.rb
# get back data of services, parse them into uniform results that can be mapped in front end
get back data of services, parse them into uniform results that can be mapped in front end
get back data of services parse them into uniform results that can be mapped in front end
def parse_service_objects
        services_array = create_service_objects
        services = if services_array
            services_array.map { |service| 
            name = service[:name].downcase
            case 
            when name.include?("netflix")
                service[:name] = "Netflix"
                p service
            when name.include?("itunes")
                service[:name]= "iTunes"
                p service
            when name.include?("amazon")
                p service[:name] = "Amazon"
                p service
            when name.include?("google play")
                p service
            when name.include?("disney")
                service[:name] = "DisneyPlus"
                p service
            when name == "iva"
                p nil
            else
                service[:name] =  "other"
                p service
            end
        }
        end 
        if services 
            services = services.compact
            services = services.uniq{ |service| service[:name]}
        end
        p services
    end
def parse_service_objects services_array = create_service_objects services = if services_array services_array . map { | service | name = service [ :name ] . downcase case when name . include? ( "netflix" ) service [ :name ] = "Netflix" p service when name . include? ( "itunes" ) service [ :name ] = "iTunes" p service when name . include? ( "amazon" ) p service [ :name ] = "Amazon" p service when name . include? ( "google play" ) p service when name . include? ( "disney" ) service [ :name ] = "DisneyPlus" p service when name == "iva" p nil else service [ :name ] = "other" p service end } end if services services = services . compact services = services . uniq { | service | service [ :name ] } end p services end
get back data of services, parse them into uniform results that can be mapped in front end
get back data of services parse them into uniform results that can be mapped in front end
# services_array = [{:name=> "iTunes", :url=> "https://itunes.apple.com/za/movie/casino-royale/id561902712"}, {:name=> "Google Play", :url=> "https://play.google.com/store/movies/details/Casino_Royale?gl=GB&hl=en&id=deA2fR9iFZw"}, {:name=> "iTunes", :url=> "https://itunes.apple.com/gb/movie/casino-royale/id561902712"}, {:name=> "IVA", :url=> nil }] # if there are services (not nil) # tidy up remove nil and duplicates