This repository has been archived by the owner on Aug 18, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now we have something like a working service.
- Loading branch information
Showing
10 changed files
with
4,484 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'yaml' | ||
|
||
class ApiKeys | ||
class << self | ||
def init | ||
@keys ||= YAML::load(File.open('./api_keys.yaml')) | ||
end | ||
|
||
def key_for(service) | ||
init | ||
@keys[service]['key'] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'yaml' | ||
|
||
class Services | ||
class << self | ||
|
||
def init | ||
@services ||= YAML::load(File.open('./services.yaml')) | ||
end | ||
|
||
def services | ||
init | ||
@services | ||
end | ||
|
||
def service_url(service_name, post_code) | ||
init | ||
@services[service_name]['where'].gsub(':post_code', post_code) | ||
end | ||
|
||
def local_services | ||
init | ||
@services.select {|_, service_obj| service_obj['internal']} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'sinatra' | ||
require 'twfy' | ||
require './lib/api_keys.rb' | ||
require 'json' | ||
|
||
helpers do | ||
def the_twfy_client | ||
@twfy_client ||= Twfy::Client.new(ApiKeys.key_for('they_work_for_you')) | ||
end | ||
|
||
def mp_url(the_mp) | ||
%Q{http://www.theyworkforyou.com/mp/#{the_mp.full_name.downcase.gsub(' ','_')}/#{the_mp.constituency.name.downcase.gsub(' ','_').gsub('&','and')}} | ||
end | ||
end | ||
|
||
get '/twfy/mp/:post_code' do | ||
@mp = the_twfy_client.mp(:postcode => params[:post_code]) | ||
erb :'twfy/mp' | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.