Sha256: 34dfe0bd750e3a6395e193ec516475d930bf0d82b4f0e498f7d71334671d724e
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
require "wonder_ways/version" require 'json' require 'faraday' require 'trail' class WonderWays attr_reader :connection def initialize(server = 'http://localhost:3000') @connection = Faraday.new(url: "#{server}/api/v1") end def list_trails(page = 1) params = { page: page } JSON.parse(connection.get('trails', params).body)['trails'] .map { |data| Trail.new(data) } end def find_trail(id = 1) params = { id: id } data = JSON.parse(connection.get("trails/#{id}", params).body)['trail'] Trail.new(data) end def search_trails_by_state(state = "CO") params = { state: state } JSON.parse(connection.get("search?state=#{state}", params).body)['trails'] .map { |data| Trail.new(data) } end def search_trails_by_location(lat = 38.3, lng = -106.6) params = { lat: lat, lng: lng } JSON.parse(connection.get("search?lat=#{lat}&lng=#{lng}", params).body)['trails'] .map { |data| Trail.new(data) } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wonder_ways-1.0.0 | lib/wonder_ways.rb |