Class: Campgrounds::CampgroundSearch

Inherits:
Base
  • Object
show all
Defined in:
lib/campgrounds/campground_search.rb

Constant Summary collapse

Path =
'/campgrounds'

Instance Attribute Summary

Attributes inherited from Base

#api_key

Instance Method Summary collapse

Methods inherited from Base

#campground_details, #campground_search, #campsite_search, #initialize, #query

Constructor Details

This class inherits a constructor from Campgrounds::Base

Instance Method Details

#allObject

Retrieve all campgrounds.



7
8
9
# File 'lib/campgrounds/campground_search.rb', line 7

def all
  query(Path)
end

#find(options = {}) ⇒ Object

A cleaned up version of the request method below. Updated to use strings or boolean values instead of varius numbers.

Optional Parameters


landmarkLat: landmarkLong: These two parameters allow for campground searches around a fixed geo-point.

siteType: If unspecified, all site types are returned.

"rv": RV Sites
"cabin": Cabins or Lodgings
"tent": Tent
"trailer": Trailer
"group": Group Site
"day": Day Use
"horse": Horse Site
"boat": Boat Site

pstate: The two character abbreviation for US state, Canadian province or territory pname: Park Name arvDate: Arrival Date lengthOfStay: When combined with arvDate, this parameter determines how long the camper would like to reserve the campground.

amenity: Campground Feature. Only one amenity can be specified per query. Specifying amenity=4004, for example, returns campgrounds with fishing.

Biking  4001
Boating 4002
Equipment Rental  4003
Fishing 4004
Golf  4005
Hiking  4006
Horseback Riding  4007
Hunting 4008
Recreational Activities 4009
Scenic Trails 4010
Sports  4011
Beach/Water Activities  4012
Winter Activities 4013

eqpLen: Equipment Length maxPeople: Number of campers

The following params seem to search correctly, though the results such as ‘sitesWithAmps’ may not return the expected results. It looks like some people put this info in the description field rather than the various Y/N fields. hookup: Electric Hookup

"15+": 15 Amps or More
"20+": 20 Amps or More 
"30+": 30 Amps or More 
"50+": 50 Amps or More

water: Water Hookup. Boolean. sewer: Sewer Hookup. Boolean. pull: Pull Through Driveway. Boolean. pets: Pets Allowed. Boolean. waterfront: Waterfront Sites. Boolean.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/campgrounds/campground_search.rb', line 65

def find(options={})
    case options[:siteType]
        when "rv"
            options[:siteType] = 2001
        when "cabin"
            options[:siteType] = 10001
        when "tent"
            options[:siteType] = 2003
        when "trailer"
            options[:siteType] = 2002
        when "group"
            options[:siteType] = 9002
        when "day"
            options[:siteType] = 9001
        when "horse"
            options[:siteType] = 3001
        when "boat"
            options[:siteType] = 2004
    end

    case options[:amenity]
        when "biking"
            options[:amenity] = 4001
        when "boating"
            options[:amenity] = 4002
        when "equipment rental"
            options[:amenity] = 4003
        when "fishing"
            options[:amenity] = 4004
        when "golf"
            options[:amenity] = 4005
        when "hiking"
            options[:amenity] = 4006
        when "horseback riding"
            options[:amenity] = 4007
        when "hunting"
            options[:amenity] = 4008
        when "recreational activities"
            options[:amenity] = 4009
        when "scenic trails"
            options[:amenity] = 4010
        when "sports"
            options[:amenity] = 4011
        when "beach/water activities"
            options[:amenity] = 4012
        when "winter activities"
            options[:amenity] = 4013
    end

    case options[:hookup]
        when "15+"
            options[:hookup] = 3002
        when "20+"
            options[:hookup] = 3003
        when "30+"
            options[:hookup] = 3004
        when "50+"
            options[:hookup] = 3005
    end

    options[:water] = 3006 if options[:water]
    options[:sewer] = 3007 if options[:sewer]
    options[:pull] = 3008 if options[:pull]
    options[:pets] = 3010 if options[:pets]
    options[:waterfront] = 3011 if options[:waterfront]

    # Might return results array at some point, but returning the wrapper for now to keep results similar to default.
    return query(Path, options)
end

#find_by_address(address, range = 1000, options = {}) ⇒ Object

Search for campgrounds with an address string and optional range in miles. The address could be a street address, city and state, etc. Uses the find method so you can pass strings/booleans



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/campgrounds/campground_search.rb', line 137

def find_by_address(address, range=1000, options={})
    coords = MultiGeocoder.geocode(address)
    options[:landmarkName] = true
    options[:landmarkLat] = coords.lat
    options[:landmarkLong] = coords.lng

    results = find(options)

    results['result'].each do |c|
        lat = c['latitude']
        long = c['longitude']
        c['distance'] = coords.distance_to([lat,long])
    end
    results['result'].delete_if {|k, v| k['distance'] >= range }

    return results
end

#request(options = {}) ⇒ Object



211
212
213
# File 'lib/campgrounds/campground_search.rb', line 211

def request(options={})
  query(Path, options)
end