act_blue_reporter 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03bdbd7f49fc11b96a8ffbdf59f75c9b277a0f76
4
- data.tar.gz: 57608ae1fb9e8429d9a0746daea595aafd923d1f
3
+ metadata.gz: d1fb11f172ddbec69ae35cab10d2f44848e544fa
4
+ data.tar.gz: e92c05017f1b82855d821668cb436feff3c2904a
5
5
  SHA512:
6
- metadata.gz: e07ff66199a5e10f5524c3c1deac8b8b09ed88633010ffbd811e6d29f499a66fb1c40b88248a3ba53db501553cc6862f43dca84f6b2cb75e0b7f83ddeea429a2
7
- data.tar.gz: 08ea144d231393c60194bf1bf899b709a0bf3e86962da16f143dd588576dc6124e36610980924d97797e39f12b4c840c5603fe80e6c9cd079f51861265bd15d9
6
+ metadata.gz: 494af4ada1b134c599b22d804c54988b6e6c08e83086b21e80c100f103b5108d9308b133c093c543707dad57b3d4bd4e161de96656d39e7b7898b5c7c56b8791
7
+ data.tar.gz: ba62c8910f40feb734bfe9538b0be23ee82359be32575349a0c4298f4e21f0e231607fb33faec8e8b2dd852cc71106e221ea79e07ee2245ea3de8bbb168e1d47
data/README.md CHANGED
@@ -10,6 +10,8 @@ ActBlue. It is designed to work across multiple ActBlue campaigns.
10
10
  It is not a full-fledged wrapper for the ActBlue API; it doesn't do much more
11
11
  than retrieve data.
12
12
 
13
+ Extracted from [DonorStack](http://donorstack.com/).
14
+
13
15
  ## Installation
14
16
 
15
17
  Add this line to your application's Gemfile:
@@ -26,7 +28,42 @@ Or install it yourself as:
26
28
 
27
29
  ## Usage
28
30
 
29
- TODO: Write usage instructions here
31
+ 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.
34
+
35
+ campaign = ActBlueReporter::Campaign.new(act_blue_login,
36
+ act_blue_password,
37
+ act_blue_entity_id)
38
+
39
+ You can use the campaign object to get data
40
+
41
+ # returns a hash of campaign details. Useful for checking credentials.
42
+ campaign.details
43
+
44
+ # returns a hash of all the campaign's contributions. Use with care.
45
+ campaign.all_contributions
46
+
47
+ # returns the contributions in the last 24 hours
48
+ campaign.contributions_in_last_24_hours
49
+
50
+ # returns contributions in a certain time range. Arguments must be
51
+ # ISO 8601 formatted strings.
52
+ contributions_in_time_range(start_time, end_time)
53
+
54
+ One of the problems with ActBlue's API is the structure of the response is
55
+ different if there is one contribution, or more than one. In particular,
56
+ responses containing multiple contributions are nested on level more than
57
+ single contributions. This class abstracts that away and returns a predictable
58
+ structure.
59
+
60
+ payload = campaign.all_contributions
61
+ formatter = ActBlueReporter::ContributionReport.new(payload)
62
+ report = formatter.report
63
+
64
+ # you can also get the count of contributions from the formatter object
65
+ formatter.count
66
+
30
67
 
31
68
  ## Contributing
32
69
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.6"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec", "~> 3.1"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
25
  spec.add_development_dependency "pry", "~> 0.10"
26
26
  spec.add_development_dependency "pry-remote", "~> 0.1"
27
27
  spec.add_development_dependency "pry-nav", "~> 0.2"
@@ -15,35 +15,27 @@ module ActBlueReporter
15
15
  def details
16
16
  request_uri = "/entities/#{@act_blue_entity_id}"
17
17
  response = make_request(request_uri, @auth)
18
- payload = response["entity"]
19
- raise ActBlueReporter::Exceptions::PayloadError unless payload
20
- return payload
18
+ response["entity"]
21
19
  end
22
20
 
23
21
  def all_contributions
24
22
  request_uri = "/contributions?destination=#{@act_blue_entity_id}"
25
23
  response = make_request(request_uri, @auth)
26
- payload = response["contributions"]
27
- raise ActBlueReporter::Exceptions::PayloadError unless payload
28
- return payload
24
+ response["contributions"]
29
25
  end
30
26
 
31
27
  def contributions_in_time_range(start_time, end_time)
32
- response = make_request( "/contributions?destination=#{@entity.to_s}&" \
33
- "payment_timestamp=#{start_time.to_s}/" \
34
- "#{end_time.to_s}",
35
- @auth)
36
- payload = response["contributions"]
37
- raise ActBlueReporter::Exceptions::PayloadError unless payload
38
- return payload
28
+ request_uri = "/contributions?destination=#{@entity.to_s}&" +
29
+ "payment_timestamp=#{start_time.to_s}/" +
30
+ "#{end_time.to_s}"
31
+ response = make_request(request_uri, @auth)
32
+ response["contributions"]
39
33
  end
40
34
 
41
35
  def contributions_in_last_24_hrs
42
36
  start_time = (Time.now.at_beginning_of_day - 24.hours).iso8601
43
37
  end_time = Time.now.at_beginning_of_day.iso8601
44
- payload = contributions_in_time_range(start_time, end_time)
45
- raise ActBlueReporter::Exceptions::PayloadError unless payload
46
- return payload
38
+ contributions_in_time_range(start_time, end_time)
47
39
  end
48
40
  end
49
41
  end
@@ -47,6 +47,11 @@ module ActBlueReporter
47
47
  unless response.success?
48
48
  raise_error("HTTP response code: #{response.response.code}")
49
49
  end
50
+
51
+ # raise an error if the response is not a hash
52
+ unless response.is_a? Hash
53
+ raise_error("Response is a #{response.class}. Expecting hash")
54
+ end
50
55
  end
51
56
 
52
57
 
@@ -6,11 +6,5 @@ module ActBlueReporter
6
6
  super
7
7
  end
8
8
  end
9
-
10
- class PayloadError < StandardError
11
- def initialize(msg = "Did not receive the requested data from ActBlue")
12
- super
13
- end
14
- end
15
9
  end
16
10
  end
@@ -1,3 +1,3 @@
1
1
  module ActBlueReporter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: act_blue_reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Johnson
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.1'
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.1'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement