Module: YellowApi::Client::GetBusinessDetails

Included in:
YellowApi::Client
Defined in:
lib/yellow_api/client/get_business_details.rb

Constant Summary

PROVINCE_ABBREVIATION_MAP =
{
  :ab => "Alberta",
  :bc => "British-Columbia",
  :mb => "Manitoba",
  :nb => "New-Brunswick",
  :nl => "Newfoundland-and-Labrador",
  :nt => "Northwest-Territories",
  :ns => "Nova-Scotia",
  :nu => "Nunavut",
  :on => "Ontario",
  :pe => "Prince-Edward-Island",
  :qc => "Quebec",
  :sk => "Saskatchewan",
  :yt => "Yukon"
}

Instance Method Summary collapse

Instance Method Details

#expand_province(prov) ⇒ Object

Expands an abbreviated province

This handles the fact that FindBusiness returns abbreviated provinces codes yet expects full province names for GetBusinessDetails



66
67
68
# File 'lib/yellow_api/client/get_business_details.rb', line 66

def expand_province(prov)
  PROVINCE_ABBREVIATION_MAP.fetch(prov.downcase.to_sym, prov)
end

#get_business_details(province, business_name, listing_id, options = {}) ⇒ Hash

Note:

Requires a FindBusiness call first.

Gets business details.

Information returned on this first call provides the necessary information for the GetBusinessDetails call. If not available, use "Canada"

Examples:

YellowApi.get_business_details("Ile-du-Prince-Edouard", "Co-operators-The", 6418182)

Options Hash (options):

  • :city (String)

    The city location of the business

  • :lang (String)

    en - English (default), fr - French

See Also:



40
41
42
43
44
45
46
47
# File 'lib/yellow_api/client/get_business_details.rb', line 40

def get_business_details(province, business_name, listing_id, options={})
  options[:prov] = normalize(expand_province(province))
  options["bus-name"] = normalize(business_name)
  options[:listingId] = listing_id
  options[:city] = normalize(options[:city]) if options.has_key? :city

  get('/GetBusinessDetails/', options)
end

#normalize(s) ⇒ Object

Normalizes a given string

All accents are removed (i.e. ???????? becomes ???a???), and All non-alphanumeric characters are replaced by dash ???-???, and Multiple dashes are replaced by a single dash.



57
58
59
60
# File 'lib/yellow_api/client/get_business_details.rb', line 57

def normalize(s)
  s.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n, '').to_s
    .gsub(/[\W]/, '-').gsub(/-+/, '-')
end