forked from arpariseau/represent-sinatra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepresent_app.rb
90 lines (69 loc) · 1.94 KB
/
represent_app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
require 'sinatra'
require "sinatra/namespace"
require './poros/bill_aggregator'
require './services/propublica_service'
require './services/news_api_service'
require './services/image_repo_service'
require './serializers/article_serializer'
require './serializers/bill_serializer'
require './serializers/chamber_vote_serializer'
require './serializers/member_vote_serializer'
require './serializers/representative_serializer'
require './serializers/senator_serializer'
namespace '/api/v1' do
before do
content_type 'application/json'
end
get '/' do
"Sinatra's running!"
end
get '/representatives' do
service = get_propublica
json = service.house_members
RepresentativeSerializer.new(json).json_api
end
get '/senators' do
service = get_propublica
json = service.senators
SenatorSerializer.new(json).json_api
end
get '/articles' do
service = get_news_api
favorite_names = params[:favorite_names]
language_abbrev = params[:language]
sort_by = params[:sort]
num_results = params[:num_results]
json = service.get_everything(favorite_names, language_abbrev, sort_by, num_results)
ArticleSerializer.new(json).json_api
end
get '/bills' do
bill_list = BillAggregator.new.aggregate_bills
BillSerializer.new(bill_list).json_api
end
get '/chamber_votes' do
chamber = params[:chamber]
ChamberVoteSerializer.new(chamber).json_api
end
get '/member_votes' do
member_id = params[:member_id]
chamber = params[:chamber]
session = params[:session]
roll_call = params[:roll_call]
json = get_propublica.roll_call_vote(chamber, session, roll_call)
MemberVoteSerializer.new(member_id, json).json_api
end
get '/images' do
congress_id = params[:congress_id]
get_image_repo.get_image(congress_id)
end
end
private
def get_propublica
PropublicaService.new
end
def get_news_api
NewsapiService.new
end
def get_image_repo
ImageRepoService.new
end