action_kit_api 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +38 -9
- data/lib/action_kit_api.rb +1 -1
- data/lib/action_kit_api/action.rb +2 -2
- data/lib/action_kit_api/connection.rb +9 -6
- data/lib/action_kit_api/data_model.rb +3 -0
- data/lib/action_kit_api/user.rb +2 -2
- data/lib/action_kit_api/version.rb +1 -1
- data/spec/connection/connection_spec.rb +0 -4
- data/spec/page/page_model_spec.rb +58 -0
- data/spec/page/page_types_spec.rb +65 -0
- data/spec/user/user_model_spec.rb +5 -0
- metadata +7 -3
data/README.md
CHANGED
@@ -1,18 +1,47 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
API
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
# ActionKit API #
|
2
|
+
|
3
|
+
This Gem provides a wrapper for the ActionKit API in a way that should feel pretty familiar if you're used to ActiveRecord (though this does not use or require ActiveRecord). I found that none existed and what we were using in our own code base was rough, undocumented and didn't conform to any expectations and it was failing in unusual and unpredictable ways. This is here to solve OUR problems and with any luck other people will be able to get some value out of it as well.
|
4
|
+
|
5
|
+
We intend to open up the repository on GitHub as soon as we're sure nothing sensitive leaked into it. In the mean time if you have suggestions for improvements, feature requests, or bug fixes please email me at: sstelfox at democracyforamerica dot com.
|
6
|
+
|
7
|
+
## Features ##
|
8
|
+
|
9
|
+
Currently implemented:
|
10
|
+
|
11
|
+
* Individual User Searching
|
12
|
+
* Individual Page Searching (any type)
|
13
|
+
* Searching on Page types: Petition, Signup, and Unsubscribe
|
14
|
+
* Creating new Users, PetitionPages, SignupPages, and UnsubscribePages
|
15
|
+
* Updating existing User and Page attributes
|
16
|
+
* Taking Actions
|
17
|
+
|
18
|
+
For Future releases:
|
19
|
+
|
20
|
+
* find\_all\_by\_* for all models (currently beta and limited to 1000 results/query)
|
21
|
+
* count on queries
|
22
|
+
* Support for all page types
|
23
|
+
* Validation logic on individual fields (all models)
|
24
|
+
|
25
|
+
## Known Issues/Bugs ##
|
26
|
+
|
27
|
+
* Currently overriding parts of XMLRPC standard library for our own ends, this may result in unexpected behaivior for applications that include this Gem and are using XMLRPC directly elsewhere, though the changes are fairly minor (User agent, and error code type validation).
|
28
|
+
|
29
|
+
## Usage ##
|
30
|
+
|
31
|
+
*Coming Soon*
|
32
|
+
|
33
|
+
## Testing Instructions ##
|
34
|
+
|
35
|
+
This Gem uses Cucumber for high-level integration and remote requests, while RSpec is for low level functionality and specifications. The RSpec tests do not require access to the actual API, everything is mocked out (with the exception of the certificate verification but that doesn't require credentials). To use **most** of the cucumber tests you need to have valid credentials for use with the ActionKit API. You can get more information on how to setup an API user in ActionKit's documentation. You need to place your credentials in /features/support/credentials.rb from the root of the Gem's directory. The Cucumber tests *WILL* create new users, pages, sign up users for pages and things that might otherwise affect live data.
|
7
36
|
|
8
37
|
***Please be aware of what the tests are doing before running them.***
|
9
38
|
|
10
|
-
Now that you've read the warning this is what the contents of the credentials
|
11
|
-
file should look like.
|
39
|
+
Now that you've read the warning this is what the contents of the credentials file should look like:
|
12
40
|
|
13
41
|
# These are credentials that need to be set for testing against
|
14
|
-
# live ActionKit.
|
42
|
+
# live ActionKit. This file will never live in the repository.
|
15
43
|
|
16
44
|
ACTIONKIT_HOSTNAME=""
|
17
45
|
ACTIONKIT_USERNAME=""
|
18
46
|
ACTIONKIT_PASSWORD=""
|
47
|
+
|
data/lib/action_kit_api.rb
CHANGED
@@ -8,9 +8,9 @@ module ActionKitApi
|
|
8
8
|
attr_accessor :id, :page, :user
|
9
9
|
|
10
10
|
# Other/Active
|
11
|
-
attr_accessor :
|
11
|
+
attr_accessor :created_user, :custom_fields, :link, :mailing,
|
12
12
|
:opq_id, :referring_mailing, :referring_user, :source, :status,
|
13
|
-
:subscribed_user, :taf_emails_sent
|
13
|
+
:subscribed_user, :taf_emails_sent
|
14
14
|
|
15
15
|
def initialize(*args)
|
16
16
|
@required_attrs = [:page, :user]
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'xmlrpc/client'
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
|
3
|
+
# A few minor tweaks to the XMLRPC standard library. There has to be a better way
|
4
|
+
# to handle some of what this is doing without going all Chuck Norris on the standard
|
5
|
+
# library. Once this library has it's full feature set I'll come back to these and dig
|
6
|
+
# deep into the bowels of XMLRPC and find a way to improve this. Suggestions welcome.
|
8
7
|
module XMLRPC
|
9
8
|
# This seems silly and dangerous right? Overwriting something in the ruby
|
10
9
|
# standard libraries? Well ActionKit is doing XMLRPC wrong. This is almost
|
@@ -37,7 +36,7 @@ module XMLRPC
|
|
37
36
|
USER_AGENT = "DFA Ruby action_kit_api/#{ActionKitApi::VERSION} ( http://code.democracyforamerica.com/ )"
|
38
37
|
end
|
39
38
|
|
40
|
-
# This was
|
39
|
+
# This was needed to prevent an empty response from the remote
|
41
40
|
# server from triggering an exception on calls
|
42
41
|
module Config
|
43
42
|
remove_const(:ENABLE_NIL_PARSER)
|
@@ -45,6 +44,10 @@ module XMLRPC
|
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
47
|
+
# This is the connection information for the ActionKit API
|
48
|
+
# which is used throughout the rest of the Gem (a connection being
|
49
|
+
# required for ... well every operation ... this is a remote API
|
50
|
+
# gem :)
|
48
51
|
module ActionKitApi
|
49
52
|
class Connection
|
50
53
|
def initialize(user, password, host)
|
data/lib/action_kit_api/user.rb
CHANGED
@@ -8,10 +8,10 @@ module ActionKitApi
|
|
8
8
|
attr_accessor :id, :email, :first_name, :last_name, :zip
|
9
9
|
|
10
10
|
# Other/Active
|
11
|
-
attr_accessor :address1, :address2, :akid, :city, :country,
|
11
|
+
attr_accessor :address1, :address2, :akid, :city, :country,
|
12
12
|
:custom_fields, :lang, :middle_name, :password, :plus4,
|
13
13
|
:postal, :prefix, :rand_id, :region, :state_name, :source,
|
14
|
-
:state, :subscription_status, :suffix, :token
|
14
|
+
:state, :subscription_status, :suffix, :token
|
15
15
|
|
16
16
|
def initialize(*args)
|
17
17
|
@required_attrs = [:email, :first_name, :last_name, :zip]
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module AKAPageSpecHelper
|
4
|
+
def validPageAttributes
|
5
|
+
{
|
6
|
+
:name => "test_page",
|
7
|
+
:title => "A Test Page",
|
8
|
+
:type => "petition"
|
9
|
+
}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ActionKitApi::Page do
|
14
|
+
include AKAPageSpecHelper
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
@page = ActionKitApi::Page.new
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not have a type" do
|
21
|
+
@page.type.should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be valid with valid attributes" do
|
25
|
+
@page.update(validPageAttributes)
|
26
|
+
@page.should be_valid
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should verify that a name is required" do
|
30
|
+
@page.update(validPageAttributes.except(:name))
|
31
|
+
@page.should_not be_valid
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should verify that a title is required" do
|
35
|
+
@page.update(validPageAttributes.except(:title))
|
36
|
+
@page.should_not be_valid
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should verify that a type is required" do
|
40
|
+
@page.update(validPageAttributes.except(:type))
|
41
|
+
@page.should_not be_valid
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not allow arbitrary attributes to be added" do
|
45
|
+
@page.update({"fake_attr" => "with some data"})
|
46
|
+
page_hash = @page.to_hash
|
47
|
+
|
48
|
+
page_hash.should_not include("fake_attr")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return it's attributes as a hash" do
|
52
|
+
@page.update(validPageAttributes)
|
53
|
+
page_hash = @page.to_hash
|
54
|
+
|
55
|
+
page_hash.should eql(validPageAttributes)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module AKAPageSpecHelper
|
4
|
+
def validPageAttributes
|
5
|
+
{
|
6
|
+
:name => "test_page",
|
7
|
+
:title => "A Test Page",
|
8
|
+
}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ActionKitApi::PetitionPage do
|
13
|
+
include AKAPageSpecHelper
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@page = ActionKitApi::PetitionPage.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have a type of 'petition'" do
|
20
|
+
@page.type.should eql('petition')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should be valid with valid attributes" do
|
24
|
+
@page.update(validPageAttributes)
|
25
|
+
@page.should be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ActionKitApi::SignupPage do
|
31
|
+
include AKAPageSpecHelper
|
32
|
+
|
33
|
+
before(:each) do
|
34
|
+
@page = ActionKitApi::SignupPage.new
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have a type of 'signup'" do
|
38
|
+
@page.type.should eql('signup')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be valid with valid attributes" do
|
42
|
+
@page.update(validPageAttributes)
|
43
|
+
@page.should be_valid
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ActionKitApi::UnsubscribePage do
|
49
|
+
include AKAPageSpecHelper
|
50
|
+
|
51
|
+
before(:each) do
|
52
|
+
@page = ActionKitApi::UnsubscribePage.new
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should have a type of 'unsubscribe'" do
|
56
|
+
@page.type.should eql('unsubscribe')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be valid with valid attributes" do
|
60
|
+
@page.update(validPageAttributes)
|
61
|
+
@page.should be_valid
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
@@ -18,6 +18,11 @@ describe ActionKitApi::User do
|
|
18
18
|
@user = ActionKitApi::User.new
|
19
19
|
end
|
20
20
|
|
21
|
+
it "should be valid with valid attributes" do
|
22
|
+
@user.update(validUserAttributes)
|
23
|
+
@user.should be_valid
|
24
|
+
end
|
25
|
+
|
21
26
|
it "should verify that an email is required" do
|
22
27
|
@user.update(validUserAttributes.except(:email))
|
23
28
|
@user.should_not be_valid
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sam Stelfox
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-03-
|
17
|
+
date: 2012-03-12 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- lib/action_kit_api/user.rb
|
80
80
|
- lib/action_kit_api/version.rb
|
81
81
|
- spec/connection/connection_spec.rb
|
82
|
+
- spec/page/page_model_spec.rb
|
83
|
+
- spec/page/page_types_spec.rb
|
82
84
|
- spec/remote_certificates_spec.rb
|
83
85
|
- spec/spec_helper.rb
|
84
86
|
- spec/user/user_model_spec.rb
|
@@ -121,6 +123,8 @@ test_files:
|
|
121
123
|
- features/users/find_a_user.feature
|
122
124
|
- features/users/update_a_user.feature
|
123
125
|
- spec/connection/connection_spec.rb
|
126
|
+
- spec/page/page_model_spec.rb
|
127
|
+
- spec/page/page_types_spec.rb
|
124
128
|
- spec/remote_certificates_spec.rb
|
125
129
|
- spec/spec_helper.rb
|
126
130
|
- spec/user/user_model_spec.rb
|