act_blue_reporter 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -12
- data/lib/act_blue_reporter/campaign.rb +9 -8
- data/lib/act_blue_reporter/connect.rb +1 -1
- data/lib/act_blue_reporter/contribution_report.rb +1 -1
- data/lib/act_blue_reporter/version.rb +1 -1
- data/spec/campaign_spec.rb +14 -7
- data/spec/contribution_report_spec.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 411f515f527d0305e142defeb71b2bdd9cf7be8a
|
4
|
+
data.tar.gz: 87ca4d91fdcf7e4b33fc1b3349b514a9a39b1544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 919826db0951cfc660f1d99a91eeafbcb4f1b9746c539754a19850231564480fb99c8d1321fc5a6df405fa946965a0a1416e7d0dcd5fa595aec0e3565c5120d6
|
7
|
+
data.tar.gz: fa61b04203610784aeec19f541a6b9b34a0e66d3cb14712f6fb81686dcefe7c076d3c694f2d779082c8fa6ef2f2794891a7c71ebbbf14c6122d2d182be3ee741
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
[![Code Climate](https://codeclimate.com/github/cdale77/act_blue_reporter/badges/gpa.svg)](https://codeclimate.com/github/cdale77/act_blue_reporter)
|
2
2
|
[![Test Coverage](https://codeclimate.com/github/cdale77/act_blue_reporter/badges/coverage.svg)](https://codeclimate.com/github/cdale77/act_blue_reporter)
|
3
3
|
[![Build Status](https://travis-ci.org/cdale77/act_blue_reporter.svg?branch=master)](https://travis-ci.org/cdale77/act_blue_reporter)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/act_blue_reporter.svg)](http://badge.fury.io/rb/act_blue_reporter)
|
4
5
|
|
5
6
|
# ActBlueReporter
|
6
7
|
|
@@ -29,14 +30,14 @@ Or install it yourself as:
|
|
29
30
|
## Usage
|
30
31
|
|
31
32
|
Create a campaign object. The login and password are the same as you use for
|
32
|
-
the web interface. The entity ID can be
|
33
|
-
usually visible in the url.
|
33
|
+
the web interface. The entity ID can be obtained from the web interface. It is
|
34
|
+
usually visible in the url. All three arguments are required.
|
34
35
|
|
35
|
-
campaign = ActBlueReporter::Campaign.new(act_blue_login,
|
36
|
-
act_blue_password,
|
37
|
-
act_blue_entity_id)
|
36
|
+
campaign = ActBlueReporter::Campaign.new(act_blue_login: my_login,
|
37
|
+
act_blue_password: my_password,
|
38
|
+
act_blue_entity_id: my_id)
|
38
39
|
|
39
|
-
You can use the campaign object to get data
|
40
|
+
You can use the campaign object to get data.
|
40
41
|
|
41
42
|
# returns a hash of campaign details. Useful for checking credentials.
|
42
43
|
campaign.details
|
@@ -44,21 +45,23 @@ You can use the campaign object to get data
|
|
44
45
|
# returns a hash of all the campaign's contributions. Use with care.
|
45
46
|
campaign.all_contributions
|
46
47
|
|
47
|
-
# returns the contributions in the
|
48
|
+
# returns the contributions in the previous day (24 hours)
|
48
49
|
campaign.contributions_in_last_24_hours
|
49
50
|
|
50
51
|
# returns contributions in a certain time range. Arguments must be
|
51
|
-
# ISO 8601 formatted strings.
|
52
|
-
|
52
|
+
# ISO 8601 formatted strings. Defaults to the previous 24 hours if no
|
53
|
+
# arguments are supplied
|
54
|
+
campaign.contributions_in_time_range(start_time: "2014-10-10T14:00:00-07:00",
|
55
|
+
end_time: "2014-10-12T14:00:00-07:00")
|
53
56
|
|
54
|
-
|
57
|
+
The structure of the response from ActBlue is
|
55
58
|
different if there is one contribution, or more than one. In particular,
|
56
|
-
responses containing multiple contributions are nested
|
59
|
+
responses containing multiple contributions are nested one level more than
|
57
60
|
single contributions. This class abstracts that away and returns a predictable
|
58
61
|
structure.
|
59
62
|
|
60
63
|
payload = campaign.all_contributions
|
61
|
-
formatter = ActBlueReporter::ContributionReport.new(payload)
|
64
|
+
formatter = ActBlueReporter::ContributionReport.new(payload: my_payload)
|
62
65
|
report = formatter.report
|
63
66
|
|
64
67
|
# you can also get the count of contributions from the formatter object
|
@@ -7,35 +7,36 @@ module ActBlueReporter
|
|
7
7
|
# This class models a campaign or committee at ActBlue and provides
|
8
8
|
# some basic functionality. ActBlue calls these "entities".
|
9
9
|
|
10
|
-
def initialize(act_blue_login
|
10
|
+
def initialize(act_blue_login:, act_blue_password:, act_blue_entity_id: )
|
11
11
|
@auth = { username: act_blue_login, password: act_blue_password }
|
12
12
|
@act_blue_entity_id = act_blue_entity_id
|
13
13
|
end
|
14
14
|
|
15
15
|
def details
|
16
16
|
request_uri = "/entities/#{@act_blue_entity_id}"
|
17
|
-
response = make_request(request_uri, @auth)
|
17
|
+
response = make_request(request_uri: request_uri, authentication: @auth)
|
18
18
|
response["entity"]
|
19
19
|
end
|
20
20
|
|
21
21
|
def all_contributions
|
22
22
|
request_uri = "/contributions?destination=#{@act_blue_entity_id}"
|
23
|
-
response = make_request(request_uri, @auth)
|
23
|
+
response = make_request(request_uri: request_uri, authentication: @auth)
|
24
24
|
response["contributions"]
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
# Defaults to the last 24 hours if no arguments are supplied
|
28
|
+
def contributions_in_time_range(start_time: (Time.now.at_beginning_of_day - 24.hours).iso8601,
|
29
|
+
end_time: Time.now.at_beginning_of_day.iso8601)
|
28
30
|
request_uri = "/contributions?destination=#{@entity.to_s}&" +
|
29
31
|
"payment_timestamp=#{start_time.to_s}/" +
|
30
32
|
"#{end_time.to_s}"
|
31
|
-
response = make_request(request_uri, @auth)
|
33
|
+
response = make_request(request_uri: request_uri, authentication: @auth)
|
32
34
|
response["contributions"]
|
33
35
|
end
|
34
36
|
|
37
|
+
# Mostly for syntax and clarity
|
35
38
|
def contributions_in_last_24_hrs
|
36
|
-
|
37
|
-
end_time = Time.now.at_beginning_of_day.iso8601
|
38
|
-
contributions_in_time_range(start_time, end_time)
|
39
|
+
contributions_in_time_range()
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
data/spec/campaign_spec.rb
CHANGED
@@ -2,8 +2,13 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe ActBlueReporter::Campaign do
|
4
4
|
|
5
|
-
let!(:campaign) { ActBlueReporter::Campaign.new(
|
6
|
-
|
5
|
+
let!(:campaign) { ActBlueReporter::Campaign.new(act_blue_login: "",
|
6
|
+
act_blue_password: "",
|
7
|
+
act_blue_entity_id: "") }
|
8
|
+
|
9
|
+
let!(:failing_campaign) { ActBlueReporter::Campaign.new(act_blue_login: "",
|
10
|
+
act_blue_password: "",
|
11
|
+
act_blue_entity_id: 0) }
|
7
12
|
|
8
13
|
describe '#initialize' do
|
9
14
|
it 'should create an object' do
|
@@ -50,19 +55,21 @@ describe ActBlueReporter::Campaign do
|
|
50
55
|
end_time = "2014-08-24T00:00:00-07:00"
|
51
56
|
describe 'success' do
|
52
57
|
it 'should return a Hash' do
|
53
|
-
|
54
|
-
be_an_instance_of Hash
|
58
|
+
result = campaign.contributions_in_time_range(start_time: start_time, end_time: end_time)
|
59
|
+
expect(result).to be_an_instance_of Hash
|
55
60
|
end
|
56
61
|
it 'should return a response with the correct info' do
|
57
|
-
|
58
|
-
|
62
|
+
result = campaign.contributions_in_time_range(start_time: start_time, end_time: end_time)
|
63
|
+
expect(result["count"]).to eq "3"
|
59
64
|
end
|
60
65
|
end
|
61
66
|
end
|
62
67
|
describe 'failure' do
|
68
|
+
tart_time = "2014-08-23T00:00:00-07:00"
|
69
|
+
end_time = "2014-08-24T00:00:00-07:00"
|
63
70
|
it 'should raise an error' do
|
64
71
|
expect do
|
65
|
-
failing_campaign.contributions_in_time_range(start_time, end_time)
|
72
|
+
failing_campaign.contributions_in_time_range(start_time: start_time, end_time: end_time)
|
66
73
|
end.to raise_error
|
67
74
|
end
|
68
75
|
end
|
@@ -2,9 +2,11 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe ActBlueReporter::ContributionReport do
|
4
4
|
|
5
|
-
let!(:campaign) { ActBlueReporter::Campaign.new(
|
5
|
+
let!(:campaign) { ActBlueReporter::Campaign.new(act_blue_login: "",
|
6
|
+
act_blue_password: "",
|
7
|
+
act_blue_entity_id: "") }
|
6
8
|
let!(:payload) { campaign.contributions_in_last_24_hrs }
|
7
|
-
let!(:report) { ActBlueReporter::ContributionReport.new(payload) }
|
9
|
+
let!(:report) { ActBlueReporter::ContributionReport.new(payload: payload) }
|
8
10
|
|
9
11
|
describe '#initialize' do
|
10
12
|
it 'should create an object' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: act_blue_reporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|