diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 490b187..4932502 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,8 +14,8 @@ jobs: strategy: matrix: ruby: - - "2.7" # Minimum supported version - - "3.2.4" + - "3.1" # Minimum supported version + - "3.2" - "3.3" - "ruby" # Latest stable version @@ -36,3 +36,4 @@ jobs: - uses: actions/setup-node@v4 - run: npm install -g ajv-cli - run: ajv -s lib/yellow_pages/merchants.schema.json -d lib/yellow_pages/merchants.yaml --errors=text + - run: ajv -s lib/yellow_pages/categories.schema.json -d lib/yellow_pages/categories.yaml --errors=text diff --git a/Gemfile.lock b/Gemfile.lock index d3813ff..351f97f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - yellow_pages (0.3.0) + yellow_pages (0.4.0) GEM remote: https://rubygems.org/ diff --git a/lib/yellow_pages.rb b/lib/yellow_pages.rb index aa80bec..c71c369 100644 --- a/lib/yellow_pages.rb +++ b/lib/yellow_pages.rb @@ -4,6 +4,7 @@ require_relative "yellow_pages/version" require_relative "yellow_pages/merchant" +require_relative "yellow_pages/category" module YellowPages class Error < StandardError; end diff --git a/lib/yellow_pages/categories.schema.json b/lib/yellow_pages/categories.schema.json new file mode 100644 index 0000000..34ace5a --- /dev/null +++ b/lib/yellow_pages/categories.schema.json @@ -0,0 +1,11 @@ +{ + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "key": { + "type": "string" + } + } +} diff --git a/lib/yellow_pages/categories.yaml b/lib/yellow_pages/categories.yaml new file mode 100644 index 0000000..8143197 --- /dev/null +++ b/lib/yellow_pages/categories.yaml @@ -0,0 +1,885 @@ +# yaml-language-server: $schema=categories.schema.json +# https://docs.stripe.com/issuing/categories +--- +7623: + key: ac_refrigeration_repair + name: A/C, Refrigeration Repair +8931: + key: accounting_bookkeeping_services + name: Accounting/Bookkeeping Services +7311: + key: advertising_services + name: Advertising Services +763: + key: agricultural_cooperative + name: Agricultural Cooperative +4511: + key: airlines_air_carriers + name: Airlines, Air Carriers +4582: + key: airports_flying_fields + name: Airports, Flying Fields +4119: + key: ambulance_services + name: Ambulance Services +7996: + key: amusement_parks_carnivals + name: Amusement Parks/Carnivals +5937: + key: antique_reproductions + name: Antique Reproductions +5932: + key: antique_shops + name: Antique Shops +7998: + key: aquariums + name: Aquariums +8911: + key: architectural_surveying_services + name: Architectural/Surveying Services +5971: + key: art_dealers_and_galleries + name: Art Dealers and Galleries +5970: + key: artists_supply_and_craft_shops + name: Artists Supply and Craft Shops +7531: + key: auto_body_repair_shops + name: Auto Body Repair Shops +7535: + key: auto_paint_shops + name: Auto Paint Shops +7538: + key: auto_service_shops + name: Auto Service Shops +5531: + key: auto_and_home_supply_stores + name: Auto and Home Supply Stores +6011: + key: automated_cash_disburse + name: Automated Cash Disburse +5542: + key: automated_fuel_dispensers + name: Automated Fuel Dispensers +8675: + key: automobile_associations + name: Automobile Associations +5533: + key: automotive_parts_and_accessories_stores + name: Automotive Parts and Accessories Stores +5532: + key: automotive_tire_stores + name: Automotive Tire Stores +9223: + key: bail_and_bond_payments + name: Bail and Bond Payments (payment to the surety for the bond, not the actual bond paid to the government agency) +5462: + key: bakeries + name: Bakeries +7929: + key: bands_orchestras + name: Bands, Orchestras +7230: + key: barber_and_beauty_shops + name: Barber and Beauty Shops +7995: + key: betting_casino_gambling + name: Betting/Casino Gambling +5940: + key: bicycle_shops + name: Bicycle Shops +7932: + key: billiard_pool_establishments + name: Billiard/Pool Establishments +5551: + key: boat_dealers + name: Boat Dealers +4457: + key: boat_rentals_and_leases + name: Boat Rentals and Leases +5942: + key: book_stores + name: Book Stores +5192: + key: books_periodicals_and_newspapers + name: Books, Periodicals, and Newspapers +7933: + key: bowling_alleys + name: Bowling Alleys +4131: + key: bus_lines + name: Bus Lines +8244: + key: business_secretarial_schools + name: Business/Secretarial Schools +7278: + key: buying_shopping_services + name: Buying/Shopping Services +4899: + key: cable_satellite_and_other_pay_television_and_radio + name: Cable, Satellite, and Other Pay Television and Radio +5946: + key: camera_and_photographic_supply_stores + name: Camera and Photographic Supply Stores +5441: + key: candy_nut_and_confectionery_stores + name: Candy, Nut, and Confectionery Stores +7512: + key: car_rental_agencies + name: Car Rental Agencies +7542: + key: car_washes + name: Car Washes +5511: + key: car_and_truck_dealers_new_used + name: Car and Truck Dealers (New & Used) Sales, Service, Repairs Parts and Leasing +5521: + key: car_and_truck_dealers_used_only + name: Car and Truck Dealers (Used Only) Sales, Service, Repairs Parts and Leasing +1750: + key: carpentry_services + name: Carpentry Services +7217: + key: carpet_upholstery_cleaning + name: Carpet/Upholstery Cleaning +5811: + key: caterers + name: Caterers +8398: + key: charitable_and_social_service_organizations_fundraising + name: Charitable and Social Service Organizations - Fundraising +5169: + key: chemicals_and_allied_products + name: Chemicals and Allied Products (Not Elsewhere Classified) +8351: + key: child_care_services + name: Child Care Services +5641: + key: childrens_and_infants_wear_stores + name: Childrens and Infants Wear Stores +8049: + key: chiropodists_podiatrists + name: Chiropodists, Podiatrists +8041: + key: chiropractors + name: Chiropractors +5993: + key: cigar_stores_and_stands + name: Cigar Stores and Stands +8641: + key: civic_social_fraternal_associations + name: Civic, Social, Fraternal Associations +7349: + key: cleaning_and_maintenance + name: Cleaning and Maintenance +7296: + key: clothing_rental + name: Clothing Rental +8220: + key: colleges_universities + name: Colleges, Universities +5046: + key: commercial_equipment + name: Commercial Equipment (Not Elsewhere Classified) +5139: + key: commercial_footwear + name: Commercial Footwear +7333: + key: commercial_photography_art_and_graphics + name: Commercial Photography, Art and Graphics +4111: + key: commuter_transport_and_ferries + name: Commuter Transport, Ferries +4816: + key: computer_network_services + name: Computer Network Services +7372: + key: computer_programming + name: Computer Programming +7379: + key: computer_repair + name: Computer Repair +5734: + key: computer_software_stores + name: Computer Software Stores +5045: + key: computers_peripherals_and_software + name: Computers, Peripherals, and Software +1771: + key: concrete_work_services + name: Concrete Work Services +5039: + key: construction_materials + name: Construction Materials (Not Elsewhere Classified) +7392: + key: consulting_public_relations + name: Consulting, Public Relations +8241: + key: correspondence_schools + name: Correspondence Schools +5977: + key: cosmetic_stores + name: Cosmetic Stores +7277: + key: counseling_services + name: Counseling Services +7997: + key: country_clubs + name: Country Clubs +4215: + key: courier_services + name: Courier Services +9211: + key: court_costs + name: Court Costs, Including Alimony and Child Support - Courts of Law +7321: + key: credit_reporting_agencies + name: Credit Reporting Agencies +4411: + key: cruise_lines + name: Cruise Lines +5451: + key: dairy_products_stores + name: Dairy Products Stores +7911: + key: dance_hall_studios_schools + name: Dance Hall, Studios, Schools +7273: + key: dating_escort_services + name: Dating/Escort Services +8021: + key: dentists_orthodontists + name: Dentists, Orthodontists +5311: + key: department_stores + name: Department Stores +7393: + key: detective_agencies + name: Detective Agencies +5815: + key: digital_goods_media + name: Digital Goods Media – Books, Movies, Music +5817: + key: digital_goods_applications + name: Digital Goods – Applications (Excludes Games) +5816: + key: digital_goods_games + name: Digital Goods – Games +5818: + key: digital_goods_large_volume + name: Digital Goods – Large Digital Goods Merchant +5964: + key: direct_marketing_catalog_merchant + name: Direct Marketing - Catalog Merchant +5965: + key: direct_marketing_combination_catalog_and_retail_merchant + name: Direct Marketing - Combination Catalog and Retail Merchant +5967: + key: direct_marketing_inbound_telemarketing + name: Direct Marketing - Inbound Telemarketing +5960: + key: direct_marketing_insurance_services + name: Direct Marketing - Insurance Services +5969: + key: direct_marketing_other + name: Direct Marketing - Other +5966: + key: direct_marketing_outbound_telemarketing + name: Direct Marketing - Outbound Telemarketing +5968: + key: direct_marketing_subscription + name: Direct Marketing - Subscription +5962: + key: direct_marketing_travel + name: Direct Marketing - Travel +5310: + key: discount_stores + name: Discount Stores +8011: + key: doctors + name: Doctors +5963: + key: door_to_door_sales + name: Door-To-Door Sales +5714: + key: drapery_window_covering_and_upholstery_stores + name: Drapery, Window Covering, and Upholstery Stores +5813: + key: drinking_places + name: Drinking Places +5912: + key: drug_stores_and_pharmacies + name: Drug Stores and Pharmacies +5122: + key: drugs_drug_proprietaries_and_druggist_sundries + name: Drugs, Drug Proprietaries, and Druggist Sundries +7216: + key: dry_cleaners + name: Dry Cleaners +5099: + key: durable_goods + name: Durable Goods (Not Elsewhere Classified) +5309: + key: duty_free_stores + name: Duty Free Stores +5812: + key: eating_places_restaurants + name: Eating Places, Restaurants +8299: + key: educational_services + name: Educational Services +5997: + key: electric_razor_stores + name: Electric Razor Stores +5552: + key: electric_vehicle_charging + name: Electric Vehicle Charging +5065: + key: electrical_parts_and_equipment + name: Electrical Parts and Equipment +1731: + key: electrical_services + name: Electrical Services +7622: + key: electronics_repair_shops + name: Electronics Repair Shops +5732: + key: electronics_stores + name: Electronics Stores +8211: + key: elementary_secondary_schools + name: Elementary, Secondary Schools +9702: + key: emergency_services_gcas_visa_use_only + name: Emergency Services (GCAS) (Visa use only) +7361: + key: employment_temp_agencies + name: Employment/Temp Agencies +7394: + key: equipment_rental + name: Equipment Rental +7342: + key: exterminating_services + name: Exterminating Services +5651: + key: family_clothing_stores + name: Family Clothing Stores +5814: + key: fast_food_restaurants + name: Fast Food Restaurants +6012: + key: financial_institutions + name: Financial Institutions +9222: + key: fines_government_administrative_entities + name: Fines - Government Administrative Entities +5718: + key: fireplace_fireplace_screens_and_accessories_stores + name: Fireplace, Fireplace Screens, and Accessories Stores +5713: + key: floor_covering_stores + name: Floor Covering Stores +5992: + key: florists + name: Florists +5193: + key: florists_supplies_nursery_stock_and_flowers + name: Florists Supplies, Nursery Stock, and Flowers +5422: + key: freezer_and_locker_meat_provisioners + name: Freezer and Locker Meat Provisioners +5983: + key: fuel_dealers_non_automotive + name: Fuel Dealers (Non Automotive) +7261: + key: funeral_services_crematories + name: Funeral Services, Crematories +7641: + key: furniture_repair_refinishing + name: Furniture Repair, Refinishing +5712: + key: furniture_home_furnishings_and_equipment_stores_except_appliances + name: Furniture, Home Furnishings, and Equipment Stores, Except Appliances +5681: + key: furriers_and_fur_shops + name: Furriers and Fur Shops +1520: + key: general_services + name: General Services +5947: + key: gift_card_novelty_and_souvenir_shops + name: Gift, Card, Novelty, and Souvenir Shops +5231: + key: glass_paint_and_wallpaper_stores + name: Glass, Paint, and Wallpaper Stores +5950: + key: glassware_crystal_stores + name: Glassware, Crystal Stores +7992: + key: golf_courses_public + name: Golf Courses - Public +7801: + key: government_licensed_online_casions_online_gambling_us_region_only # directly from Stripe's docs :-P + name: Government Licensed On-line Casinos (On-Line Gambling)(US Region only) +9399: + key: government_services + name: Government Services (Not Elsewhere Classified) +7802: + key: government_licensed_horse_dog_racing_us_region_only + name: Government-Licensed Horse/Dog Racing (US Region only) +9406: + key: government_owned_lotteries_non_us_region + name: Government-Owned Lotteries (Non-US region) +7800: + key: government_owned_lotteries_us_region_only + name: Government-Owned Lotteries (US Region only) +5411: + key: grocery_stores_supermarkets + name: Grocery Stores, Supermarkets +5251: + key: hardware_stores + name: Hardware Stores +5072: + key: hardware_equipment_and_supplies + name: Hardware, Equipment, and Supplies +7298: + key: health_and_beauty_spas + name: Health and Beauty Spas +5975: + key: hearing_aids_sales_and_supplies + name: Hearing Aids Sales and Supplies +1711: + key: heating_plumbing_a_c + name: Heating, Plumbing, A/C +5945: + key: hobby_toy_and_game_shops + name: Hobby, Toy, and Game Shops +5200: + key: home_supply_warehouse_stores + name: Home Supply Warehouse Stores +8062: + key: hospitals + name: Hospitals +7011: + key: hotels_motels_and_resorts + name: Hotels, Motels, and Resorts +5722: + key: household_appliance_stores + name: Household Appliance Stores +5085: + key: industrial_supplies + name: Industrial Supplies (Not Elsewhere Classified) +7375: + key: information_retrieval_services + name: Information Retrieval Services +6399: + key: insurance_default + name: Insurance - Default +6300: + key: insurance_underwriting_premiums + name: Insurance Underwriting, Premiums +9950: + key: intra_company_purchases + name: Intra-Company Purchases +5944: + key: jewelry_stores_watches_clocks_and_silverware_stores + name: Jewelry Stores, Watches, Clocks, and Silverware Stores +780: + key: landscaping_services + name: Landscaping Services +7211: + key: laundries + name: Laundries +7210: + key: laundry_cleaning_services + name: Laundry, Cleaning Services +8111: + key: legal_services_attorneys + name: Legal Services, Attorneys +5948: + key: luggage_and_leather_goods_stores + name: Luggage and Leather Goods Stores +5211: + key: lumber_building_materials_stores + name: Lumber, Building Materials Stores +6010: + key: manual_cash_disburse + name: Manual Cash Disburse +4468: + key: marinas_service_and_supplies + name: Marinas, Service and Supplies +5262: + key: marketplaces + name: Marketplaces +1740: + key: masonry_stonework_and_plaster + name: Masonry, Stonework, and Plaster +7297: + key: massage_parlors + name: Massage Parlors +8099: + key: medical_services + name: Medical Services +8071: + key: medical_and_dental_labs + name: Medical and Dental Labs +5047: + key: medical_dental_ophthalmic_and_hospital_equipment_and_supplies + name: Medical, Dental, Ophthalmic, and Hospital Equipment and Supplies +8699: + key: membership_organizations + name: Membership Organizations +5611: + key: mens_and_boys_clothing_and_accessories_stores + name: Mens and Boys Clothing and Accessories Stores +5691: + key: mens_womens_clothing_stores + name: Mens, Womens Clothing Stores +5051: + key: metal_service_centers + name: Metal Service Centers +5699: + key: miscellaneous_apparel_and_accessory_shops + name: Miscellaneous Apparel and Accessory Shops +5599: + key: miscellaneous_auto_dealers + name: Miscellaneous Auto Dealers +7399: + key: miscellaneous_business_services + name: Miscellaneous Business Services +5499: + key: miscellaneous_food_stores + name: Miscellaneous Food Stores - Convenience Stores and Specialty Markets +5399: + key: miscellaneous_general_merchandise + name: Miscellaneous General Merchandise +7299: + key: miscellaneous_general_services + name: Miscellaneous General Services +5719: + key: miscellaneous_home_furnishing_specialty_stores + name: Miscellaneous Home Furnishing Specialty Stores +2741: + key: miscellaneous_publishing_and_printing + name: Miscellaneous Publishing and Printing +7999: + key: miscellaneous_recreation_services + name: Miscellaneous Recreation Services +7699: + key: miscellaneous_repair_shops + name: Miscellaneous Repair Shops +5999: + key: miscellaneous_specialty_retail + name: Miscellaneous Specialty Retail +5271: + key: mobile_home_dealers + name: Mobile Home Dealers +7832: + key: motion_picture_theaters + name: Motion Picture Theaters +4214: + key: motor_freight_carriers_and_trucking + name: Motor Freight Carriers and Trucking - Local and Long Distance, Moving and Storage Companies, and Local Delivery Services +5592: + key: motor_homes_dealers + name: Motor Homes Dealers +5013: + key: motor_vehicle_supplies_and_new_parts + name: Motor Vehicle Supplies and New Parts +5571: + key: motorcycle_shops_and_dealers + name: Motorcycle Shops and Dealers +5561: + key: motorcycle_shops_dealers + name: Motorcycle Shops, Dealers +5733: + key: music_stores_musical_instruments_pianos_and_sheet_music + name: Music Stores-Musical Instruments, Pianos, and Sheet Music +5994: + key: news_dealers_and_newsstands + name: News Dealers and Newsstands +6051: + key: non_fi_money_orders + name: Non-FI, Money Orders +6540: + key: non_fi_stored_value_card_purchase_load + name: Non-FI, Stored Value Card Purchase/Load +5199: + key: nondurable_goods + name: Nondurable Goods (Not Elsewhere Classified) +5261: + key: nurseries_lawn_and_garden_supply_stores + name: Nurseries, Lawn and Garden Supply Stores +8050: + key: nursing_personal_care + name: Nursing/Personal Care +5021: + key: office_and_commercial_furniture + name: Office and Commercial Furniture +8043: + key: opticians_eyeglasses + name: Opticians, Eyeglasses +8042: + key: optometrists_ophthalmologist + name: Optometrists, Ophthalmologist +5976: + key: orthopedic_goods_prosthetic_devices + name: Orthopedic Goods - Prosthetic Devices +8031: + key: osteopaths + name: Osteopaths +5921: + key: package_stores_beer_wine_and_liquor + name: Package Stores-Beer, Wine, and Liquor +5198: + key: paints_varnishes_and_supplies + name: Paints, Varnishes, and Supplies +7523: + key: parking_lots_garages + name: Parking Lots, Garages +4112: + key: passenger_railways + name: Passenger Railways +5933: + key: pawn_shops + name: Pawn Shops +5995: + key: pet_shops_pet_food_and_supplies + name: Pet Shops, Pet Food, and Supplies +5172: + key: petroleum_and_petroleum_products + name: Petroleum and Petroleum Products +7395: + key: photo_developing + name: Photo Developing +7221: + key: photographic_studios + name: Photographic Studios +5044: + key: photographic_photocopy_microfilm_equipment_and_supplies + name: Photographic, Photocopy, Microfilm Equipment, and Supplies +7829: + key: picture_video_production + name: Picture/Video Production +5131: + key: piece_goods_notions_and_other_dry_goods + name: Piece Goods, Notions, and Other Dry Goods +5074: + key: plumbing_heating_equipment_and_supplies + name: Plumbing, Heating Equipment, and Supplies +8651: + key: political_organizations + name: Political Organizations +9402: + key: postal_services_government_only + name: Postal Services - Government Only +5094: + key: precious_stones_and_metals_watches_and_jewelry + name: Precious Stones and Metals, Watches and Jewelry +8999: + key: professional_services + name: Professional Services +4225: + key: public_warehousing_and_storage + name: Public Warehousing and Storage - Farm Products, Refrigerated Goods, Household Goods, and Storage +7338: + key: quick_copy_repro_and_blueprint + name: Quick Copy, Repro, and Blueprint +4011: + key: railroads + name: Railroads +6513: + key: real_estate_agents_and_managers_rentals + name: Real Estate Agents and Managers - Rentals +5735: + key: record_stores + name: Record Stores +7519: + key: recreational_vehicle_rentals + name: Recreational Vehicle Rentals +5973: + key: religious_goods_stores + name: Religious Goods Stores +8661: + key: religious_organizations + name: Religious Organizations +1761: + key: roofing_siding_sheet_metal + name: Roofing/Siding, Sheet Metal +7339: + key: secretarial_support_services + name: Secretarial Support Services +6211: + key: security_brokers_dealers + name: Security Brokers/Dealers +5541: + key: service_stations + name: Service Stations +5949: + key: sewing_needlework_fabric_and_piece_goods_stores + name: Sewing, Needlework, Fabric, and Piece Goods Stores +7251: + key: shoe_repair_hat_cleaning + name: Shoe Repair/Hat Cleaning +5661: + key: shoe_stores + name: Shoe Stores +7629: + key: small_appliance_repair + name: Small Appliance Repair +5598: + key: snowmobile_dealers + name: Snowmobile Dealers +1799: + key: special_trade_services + name: Special Trade Services +2842: + key: specialty_cleaning + name: Specialty Cleaning +5941: + key: sporting_goods_stores + name: Sporting Goods Stores +7032: + key: sporting_recreation_camps + name: Sporting/Recreation Camps +7941: + key: sports_clubs_fields + name: Sports Clubs/Fields +5655: + key: sports_and_riding_apparel_stores + name: Sports and Riding Apparel Stores +5972: + key: stamp_and_coin_stores + name: Stamp and Coin Stores +5111: + key: stationary_office_supplies_printing_and_writing_paper + name: Stationary, Office Supplies, Printing and Writing Paper +5943: + key: stationery_stores_office_and_school_supply_stores + name: Stationery Stores, Office, and School Supply Stores +5996: + key: swimming_pools_sales + name: Swimming Pools Sales +4723: + key: t_ui_travel_germany + name: TUI Travel - Germany +5697: + key: tailors_alterations + name: Tailors, Alterations +9311: + key: tax_payments_government_agencies + name: Tax Payments - Government Agencies +7276: + key: tax_preparation_services + name: Tax Preparation Services +4121: + key: taxicabs_limousines + name: Taxicabs/Limousines +4812: + key: telecommunication_equipment_and_telephone_sales + name: Telecommunication Equipment and Telephone Sales +4814: + key: telecommunication_services + name: Telecommunication Services +4821: + key: telegraph_services + name: Telegraph Services +5998: + key: tent_and_awning_shops + name: Tent and Awning Shops +8734: + key: testing_laboratories + name: Testing Laboratories +7922: + key: theatrical_ticket_agencies + name: Theatrical Ticket Agencies +7012: + key: timeshares + name: Timeshares +7534: + key: tire_retreading_and_repair + name: Tire Retreading and Repair +4784: + key: tolls_bridge_fees + name: Tolls/Bridge Fees +7991: + key: tourist_attractions_and_exhibits + name: Tourist Attractions and Exhibits +7549: + key: towing_services + name: Towing Services +7033: + key: trailer_parks_campgrounds + name: Trailer Parks, Campgrounds +4789: + key: transportation_services + name: Transportation Services (Not Elsewhere Classified) +4722: + key: travel_agencies_tour_operators + name: Travel Agencies, Tour Operators +7511: + key: truck_stop_iteration + name: Truck Stops +7513: + key: truck_utility_trailer_rentals + name: Truck/Utility Trailer Rentals +2791: + key: typesetting_plate_making_and_related_services + name: Typesetting, Plate Making, and Related Services +5978: + key: typewriter_stores + name: Typewriter Stores +9405: + key: u_s_federal_government_agencies_or_departments + name: U.S. Federal Government Agencies or Departments +5137: + key: uniforms_commercial_clothing + name: Uniforms, Commercial Clothing +5931: + key: used_merchandise_and_secondhand_stores + name: Used Merchandise and Secondhand Stores +4900: + key: utilities + name: Utilities +5331: + key: variety_stores + name: Variety Stores +742: + key: veterinary_services + name: Veterinary Services +7993: + key: video_amusement_game_supplies + name: Video Amusement Game Supplies +7994: + key: video_game_arcades + name: Video Game Arcades +7841: + key: video_tape_rental_stores + name: Video Tape Rental Stores +8249: + key: vocational_trade_schools + name: Vocational/Trade Schools +7631: + key: watch_jewelry_repair + name: Watch/Jewelry Repair +7692: + key: welding_repair + name: Welding Repair +5300: + key: wholesale_clubs + name: Wholesale Clubs +5698: + key: wig_and_toupee_stores + name: Wig and Toupee Stores +4829: + key: wires_money_orders + name: Wires, Money Orders +5631: + key: womens_accessory_and_specialty_shops + name: Womens Accessory and Specialty Shops +5621: + key: womens_ready_to_wear_stores + name: Womens Ready-To-Wear Stores +5935: + key: wrecking_and_salvage_yards + name: Wrecking and Salvage Yards diff --git a/lib/yellow_pages/category.rb b/lib/yellow_pages/category.rb new file mode 100644 index 0000000..2d8b93c --- /dev/null +++ b/lib/yellow_pages/category.rb @@ -0,0 +1,80 @@ +# Read category.yaml + +require "yaml" +require "pathname" + +module YellowPages + class Category + # @return [Hash] all categories keyed by their MCC code + def self.categories_by_code + @categories_by_code ||= + begin + path = Pathname.new(__dir__).join("categories.yaml") + YAML.load_file(path).map do |code, obj| + [code.to_s, obj.merge(code:).transform_keys(&:to_sym)] + end.to_h + end + end + + # @return [Hash] all categories keyed by their stripe key + def self.categories_by_key + @categories_by_key ||= + begin + categories_by_code.map do |code, obj| + [obj.fetch(:key), obj] + end.to_h + end + end + + # Pre-compile on boot/gem require + categories_by_code + categories_by_key + + def initialize(code: nil, key: nil) + raise ArgumentError, "Either code or key must be provided" if code.nil? && key.nil? + + @code, @key = code, key + end + + def self.lookup(...) + new(...) + end + + # Returns category's code + # + # @return [String, nil] the code of the category, if found + def code + category&.fetch(:code) + end + + # Returns category's name + # + # @return [String, nil] the name of the category, if found + def name + category&.fetch(:name) + end + + # Returns category's key + # + # @return [String, nil] the key of the category, if found + def key + category&.fetch(:key) + end + + # Returns true if the category is in the dataset + # @return [Boolean] whether the category is in our dataset + def in_dataset? + !category.nil? + end + + private + + def category + if @code.nil? + self.class.categories_by_key[@key] + else + self.class.categories_by_code[@code] + end + end + end +end diff --git a/lib/yellow_pages/merchant.rb b/lib/yellow_pages/merchant.rb index 5fccd72..2d0f1ab 100644 --- a/lib/yellow_pages/merchant.rb +++ b/lib/yellow_pages/merchant.rb @@ -26,6 +26,9 @@ def self.merchants end end + # Pre-compile on boot/gem require + merchants + def initialize(network_id:) @network_id = network_id diff --git a/lib/yellow_pages/version.rb b/lib/yellow_pages/version.rb index bc8f015..ca0c1d1 100644 --- a/lib/yellow_pages/version.rb +++ b/lib/yellow_pages/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module YellowPages - VERSION = "0.3.0" + VERSION = "0.4.0" end diff --git a/spec/yellow_pages/category_spec.rb b/spec/yellow_pages/category_spec.rb new file mode 100644 index 0000000..0603543 --- /dev/null +++ b/spec/yellow_pages/category_spec.rb @@ -0,0 +1,96 @@ +RSpec.describe YellowPages::Category do + it "exists" do + expect(YellowPages::Category).not_to be nil + end + + describe "::lookup" do + it "initializes a new category by MCC" do + category = YellowPages::Category.lookup(code: "5598") + expect(category).to be_a YellowPages::Category + end + it "initializes a new category by Stripe code" do + category = YellowPages::Category.lookup(key: "government_licensed_horse_dog_racing_us_region_only") + expect(category).to be_a YellowPages::Category + end + it "throws an error if neither a key nor a code is provided" do + expect { + YellowPages::Category.lookup(key: nil, code: nil) + }.to raise_error(ArgumentError) + end + end + + describe "::categories_by_code" do + it "returns a hash of categories keyed by their MCC codes" do + categories = YellowPages::Category.categories_by_code + expect(categories).to be_a Hash + expect(categories.keys).to include("8699") + expect(categories["8699"].keys).to include(:key, :name) + end + end + + describe "::categories_by_key" do + it "returns a hash of categories keyed by their Stripe names" do + categories = YellowPages::Category.categories_by_key + expect(categories).to be_a Hash + expect(categories.keys).to include("telegraph_services") + expect(categories["telegraph_services"].keys).to include(:key, :name) + end + end + + describe "#name" do + context "when category is found" do + it "returns the category's name" do + category = YellowPages::Category.new(key: "typewriter_stores") + expect(category.name).to eq("Typewriter Stores") + end + end + + context "when category is not found" do + it "returns nil" do + category = YellowPages::Category.new(key: "illicit_goods_and_activities") + expect(category.name).to be nil + + category = YellowPages::Category.new(key: "") + expect(category.name).to be nil + end + end + end + + describe "#key" do + context "when category is found" do + it "returns the category's key" do + category = YellowPages::Category.new(code: "5681") + expect(category.key).to eq("furriers_and_fur_shops") + end + end + + context "when category is not found" do + it "returns nil" do + category = YellowPages::Category.new(code: "42069") + expect(category.key).to be nil + end + end + end + + describe "#in_dataset?" do + context "when not in dataset" do + it "returns false" do + category = YellowPages::Category.new(code: "31337") + expect(category.in_dataset?).to be false + + category = YellowPages::Category.new(key: "horse_annihilation_services") + expect(category.in_dataset?).to be false + end + end + + context "when in dataset" do + it "returns true" do + category = YellowPages::Category.new(code: "7251") + expect(category.in_dataset?).to be true + + category = YellowPages::Category.new(key: "video_tape_rental_stores") + expect(category.in_dataset?).to be true + end + end + end +end diff --git a/yellow_pages.gemspec b/yellow_pages.gemspec index b4bb5e9..fafb859 100644 --- a/yellow_pages.gemspec +++ b/yellow_pages.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| # spec.description = "TODO: Write a longer description or delete this line." spec.homepage = "https://github.com/hackclub/yellow_pages" spec.license = "MIT" - spec.required_ruby_version = ">= 2.7.0" + spec.required_ruby_version = ">= 3.1.0" spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"