actionkit_connector 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: 7e8ac5ca62b2bc490f252ac6fe28e779186420dd
4
- data.tar.gz: 023b208b610f7b71e07f0fde4fa64a9156615d63
3
+ metadata.gz: 51bad1dd8382c738ff52aeee2276b6fbc5136ae7
4
+ data.tar.gz: 80db19e48df8f18c9ff5cc9e52011f5ae32244ce
5
5
  SHA512:
6
- metadata.gz: adf985e88a49a3726333e3f50d5e1c639ce845bd453c37c979897a5347b0c818b668ae4820a20265df2e954a55ae8c8a0e82d2112a0cede3cac5a9cb5d47ecf9
7
- data.tar.gz: 62399a6c565264f3bd7c8b7e1e9260c1afb6bd5983e1b198bde942fb585da241cb653134ec62b589b40e7ba2fbb8fb51b2a0e8b2929fb327b4149c0194722f2f
6
+ metadata.gz: ac037266a94ae054753a6ce1373202d23b1c99852b0bcb9f6cea8df686cdc4ede718c9376f52f4f186a996bda916cbf0c94c0f1e9e917d9e9d1cc572424e21bd
7
+ data.tar.gz: 6f9a8ce758a7a4b3e1d4c88eaaf5380ca3c68f78b5f3c0c6417a69b53d44a6f0534cc4c489e82376473b0924e7af2adcaa3dcef47b12e5171f36cdf690018f8e
data/.gitignore CHANGED
@@ -14,3 +14,4 @@
14
14
  mkmf.log
15
15
  .idea/
16
16
  *.iml
17
+ local_test.rb
data/Gemfile CHANGED
@@ -3,3 +3,4 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in actionkit_connector.gemspec
4
4
  gemspec
5
5
  gem 'httparty', '~> 0.13'
6
+ gem 'rspec'
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.7'
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
25
26
  end
@@ -1,18 +1,39 @@
1
- require "actionkit_connector/version"
1
+ require_relative 'actionkit_connector/version'
2
+ require 'httparty'
2
3
 
3
4
  module ActionKitConnector
4
5
  class Connector
5
6
  include HTTParty
6
7
 
8
+ attr_accessor :username
9
+ attr_accessor :password
10
+ attr_accessor :base_url
11
+
12
+ # Initializes a connector to the ActionKit API.
13
+ # A new connection is created on each call, so there
14
+ # no need to worry about resource utilization.
15
+ #
16
+ # @param [String] username The username of your ActionKit user.
17
+ # @param [String] password The password for your ActionKit user.
18
+ # @param [String] base_url The base url of your ActionKit instance.
7
19
  def initialize(username, password, base_url)
8
- @auth = {username: username, password: password}
9
- @base_url = base_url
20
+ self.username = username
21
+ self.password = password
22
+ self.base_url = base_url
23
+ end
24
+
25
+ def auth
26
+ {username: self.username, password: self.password}
10
27
  end
11
28
 
29
+ # Lists petition pages in your instance.
30
+ #
31
+ # @param [Int] offset The number of records to skip.
32
+ # @param [Int] limit The maximum number of results to return.
12
33
  def list_petition_pages(offset=0, limit=20)
