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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1fb11f172ddbec69ae35cab10d2f44848e544fa
4
- data.tar.gz: e92c05017f1b82855d821668cb436feff3c2904a
3
+ metadata.gz: 411f515f527d0305e142defeb71b2bdd9cf7be8a
4
+ data.tar.gz: 87ca4d91fdcf7e4b33fc1b3349b514a9a39b1544
5
5
  SHA512:
6
- metadata.gz: 494af4ada1b134c599b22d804c54988b6e6c08e83086b21e80c100f103b5108d9308b133c093c543707dad57b3d4bd4e161de96656d39e7b7898b5c7c56b8791
7
- data.tar.gz: ba62c8910f40feb734bfe9538b0be23ee82359be32575349a0c4298f4e21f0e231607fb33faec8e8b2dd852cc71106e221ea79e07ee2245ea3de8bbb168e1d47
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 obtain from the web interface. It is
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 last 24 hours
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
- contributions_in_time_range(start_time, end_time)
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
- One of the problems with ActBlue's API is the structure of the response is
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 on level more than
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, act_blue_password, act_blue_entity_id)
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
- def contributions_in_time_range(start_time, end_time)
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
- start_time = (Time.now.at_beginning_of_day - 24.hours).iso8601
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
@@ -13,7 +13,7 @@ module ActBlueReporter
13
13
  HEADER = { "Accept" => "application/xml" }
14
14
 
15
15
  private
16
- def make_request(request_uri, authentication)
16
+ def make_request(request_uri:, authentication:)
17
17
 
18
18
  response = request_wrapper(request_uri, authentication)
19
19
 
@@ -7,7 +7,7 @@ module ActBlueReporter
7
7
 
8
8
  attr_reader :payload
9
9
 
10
- def initialize(payload)
10
+ def initialize(payload:)
11
11
  @payload = payload
12
12
  end
13
13
 
@@ -1,3 +1,3 @@
1
1
  module ActBlueReporter
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -2,8 +2,13 @@ require "spec_helper"
2
2
 
3
3
  describe ActBlueReporter::Campaign do
4
4
 
5
- let!(:campaign) { ActBlueReporter::Campaign.new("", "", "") }
6
- let!(:failing_campaign) { ActBlueReporter::Campaign.new("", "", "0") }
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
- expect(campaign.contributions_in_time_range(start_time, end_time)).to \
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
- expect(campaign.contributions_in_time_range(start_time, end_time)["count"]).to \
58
- eq "3"
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.2
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-09-20 00:00:00.000000000 Z
11
+ date: 2014-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler