supercamp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8febad2fae0ba82c928a3fde98a0e6032d9f14b6
4
+ data.tar.gz: 2641fdcc51a40cf1755a1da6f97930386a9654e5
5
+ SHA512:
6
+ metadata.gz: 2351f837d0c80a1be178bfe9c3d45c264284361f8e576b52b437feabcc1e274edfcd68f883ffdf306fbaa88b98c792812cd4083ca1e5b8bf620a0f36c5f05cc2
7
+ data.tar.gz: 3f5ef2f2617a53108c8dfa98776c81fdae8a7a4d0fce59d721d69fbab52169341746dc3b1d0a92a12a32fc629bfde28571816a52577747eb1fff7777b0138c1e
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /.env
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 2.1.4@supercamp" > .rvmrc
9
+ environment_id="ruby-2.1.4@supercamp"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.26.0 (master)" # 1.10.1 seems like a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
27
+ do
28
+ if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
29
+ then \. "${__hook}" || true
30
+ fi
31
+ done
32
+ unset __hook
33
+ if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
34
+ then
35
+ if [[ $- == *i* ]] # check for interactive shells
36
+ then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)
37
+ " # show the user the ruby and gemset they are using in green
38
+ else printf "%b" "Using: $GEM_HOME
39
+ " # don't use colors in non-interactive shells
40
+ fi
41
+ fi
42
+ else
43
+ # If the environment file has not yet been created, use the RVM CLI to select.
44
+ rvm --create "$environment_id" || {
45
+ echo "Failed to create RVM environment '${environment_id}'."
46
+ return 1
47
+ }
48
+ fi
49
+
50
+ # If you use bundler, this might be useful to you:
51
+ # if [[ -s Gemfile ]] && {
52
+ # ! builtin command -v bundle >/dev/null ||
53
+ # builtin command -v bundle | GREP_OPTIONS=""
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in supercamp.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Dave Krupinski
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Supercamp
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'supercamp'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install supercamp
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/supercamp/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color', '--format', 'nested']
8
+ end
9
+
10
+ task default: :spec
@@ -0,0 +1,22 @@
1
+ module Supercamp
2
+
3
+ class Configuration
4
+
5
+ attr_accessor :api_key
6
+ attr_accessor :timeout
7
+
8
+ def initialize
9
+ @timeout ||= 5
10
+ end
11
+
12
+ def configure
13
+ yield self
14
+ end
15
+
16
+ def base_url
17
+ "http://api.amp.active.com/camping"
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,53 @@
1
+ module Supercamp
2
+ module Criteria
3
+
4
+ class Abstract
5
+
6
+ attr_accessor :options
7
+
8
+ def initialize(&block)
9
+ @options = {}
10
+ instance_eval(&block) if block_given?
11
+ end
12
+
13
+ class << self
14
+
15
+ def search(&block)
16
+ new &block
17
+ end
18
+
19
+ end
20
+
21
+ def search(&block)
22
+ self.class.search &block
23
+ end
24
+
25
+ def endpoint
26
+ name = self.class.to_s.split("::").last.downcase
27
+ "#{Supercamp.config.base_url}/#{name}s"
28
+ end
29
+
30
+ def query
31
+ opts = { api_key: Supercamp.config.api_key }.merge(options)
32
+ Typhoeus::Request.new(endpoint, timeout: Supercamp.config.timeout, params: opts)
33
+ end
34
+
35
+ def response(query=query)
36
+ response = query.run
37
+ if response.code == 200
38
+ Supercamp::Response.new response
39
+ else
40
+ raise Supercamp::Error.new self, response
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def merge_option(key, value)
47
+ @options[key.to_s] = value
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,87 @@
1
+ module Supercamp
2
+ module Criteria
3
+
4
+ class Campground < Campsite
5
+
6
+ AMENITIES = {
7
+ "biking" => 4001,
8
+ "boating" => 4002,
9
+ "equipment_rentals" => 4003,
10
+ "fishing" => 4004,
11
+ "golf" => 4005,
12
+ "hiking" => 4006,
13
+ "horseback_riding" => 4007,
14
+ "hunting" => 4008,
15
+ "rec_activities" => 4009,
16
+ "scenic_trails" => 4010,
17
+ "sports" => 4011,
18
+ "beach_or_water" => 4012,
19
+ "winter_activities" => 4013
20
+ }
21
+
22
+ # landmarkLat, landmarkLong (latitude/longitude)
23
+ #
24
+ # These two parameters allow for campground searches around a fixed geo-point.
25
+ #
26
+ def geo(lat, lng)
27
+ merge_option("landmarkLat", lat)
28
+ merge_option("landmarkLong", lng)
29
+ self
30
+ end
31
+
32
+
33
+ # pstate: State or Province
34
+ #
35
+ # The two character abbreviation for US state
36
+ #
37
+ def state(abbr)
38
+ merge_option(:pstate, abbr)
39
+ self
40
+ end
41
+
42
+
43
+ # pname: Park Name
44
+ #
45
+ # The name of the park. When this parameter is specified,
46
+ # the API performs a string-match query for parks containing
47
+ # the character string specified.
48
+ #
49
+ def name(city)
50
+ merge_option(:pname, city)
51
+ self
52
+ end
53
+
54
+
55
+ # amenity: Campground Feature
56
+ #
57
+ # There are all sorts of things to do at campgrounds.
58
+ # Only one amenity can be specified per query.
59
+ #
60
+ def amenity(key)
61
+ code = AMENITIES.fetch(key.to_s)
62
+ merge_option(:amenity, code)
63
+ self
64
+ end
65
+
66
+
67
+ # has: Campture Features
68
+ #
69
+ # Specify 1 or more optional perks:
70
+ # # water
71
+ # # sewer
72
+ # # pull
73
+ # # pets
74
+ # # waterfront
75
+ #
76
+ def has(*perks)
77
+ perks.each do |perk|
78
+ next unless PERKS.has_key?(perk.to_s)
79
+ merge_option(perk, PERKS[perk.to_s])
80
+ end
81
+ self
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,99 @@
1
+ module Supercamp
2
+ module Criteria
3
+
4
+ class Campsite < Abstract
5
+
6
+ TYPES = {
7
+ "rv" => 2001,
8
+ "cabin" => 10001,
9
+ "lodging" => 10001,
10
+ "tent" => 2003,
11
+ "trailer" => 2002,
12
+ "group_site" => 9002,
13
+ "day_use" => 9001,
14
+ "horse_site" => 3001,
15
+ "boat_site" => 2004
16
+ }
17
+
18
+ PERKS = {
19
+ "water" => 3007,
20
+ "sewer" => 3007,
21
+ "pull" => 3008,
22
+ "pets" => 3010,
23
+ "waterfront" => 3011
24
+ }
25
+
26
+ ELECTRIC_HOOKUPS = {
27
+ "15" => 3002,
28
+ "20" => 3003,
29
+ "30" => 3004,
30
+ "50" => 3005
31
+ }
32
+
33
+
34
+ # siteType
35
+ #
36
+ # If unspecified, all site types are returned.
37
+ #
38
+ def site_type(name)
39
+ code = TYPES.fetch(name.to_s)
40
+ merge_option("siteType", code)
41
+ self
42
+ end
43
+
44
+
45
+ # arvdate: Arrival Date
46
+ #
47
+ # The date in which the camper wants to start camping in mm/dd/yyyy format.
48
+ #
49
+ def arrival(date)
50
+ merge_option(:arvdate, date)
51
+ self
52
+ end
53
+
54
+
55
+ # lengthOfStay: Length of Stay
56
+ #
57
+ # When combined with arvdate, this parameter determines how long
58
+ # the camper would like to reserve the campground.
59
+ #
60
+ def nights(amt)
61
+ merge_option("lengthOfStay", amt)
62
+ self
63
+ end
64
+
65
+
66
+ # eqplen: Equipment Length
67
+ #
68
+ # If the camper wants to find campgrounds where his 50 foot RV will fit,
69
+ # issue a query where eqplen=50
70
+ #
71
+ def min_equip_length(val)
72
+ merge_option("eqplen", val)
73
+ self
74
+ end
75
+
76
+
77
+ # Maxpeople: Number of campers
78
+ #
79
+ #
80
+ def people(amt)
81
+ merge_option("Maxpeople", amt)
82
+ self
83
+ end
84
+
85
+
86
+ # hookup: Electric Hookup
87
+ #
88
+ #
89
+ def min_elec_amps(val)
90
+ code = ELECTRIC_HOOKUPS.fetch(val.to_s)
91
+ merge_option(:hookup, code)
92
+ self
93
+ end
94
+
95
+
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,31 @@
1
+ module Supercamp
2
+ module Criteria
3
+
4
+ class Detail < Abstract
5
+
6
+ # contractCode: STATE, FEDERAL or PRIVATE
7
+
8
+ # "contractCode" is a syonym for contractID, which is what is returned by
9
+ # the Campground Search API. It specifies the jurisdiction for the campground.
10
+ # This parameter must be used in conjuction with parkId
11
+ #
12
+ def contract_code(type)
13
+ merge_option("contractCode", type)
14
+ self
15
+ end
16
+
17
+
18
+ # parkId: Facility ID
19
+
20
+ # "parkId" is a synonym for "facilityID", which is returned by the Campground Search API.
21
+ # It is a unique identifier for the campground.
22
+ #
23
+ def id(val)
24
+ merge_option("parkId", val)
25
+ self
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ module Supercamp
2
+
3
+ class Error < StandardError
4
+
5
+ attr_reader :code
6
+ attr_reader :api_code
7
+ attr_reader :criteria
8
+
9
+ def initialize(criteria, response)
10
+ @code = response.options[:code]
11
+ @api_code = response.options[:headers]["X-Mashery-Error-Code"]
12
+ @criteria = criteria
13
+ super(response.body)
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,41 @@
1
+ require 'oga'
2
+ require 'hashr'
3
+
4
+ module Supercamp
5
+
6
+ class Response
7
+
8
+ attr_reader :count
9
+ attr_reader :entries
10
+
11
+ def initialize(response)
12
+ p = parse_response(response.body)
13
+
14
+ set_results_count(p)
15
+ set_entries(p)
16
+ end
17
+
18
+
19
+ private
20
+
21
+ def parse_response(xml)
22
+ xml.gsub!("\n", "")
23
+ Oga.parse_xml(xml).xpath("resultset").first
24
+ end
25
+
26
+ def set_results_count(parsed)
27
+ @count = parsed.attribute("count").value.to_i
28
+ end
29
+
30
+ def set_entries(parsed)
31
+ @entries = parsed.children.map do |child|
32
+ child.attributes.inject(Hashr.new) do |h, attr|
33
+ key = attr.name.gsub(/(.)([A-Z])/,'\1_\2').downcase
34
+ h[key] = attr.value; h
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,3 @@
1
+ module Supercamp
2
+ VERSION = "0.0.1"
3
+ end
data/lib/supercamp.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'typhoeus'
2
+
3
+ require 'supercamp/configuration'
4
+ require 'supercamp/error'
5
+ require 'supercamp/response'
6
+ require 'supercamp/version'
7
+ require 'supercamp/criteria/abstract'
8
+ require 'supercamp/criteria/campsite'
9
+ require 'supercamp/criteria/campground'
10
+ require 'supercamp/criteria/detail'
11
+
12
+ module Supercamp
13
+ extend self
14
+
15
+ def config
16
+ @config ||= Configuration.new
17
+ end
18
+
19
+ def configure
20
+ yield config
21
+ end
22
+
23
+ def campsites
24
+ Supercamp::Criteria::Campsite.new
25
+ end
26
+
27
+ def campgrounds
28
+ Supercamp::Criteria::Campground.new
29
+ end
30
+
31
+ def details
32
+ Supercamp::Criteria::Detail.new
33
+ end
34
+
35
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'supercamp'
3
+ require 'vcr'
4
+ require 'dotenv'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ Dotenv.load
9
+
10
+ config.filter_run :focus
11
+ config.run_all_when_everything_filtered = true
12
+
13
+ Supercamp.configure do |c|
14
+ c.api_key = ENV["API_KEY"]
15
+ end
16
+
17
+ VCR.configure do |c|
18
+ c.cassette_library_dir = 'spec/vcr_cassettes'
19
+ c.hook_into :typhoeus
20
+ end
21
+
22
+ end
@@ -0,0 +1,59 @@
1
+ require "spec_helper"
2
+
3
+ describe Supercamp::Configuration do
4
+
5
+ describe "#configure" do
6
+
7
+ context "w/ valid settings" do
8
+
9
+ before do
10
+ subject.configure do |config|
11
+ config.api_key = "super"
12
+ config.timeout = 10
13
+ end
14
+ end
15
+
16
+ it { expect(subject.api_key).to eq "super" }
17
+ it { expect(subject.timeout).to eq 10 }
18
+
19
+ end
20
+
21
+ context "w/ invalid settings" do
22
+
23
+ it do
24
+ expect {
25
+ subject.configure do |config|
26
+ config.crabs = "super"
27
+ end
28
+ }.to raise_error NoMethodError
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
35
+
36
+ describe "#base_url" do
37
+
38
+ it { expect(subject.base_url).to eq "http://api.amp.active.com/camping" }
39
+
40
+ end
41
+
42
+
43
+ describe "#api_key" do
44
+
45
+ it "defaults to nil" do
46
+ expect(subject.api_key).to be_nil
47
+ end
48
+
49
+ end
50
+
51
+
52
+ describe "#timeout" do
53
+
54
+ it "defaults to 5 (seconds)" do
55
+ expect(subject.timeout).to eq 5
56
+ end
57
+ end
58
+
59
+ end