13
- target = "#{@base_url}/petitionpage/"
34
+ target = "#{self.base_url}/petitionpage/"
14
35
  options = {
15
- basic_auth: @auth,
36
+ basic_auth: self.auth,
16
37
  query: {
17
38
  _limit: limit,
18
39
  _offset: offset
@@ -21,20 +42,55 @@ module ActionKitConnector
21
42
  self.class.get(target, options)
22
43
  end
23
44
 
45
+ # Returns the information for a single PetitionPage.
46
+ #
47
+ # @param [Int] id The ID of the page to return.
24
48
  def petition_page(id)
25
- target = "#{@base_url}/petitionpage/#{id}/"
26
- self.class.get(target, {basic_auth: @auth})
49
+ target = "#{self.base_url}/petitionpage/#{id}/"
50
+ self.class.get(target, {basic_auth: self.auth})
27
51
  end
28
52
 
53
+ # Create a petition page in your ActionKit instance.
54
+ #
55
+ # @param [String] name The name of the page.
56
+ # @param [String] title The title of the page.
57
+ # @param [URI] lang The URI string for the language of this page in the form of /rest/v1/language/{id}
58
+ # @param [URL] canonical_url The canonical URL for this page.
29
59
  def create_petition_page(name, title, lang, canonical_url)
30
- target = "#{@base_url}/petitionpage/"
60
+ target = "#{self.base_url}/petitionpage/"
61
+ options = {
62
+ basic_auth: self.auth,
63
+ headers: {
64
+ 'Content-type' => 'application/json'
65
+ },
66
+ :body => {
67
+ :type => 'petitionpage',
68
+ :hidden => false,
69
+ :name => name,
70
+ :title => title,
71
+ :lang => lang,
72
+ :canonical_url => canonical_url
73
+ }.to_json,
74
+ format: :json
75
+ }
76
+ self.class.post(target, options)
77
+ end
78
+
79
+ # Create a donation page in your ActionKit instance.
80
+ #
81
+ # @param [String] name The name of the page.
82
+ # @param [String] title The title of the page.
83
+ # @param [URI] lang The URI string for the language of this page in the form of /rest/v1/language/{id}
84
+ # @param [URL] canonical_url The canonical URL for this page.
85
+ def create_donation_page(name, title, lang, canonical_url)
86
+ target = "#{self.base_url}/donationpage/"
31
87
  options = {
32
- basic_auth: @auth,
88
+ basic_auth: self.auth,
33
89
  headers: {
34
90
  'Content-type' => 'application/json'
35
91
  },
36
92
  :body => {
37
- :type => "petitionpage",
93
+ :type => 'donationpage',
38
94
  :hidden => false,
39
95
  :name => name,
40
96
  :title => title,
@@ -46,10 +102,14 @@ module ActionKitConnector
46
102
  self.class.post(target, options)
47
103
  end
48
104
 
105
+ # Creates an action which associates a user with a page.
106
+ #
107
+ # @param [String] page_name The ActionKit name of the page on which the action is being taken.
108
+ # @param [String] email The email address of the person taking action.
49
109
  def create_action(page_name, email)
50
- target = "#{@base_url}/action/"
110
+ target = "#{self.base_url}/action/"
51
111
  options = {
52
- basic_auth: @auth,
112
+ basic_auth: self.auth,
53
113
  body: {
54
114
  page: page_name,
55
115
  email: email
@@ -1,3 +1,3 @@
1
1
  module ActionkitConnector
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,21 @@
1
+ require 'rspec'
2
+ require_relative '../lib/actionkit_connector'
3
+
4
+ describe 'Connector' do
5
+ before :each do
6
+ @connector = ActionKitConnector::Connector.new 'username', 'password', 'url'
7
+ end
8
+
9
+ it 'should create auth' do
10
+ expect(@connector.auth).to eql({username: 'username', password: 'password'})
11
+ end
12
+
13
+ it 'should change auth' do
14
+ @connector.password = 'new_password'
15
+ expect(@connector.auth).to eql({username: 'username', password: 'new_password'})
16
+ end
17
+
18
+ it 'should create base url' do
19
+ expect(@connector.base_url).to eql 'url'
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionkit_connector
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
  - Eric Boersma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-02 00:00:00.000000000 Z
11
+ date: 2015-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: ''
56
70
  email:
57
71
  - eric.boersma@gmail.com
@@ -68,6 +82,7 @@ files:
68
82
  - actionkit_connector.gemspec
69
83
  - lib/actionkit_connector.rb
70
84
  - lib/actionkit_connector/version.rb
85
+ - test/connector_spec.rb
71
86
  homepage: https://github.com/EricBoersma/actionkit_connector
72
87
  licenses:
73
88
  - MIT
@@ -92,4 +107,5 @@ rubygems_version: 2.4.3
92
107
  signing_key:
93
108
  specification_version: 4
94
109
  summary: A gem for interacting with the ActionKit API.
95
- test_files: []
110
+ test_files:
111
+ - test/connector_spec.rb