walkscore 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /lib/walkscore/api_key.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in walkscore.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 michael verdi
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.
@@ -0,0 +1,35 @@
1
+ # Walkscore
2
+ This is a gem for interacting with the Walkscore Api. You can easily request the walkscore of any given city by just passing in the lat and long of a given city. You will need an API key from walkscore first.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'walkscore'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install walkscore
17
+
18
+ ## Usage
19
+
20
+ ### There is only one external method you will be using to interact with the api.
21
+
22
+ ### WalkscoreApi::Walkscore.find({lat: 40.7143528 , long: -74.00597309999999 }, API_KEY)
23
+ That's it! You're response will be a Walkscore object where you have access to the following methods
24
+ + score
25
+ + description
26
+ + updated
27
+ + logo_url
28
+ + ws_link
29
+ + Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ require "walkscore/api_key"
2
+ require "walkscore/version"
3
+ require "walkscore/client"
4
+ require "walkscore/walkscore"
@@ -0,0 +1,23 @@
1
+ require 'faraday'
2
+
3
+ module WalkscoreApi
4
+ class Client
5
+ BASE_URL = 'http://api.walkscore.com'
6
+
7
+ def initialize
8
+ @connection = Faraday.new(BASE_URL)
9
+ end
10
+
11
+ def make_connection(location, api_key)
12
+ response = @connection.get do |req|
13
+ req.url '/score'
14
+ req.headers['Accepts'] = 'application/json'
15
+ req.params['format'] = 'json'
16
+ req.params['lat'] = location[:lat]
17
+ req.params['lon'] = location[:long]
18
+ req.params['wsapikey'] = api_key
19
+ end
20
+ response.body
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Walkscore
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'json'
2
+
3
+ module WalkscoreApi
4
+ class Walkscore
5
+ attr_accessor :score, :description, :updated, :logo_url, :ws_link
6
+
7
+ def initialize(attributes)
8
+ self.score = attributes['walkscore']
9
+ self.description = attributes['description']
10
+ self.updated = attributes['updated']
11
+ self.logo_url = attributes['logo_url']
12
+ self.ws_link = attributes['ws_link']
13
+ end
14
+
15
+ def self.client
16
+ WalkscoreApi::Client.new
17
+ end
18
+
19
+ def self.find(location, api_key)
20
+ parsed_results = JSON.parse(client.make_connection(location, api_key))
21
+ WalkscoreApi::Walkscore.new(parsed_results)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe WalkscoreApi::Client do
4
+ describe '#make_connection' do
5
+ context 'when making a get request to the walkscore api' do
6
+ it 'returns a status of 1 for successful connection' do
7
+ client = WalkscoreApi::Client.new
8
+ result = client.make_connection({lat: 40.7143528 , long: -74.00597309999999 }, API_KEY)
9
+ JSON.parse(result)['status'].should == 1
10
+ end
11
+
12
+ it 'returns a status of 40 for unsuccessful connection' do
13
+ client = WalkscoreApi::Client.new
14
+ result = client.make_connection({lat: 40.7143528 , long: -74.00597309999999 }, 'some_random_text')
15
+ JSON.parse(result)['status'].should == 40
16
+ end
17
+
18
+ it 'returns a status of 30 for invalid location connection' do
19
+ client = WalkscoreApi::Client.new
20
+ result = client.make_connection({lat: -0.7143528 , long: 345.0059 }, API_KEY)
21
+ JSON.parse(result)['status'].should == 30
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1 @@
1
+ require './lib/walkscore'
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ class MockClient
4
+ def make_connection(location, api_key)
5
+ <<-eos
6
+ {\n\"status\": 1 \n,
7
+ \"walkscore\": 100\n,
8
+ \"description\": \"Walker's Paradise\"\n,
9
+ \"updated\": \"2012-06-27 23:22:43.598005\" \n,
10
+ \"logo_url\": \"http://www2.walkscore.com/images/api-logo.gif\"\n,
11
+ \"more_info_icon\": \"http://www2.walkscore.com/images/api-more-info.gif\"\n,
12
+ \"more_info_link\": \"http://www.walkscore.com/how-it-works.shtml\"\n, \"ws_link\": \"http://www.walkscore.com/score/loc/lat=40.7143528/lng=-74.00597309999999/?utm_source=dynamiteurbanite.com&utm_medium=ws_api&utm_campaign=ws_api\"\n,
13
+ \"snapped_lat\": 40.7145\n,
14
+ \"snapped_lon\": -74.0055 \n\n\n\n}
15
+ eos
16
+ end
17
+ end
18
+
19
+ describe WalkscoreApi::Walkscore do
20
+ before(:each) do
21
+ WalkscoreApi::Walkscore.stub(:client).and_return(MockClient.new)
22
+ end
23
+
24
+ describe '.find(location, api_key)' do
25
+ it 'returns an instance of WalkscoreApi::Walkscore' do
26
+ WalkscoreApi::Walkscore.find({lat: 40.7143528 , long: -74.00597309999999}, API_KEY).should be_a(WalkscoreApi::Walkscore)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/walkscore/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["michael verdi"]
6
+ gem.email = ["michael.v.verdi@gmail.com"]
7
+ gem.description = %q{Wrapper for the Walkscore Api}
8
+ gem.summary = %q{Wrapper for the Walkscore Api}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "walkscore"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Walkscore::VERSION
17
+
18
+ gem.add_runtime_dependency('faraday')
19
+ gem.add_development_dependency('rspec')
20
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: walkscore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - michael verdi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: &70333941152160 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70333941152160
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70333941151660 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70333941151660
36
+ description: Wrapper for the Walkscore Api
37
+ email:
38
+ - michael.v.verdi@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - lib/walkscore.rb
49
+ - lib/walkscore/client.rb
50
+ - lib/walkscore/version.rb
51
+ - lib/walkscore/walkscore.rb
52
+ - spec/client_spec.rb
53
+ - spec/spec_helper.rb
54
+ - spec/walkscore_spec.rb
55
+ - walkscore.gemspec
56
+ homepage: ''
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.17
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Wrapper for the Walkscore Api
80
+ test_files:
81
+ - spec/client_spec.rb
82
+ - spec/spec_helper.rb
83
+ - spec/walkscore_spec.rb