netroots-ruby-actblue 0.0.1

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.
data/README ADDED
File without changes
data/lib/actblue.rb ADDED
@@ -0,0 +1,110 @@
1
+ require 'rubygems'
2
+ require 'net/https'
3
+ require 'cgi'
4
+ require 'httparty'
5
+ require 'rexml/document'
6
+
7
+ class REXMLUtilityNode
8
+ def undasherize_keys(params)
9
+ params
10
+ end
11
+ end
12
+
13
+ module ActBlue
14
+
15
+ ACTBLUE_VERSION = "2007-10-1"
16
+ ACTBLUE_URL = "https://secure.actblue.com"
17
+
18
+ class ActiveBlue
19
+ include HTTParty
20
+ format :xml
21
+ base_uri "#{ACTBLUE_URL}/#{ACTBLUE_VERSION}"
22
+ basic_auth ENV['ACTBLUE_USER'], ENV['ACTBLUE_PASS'] if (ENV['ACTBLUE_USER'] && ENV['ACTBLUE_PASS'])
23
+ headers 'Accept' => 'application/xml'
24
+
25
+ attr_accessor :variables
26
+
27
+ ACT_TYPES = {
28
+ 'source' => 'Source',
29
+ 'page' => 'Page',
30
+ 'lineitem' => 'LineItem',
31
+ 'lineitems' => lambda {|hash| if (hash.is_a?(Array) && hash.first.class.name == "ActBlue::LineItem") then return hash end; collection = []; if hash['lineitem'].is_a?(Hash) then collection << LineItem.new(hash['lineitem']); else hash['lineitem'].each {|l| collection << LineItem.new(l); }; end; return collection; },
32
+ 'entity' => 'Entity',
33
+ 'instrument' => 'Instrument',
34
+ 'election' => 'Election',
35
+ 'expires' => 'Expires',
36
+ 'listentry' => 'ListEntry',
37
+ 'listentries' => lambda {|hash| if (hash.is_a?(Array) && hash.first.class.name == "ActBlue::ListEntry") then return hash end; collection = []; if hash['listentry'].is_a?(Hash) then collection << ListEntry.new(hash['listentry']); else hash['listentry'].each {|l| collection << ListEntry.new(l); }; end; return collection; },
38
+ 'creditcard' => 'CreditCard',
39
+ 'check' => 'Check',
40
+ 'candidacy' => 'Candidacy',
41
+ 'office' => 'Office'
42
+ }
43
+
44
+ def initialize(params = {})
45
+ @variables = {}
46
+ params.each do |key, value|
47
+ if value
48
+ if ACT_TYPES[key.to_s] && ACT_TYPES[key.to_s].is_a?(Proc)
49
+ collection = []
50
+ collection = ACT_TYPES[key.to_s].call(value) if !value.empty?
51
+ @variables[key.to_s] = collection
52
+ elsif ACT_TYPES[key.to_s] && value.is_a?(Hash)
53
+ @variables[key.to_s] = Object.const_get(ACT_TYPES[key.to_s]).new(value)
54
+ else
55
+ @variables[key.to_s] = value
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ def [](key)
62
+ @variables[key]
63
+ end
64
+
65
+ def []=(key, val)
66
+ @variables[key] = val
67
+ end
68
+
69
+ def to_xml
70
+ doc = REXML::Document.new
71
+ doc.add_element(to_xml_element)
72
+ output = ""
73
+ doc.write(output)
74
+ output
75
+ end
76
+
77
+ def to_xml_element
78
+ element = REXML::Element.new(self.class::XML_NAME)
79
+ self.class::ATTRIBUTES.each do |a|
80
+ element.add_attribute(a, @variables[a]) if @variables[a]
81
+ end
82
+ self.class::ELEMENTS.each do |e|
83
+ if @variables[e]
84
+ if ACT_TYPES[e] && ACT_TYPES[e].is_a?(Proc)
85
+ parentElement = REXML::Element.new(e)
86
+ @variables[e].each do |c|
87
+ if c.methods.include? "to_xml_element"
88
+ parentElement.add_element(c.to_xml_element)
89
+ end
90
+ end
91
+ element.add_element(parentElement)
92
+ else
93
+ if @variables[e].methods.include? "to_xml_element"
94
+ element.add_element(@variables[e].to_xml_element)
95
+ else
96
+ newElement = REXML::Element.new(e)
97
+ newElement.text = @variables[e]
98
+ element.add_element(newElement)
99
+ end
100
+ end
101
+ end
102
+ end
103
+ element
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+
110
+ Dir["#{File.dirname(__FILE__)}/actblue/*.rb"].each { |source_file| require source_file }
@@ -0,0 +1,11 @@
1
+ module ActBlue
2
+
3
+ class Candidacy < ActiveBlue
4
+
5
+ XML_NAME = 'candidacy'
6
+ ATTRIBUTES = ['id']
7
+ ELEMENTS = ['election','result']
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ module ActBlue
2
+
3
+ class Check < ActiveBlue
4
+
5
+ XML_NAME = 'check'
6
+ ATTRIBUTES = ['id']
7
+ ELEMENTS = ['date', 'number']
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,32 @@
1
+ module ActBlue
2
+
3
+ class Contribution < ActiveBlue
4
+
5
+ XML_NAME = 'contribution'
6
+ ATTRIBUTES = ['order-number', 'created-on']
7
+ ELEMENTS = ['refcode', 'source', 'timestamp', 'submitter', 'recurring', 'recurringtimes', 'referrer', 'successuri', 'lineitems']
8
+
9
+ def self.get(params)
10
+ hash = ActiveBlue.get('/contributions', :query => params)
11
+ result = []
12
+ if hash["contributions"]
13
+ hash["contributions"]["contribution"].each do |h|
14
+ result << Contribution.new(h)
15
+ end
16
+ elsif hash["contribution"]
17
+ result << Contribution.new(hash["contribution"])
18
+ end
19
+ result
20
+ end
21
+
22
+ def post
23
+ super.post('/contributions', :body => to_xml)
24
+ end
25
+
26
+ def put
27
+ super.put('/contributions', :body => to_xml)
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,11 @@
1
+ module ActBlue
2
+
3
+ class CreditCard < ActiveBlue
4
+
5
+ XML_NAME = 'creditcard'
6
+ ATTRIBUTES = []
7
+ ELEMENTS = ['name', 'billing-addr1', 'billing-addr2', 'billing-city', 'billing-state', 'billing-postalcode', 'account', 'expires', 'verifier']
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ module ActBlue
2
+
3
+ class Election < ActiveBlue
4
+
5
+ XML_NAME = 'election'
6
+ ATTRIBUTES = ['id']
7
+ ELEMENTS = ['election_date','office']
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ module ActBlue
2
+
3
+ class Entity < ActiveBlue
4
+
5
+ XML_NAME = 'entity'
6
+ ATTRIBUTES = ['id']
7
+ ELEMENTS = ['legalname', 'displayname', 'sortname', 'jurisdiction', 'govid', 'prefacewiththe', 'donate', 'kind', 'state', 'party', 'url', 'visible','candidacy']
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ module ActBlue
2
+
3
+ class Expires < ActiveBlue
4
+
5
+ XML_NAME = 'expires'
6
+ ATTRIBUTES = ['year', 'month']
7
+ ELEMENTS = []
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ module ActBlue
2
+
3
+ class Instrument < ActiveBlue
4
+
5
+ XML_NAME = 'instrument'
6
+ ATTRIBUTES = []
7
+ ELEMENTS = ['creditcard', 'check']
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ module ActBlue
2
+
3
+ class LineItem < ActiveBlue
4
+
5
+ XML_NAME = 'lineitem'
6
+ ATTRIBUTES = ['id','effective-at','visibility']
7
+ ELEMENTS = ['amount', 'fee', 'entity']
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ module ActBlue
2
+
3
+ class ListEntry < ActiveBlue
4
+
5
+ XML_NAME = 'listentry'
6
+ ATTRIBUTES = ['page','entity','position']
7
+ ELEMENTS = ['blurb']
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ module ActBlue
2
+
3
+ class Office < ActiveBlue
4
+
5
+ XML_NAME = 'office'
6
+ ATTRIBUTES = ['id']
7
+ ELEMENTS = ['name','description','race_type','district','seat_count','state']
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,32 @@
1
+ module ActBlue
2
+
3
+ class Page < ActiveBlue
4
+
5
+ XML_NAME = 'page'
6
+ ATTRIBUTES = ['name', 'partner', 'created-on']
7
+ ELEMENTS = ['title', 'author', 'blurb', 'visibility', 'showcandidatesummary', 'listentries']
8
+
9
+ def self.get(params)
10
+ hash = ActiveBlue.get('/pages', :query => params)
11
+ result = []
12
+ if hash["pages"]
13
+ hash["pages"].each do |h|
14
+ result << Page.new(h)
15
+ end
16
+ elsif hash["page"]
17
+ result << Page.new(hash["page"])
18
+ end
19
+ result
20
+ end
21
+
22
+ def post
23
+ super.post('/pages', :body => to_xml)
24
+ end
25
+
26
+ def put
27
+ super.put('/pages', :body => to_xml)
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,11 @@
1
+ module ActBlue
2
+
3
+ class Source < ActiveBlue
4
+
5
+ XML_NAME = 'source'
6
+ ATTRIBUTES = []
7
+ ELEMENTS = ['firstname', 'lastname', 'addr1', 'addr2', 'city', 'state', 'zip', 'country', 'employer', 'occupation', 'empaddr1', 'empaddr2', 'empcity', 'empstate', 'empzip', 'empcountry', 'email', 'phone']
8
+
9
+ end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netroots-ruby-actblue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Shank
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-11 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.1
24
+ version:
25
+ description:
26
+ email: kyle.shank@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - actblue4r.gemspec
35
+ - lib/actblue.rb
36
+ - lib/actblue/contribution.rb
37
+ - lib/actblue/entity.rb
38
+ - lib/actblue/instrument.rb
39
+ - lib/actblue/line_item.rb
40
+ - lib/actblue/page.rb
41
+ - lib/actblue/source.rb
42
+ - lib/actblue/candidacy.rb
43
+ - lib/actblue/check.rb
44
+ - lib/actblue/credit_card.rb
45
+ - lib/actblue/election.rb
46
+ - lib/actblue/expires.rb
47
+ - lib/actblue/list_entry.rb
48
+ - lib/actblue/office.rb
49
+ - README
50
+ has_rdoc: false
51
+ homepage: http://github.com/netroots/ruby-actblue
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.2.0
73
+ signing_key:
74
+ specification_version: 2
75
+ summary: Library for accessing the ActBlue API.
76
+ test_files: []
77
+