-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathapi.js
128 lines (104 loc) · 2.84 KB
/
api.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* API service for the Democracy.io app.
*/
var helpers = require('../helpers/api');
var models = require('../../../models');
var Raven = require('../raven-client');
var api = function ($http, dioConfig) {
var siteConfig = dioConfig.SITE;
return {
makeRelativeAPIURL: function(path) {
return helpers.makeRelativeAPIUrl(siteConfig.API_BASE_URL, siteConfig.API_VERSION, path);
},
makeAPICall: function(opts, cb) {
opts.apiCall = true;
$http(opts)
.then(function(data) {
cb(null, data.data);
})
.catch(function(data) {
Raven.captureException(data);
cb(data, null);
});
},
verifyAddress: function(address, cb) {
var opts = {
url: this.makeRelativeAPIURL('location/verify'),
method: 'GET',
params: {address: address},
modelClass: models.CanonicalAddress
};
this.makeAPICall(opts, cb);
},
/**
*
* @param stateAbbrev
* @param district
* @param cb
*/
findLegislatorsByDistrict: function(stateAbbrev, district, cb) {
var opts = {
url: this.makeRelativeAPIURL('/legislators/findByDistrict'),
method: 'GET',
params: {state: stateAbbrev, district: district},
modelClass: models.Legislator
};
this.makeAPICall(opts, cb);
},
legislatorFormElemsByBioguideIds: function(bioguideIds, cb) {
var opts = {
url: this.makeRelativeAPIURL('/formElements/findByLegislatorBioguideIds'),
method: 'GET',
params: {bioguideIds: bioguideIds},
modelClass: models.LegislatorFormElements
};
this.makeAPICall(opts, cb);
},
/**
*
*/
submitMessageToReps: function(messages, cb) {
var opts = {
url: this.makeRelativeAPIURL('/legislators/message'),
method: 'POST',
data: messages,
modelClass: models.MessageResponse
};
this.makeAPICall(opts, cb);
},
/**
*
*/
subscribeToEFFList: function(subRequest, cb) {
var opts = {
url: this.makeRelativeAPIURL('/subscription'),
method: 'POST',
data: subRequest,
modelClass: models.MessageResponse
};
this.makeAPICall(opts, cb);
},
/**
*
*/
submitCaptchaResponse: function(captchaSolution, cb) {
var opts = {
url: this.makeRelativeAPIURL('captchaSolution'),
method: 'POST',
data: captchaSolution
};
this.makeAPICall(opts, cb);
},
logException: function(exception) {
var opts = {
url: this.makeRelativeAPIURL('exception'),
method: 'POST',
data: exception
};
// Pass in a noop cb, so the exception log is best-effort
this.makeAPICall(opts, function() {
});
}
};
};
module.exports = ['$http', 'dioConfig', api];