nationbuilder-rb 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/README.md +9 -0
  4. data/VERSION +1 -1
  5. data/lib/api_spec/.ruby-gemset +1 -0
  6. data/lib/api_spec/.ruby-version +1 -0
  7. data/lib/api_spec/Gemfile +3 -0
  8. data/lib/api_spec/Gemfile.lock +13 -0
  9. data/lib/api_spec/LICENSE.txt +20 -0
  10. data/lib/api_spec/README.md +20 -0
  11. data/lib/api_spec/Rakefile +9 -0
  12. data/lib/api_spec/lib/api_spec.rb +26 -0
  13. data/lib/api_spec/lib/api_spec/generator.rb +113 -0
  14. data/lib/api_spec/lib/api_spec/specs/basic_pages.rb +106 -0
  15. data/lib/api_spec/lib/api_spec/specs/blog_posts.rb +160 -0
  16. data/lib/api_spec/lib/api_spec/specs/blogs.rb +128 -0
  17. data/lib/api_spec/lib/api_spec/specs/calendars.rb +128 -0
  18. data/lib/api_spec/lib/api_spec/specs/campaign_data.rb +15 -0
  19. data/lib/api_spec/lib/api_spec/specs/contacts.rb +155 -0
  20. data/lib/api_spec/lib/api_spec/specs/donations.rb +76 -0
  21. data/lib/api_spec/lib/api_spec/specs/events.rb +238 -0
  22. data/lib/api_spec/lib/api_spec/specs/exports.rb +42 -0
  23. data/lib/api_spec/lib/api_spec/specs/imports.rb +43 -0
  24. data/lib/api_spec/lib/api_spec/specs/lists.rb +215 -0
  25. data/lib/api_spec/lib/api_spec/specs/memberships.rb +94 -0
  26. data/lib/api_spec/lib/api_spec/specs/page_attachments.rb +121 -0
  27. data/lib/api_spec/lib/api_spec/specs/people.rb +500 -0
  28. data/lib/api_spec/lib/api_spec/specs/people_tags.rb +63 -0
  29. data/lib/api_spec/lib/api_spec/specs/precincts.rb +89 -0
  30. data/lib/api_spec/lib/api_spec/specs/sites.rb +32 -0
  31. data/lib/api_spec/lib/api_spec/specs/survey_responses.rb +64 -0
  32. data/lib/api_spec/lib/api_spec/specs/surveys.rb +106 -0
  33. data/lib/api_spec/lib/api_spec/specs/webhooks.rb +75 -0
  34. data/lib/{nationbuilder/api_spec.json → api_spec/spec.json} +143 -5
  35. data/lib/nationbuilder/client.rb +1 -1
  36. data/nationbuilder-rb.gemspec +35 -5
  37. data/spec/nationbuilder_client_spec.rb +1 -0
  38. data/update_subtree.sh +1 -0
  39. metadata +33 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2a9e95e72f4cd31b317649c6542b23341ced9d4
4
- data.tar.gz: 9151348b994b64949318fe8dd7de00d695c872ff
3
+ metadata.gz: c7f8f90ebdd85002490a6b397dd09fa46281b8bd
4
+ data.tar.gz: f9202e8f4eb9dbe9aadf58e573d1bbbaa9e8769e
5
5
  SHA512:
6
- metadata.gz: 5f36cae292f6a27e6ba670f6afcc04fab0baa13e8e17fa63182338ebce404430c8c192a45ce58cf5db9b048fd5389ac7b2e62b3164c19a4b48a7b4b0ff1fc0f2
7
- data.tar.gz: 19b7ba8cb1264bce42ddc1c51898aa93d43c94c9549b3c6fbd06e98deede47316e760c8d1f9fd51fa5494ec746861a3e580e37a68bf7de7cabef28f33885ad93
6
+ metadata.gz: f98ce91610243f72fdd466c7a005ccbd72d2d53f38141f0efccec999014797ce72e9056cba4dc0abc0bd5d6825693b8297a6b6cb519080b722c220cc80b4c193
7
+ data.tar.gz: 1cd633b609c6a5bea0127293b1b6b6fed244094b92e7cd8fc836d71dec0bc2a74de1468d993077916ac60a8d6f128c26787c5fe357543980c7ab30422c241fce
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.1.0
1
+ ruby-2.1.6
data/README.md CHANGED
@@ -122,3 +122,12 @@ Endpoint: basic_pages
122
122
 
123
123
  ...
124
124
  ```
125
+
126
+ ## Development
127
+
128
+ To update the API specification that powers this client, first make
129
+ the appropriate updates to the
130
+ [api_spec](https://github.com/nationbuilder/api_spec) repository. Once
131
+ the changes have been merged to api_spec's master branch, run the
132
+ `update_subtree.sh` script in the root directory of this project to
133
+ copy over the changes.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.2
1
+ 1.3.3
@@ -0,0 +1 @@
1
+ api_spec
@@ -0,0 +1 @@
1
+ ruby-2.1.6
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
@@ -0,0 +1,13 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ rake (10.4.2)
5
+
6
+ PLATFORMS
7
+ ruby
8
+
9
+ DEPENDENCIES
10
+ rake
11
+
12
+ BUNDLED WITH
13
+ 1.10.2
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 NationBuilder.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ # api_spec
2
+ This project is centered around generating the `spec.json` file
3
+ located in the root directory. The `spec.json` file contains a machine
4
+ readable specification of the NationBuilder API. It is in Mashery's
5
+ [I/O Docs](http://www.mashery.com/product/io-docs) format. The
6
+ specification can be used to generate documentation servers and client
7
+ libraries for the NationBuilder API.
8
+
9
+ ## Developer environment setup
10
+
11
+ ```ruby
12
+ bundle install
13
+ ```
14
+
15
+ ## Adding/modifying an endpoint
16
+
17
+ Locate the file in `lib/api_spec/specs` that corresponds to the API
18
+ you're modifying. With the DSL used in the file, make your changes. In
19
+ the root project directory, run `rake` to update the `spec.json`
20
+ file. Commit your changes.
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH << 'lib'
2
+ $LOAD_PATH << 'lib/api_spec'
3
+
4
+ task :generate_spec do
5
+ require 'api_spec'
6
+ ApiSpec::Spec.write_spec('spec.json')
7
+ end
8
+
9
+ task :default => [:generate_spec]
@@ -0,0 +1,26 @@
1
+ require 'json'
2
+
3
+ module ApiSpec; end
4
+
5
+ require 'generator'
6
+
7
+ require 'specs/basic_pages'
8
+ require 'specs/blog_posts'
9
+ require 'specs/blogs'
10
+ require 'specs/calendars'
11
+ require 'specs/campaign_data'
12
+ require 'specs/contacts'
13
+ require 'specs/donations'
14
+ require 'specs/events'
15
+ require 'specs/imports'
16
+ require 'specs/exports'
17
+ require 'specs/lists'
18
+ require 'specs/memberships'
19
+ require 'specs/page_attachments'
20
+ require 'specs/people'
21
+ require 'specs/people_tags'
22
+ require 'specs/precincts'
23
+ require 'specs/sites'
24
+ require 'specs/survey_responses'
25
+ require 'specs/surveys'
26
+ require 'specs/webhooks'
@@ -0,0 +1,113 @@
1
+ module ApiSpec
2
+ class APIObject
3
+ class << self
4
+ attr_accessor :nested_name, :nested_class, :nested_adder_name
5
+ end
6
+
7
+ def nested_name
8
+ self.class.nested_name
9
+ end
10
+
11
+ def nested_class
12
+ self.class.nested_class
13
+ end
14
+
15
+ def initialize(name)
16
+ @name = name
17
+ send("#{nested_name}=".to_sym, []) if nested_name
18
+ end
19
+
20
+ def to_hash
21
+ pairs = self.class::JSON_NAMES.map do |name, json_name|
22
+ [json_name, send(name)]
23
+ end
24
+
25
+ hash = Hash[pairs]
26
+
27
+ if nested_name
28
+ hash[nested_name.to_s] = send(nested_name).map { |obj| obj.to_hash }
29
+ end
30
+
31
+ hash
32
+ end
33
+
34
+ def self.init(base)
35
+ base.send(:attr_accessor, *base::JSON_NAMES.keys)
36
+ base.send(:attr_accessor, base.nested_name) if base.nested_name
37
+ base.send(:define_method, base.nested_adder_name) do |name, &block|
38
+ obj = nested_class.new(name)
39
+ block.call(obj)
40
+ send(nested_name) << obj
41
+ end if base.nested_adder_name
42
+ end
43
+
44
+ end
45
+
46
+ class Parameter < APIObject
47
+
48
+ JSON_NAMES = {
49
+ name: 'Name',
50
+ required: 'Required',
51
+ default: 'Default',
52
+ type: 'Type',
53
+ description: 'Description'
54
+ }
55
+
56
+ init(self)
57
+
58
+ end
59
+
60
+ class Method < APIObject
61
+
62
+ JSON_NAMES = {
63
+ name: "MethodName",
64
+ synopsis: "Synopsis",
65
+ http_method: "HTTPMethod",
66
+ uri: "URI"
67
+ }
68
+
69
+ self.nested_name = :parameters
70
+ self.nested_adder_name = :parameter
71
+ self.nested_class = Parameter
72
+
73
+ init(self)
74
+
75
+ end
76
+
77
+ class Endpoint < APIObject
78
+
79
+ JSON_NAMES = {
80
+ name: "name",
81
+ }
82
+
83
+ self.nested_name = :methods
84
+ self.nested_adder_name = :method
85
+ self.nested_class = ApiSpec::Method
86
+
87
+ init(self)
88
+
89
+ end
90
+
91
+ class Spec < APIObject
92
+
93
+ class << self
94
+ attr_accessor :endpoints
95
+ end
96
+
97
+ self.endpoints = []
98
+
99
+ def self.to_hash
100
+ { 'endpoints' => endpoints.map { |endpoint| endpoint.to_hash } }
101
+ end
102
+
103
+ def self.write_spec(path)
104
+ File.open(path, 'w') { |f| f.write(JSON.pretty_generate(to_hash)) }
105
+ end
106
+
107
+ def self.endpoint(name)
108
+ endpoint = Endpoint.new(name)
109
+ yield endpoint
110
+ endpoints << endpoint
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,106 @@
1
+ class ApiSpec::Spec
2
+
3
+ endpoint 'Basic Pages' do |bp|
4
+
5
+ bp.method('Index') do |m|
6
+
7
+ m.synopsis = "Shows a list of the basic pages in the system"
8
+ m.http_method = "GET"
9
+ m.uri = "/sites/:site_slug/pages/basic_pages"
10
+
11
+ m.parameter('site_slug') do |p|
12
+ p.required = 'Y'
13
+ p.type = 'string'
14
+ p.description = 'the site holding the basic page'
15
+ end
16
+
17
+ m.parameter('__token') do |p|
18
+ p.required = 'N'
19
+ p.type = 'string'
20
+ p.description = 'pagination token'
21
+ end
22
+
23
+ m.parameter('__nonce') do |p|
24
+ p.required = 'N'
25
+ p.type = 'string'
26
+ p.description = 'pagination nonce'
27
+ end
28
+
29
+ m.parameter('limit') do |p|
30
+ p.required = 'N'
31
+ p.default = '10'
32
+ p.type = 'int'
33
+ p.description = 'maximum number of results to return'
34
+ end
35
+
36
+ end
37
+
38
+ bp.method('Create') do |m|
39
+
40
+ m.synopsis = "Creates a basic page for a site"
41
+ m.http_method = "POST"
42
+ m.uri = "/sites/:site_slug/pages/basic_pages"
43
+
44
+ m.parameter('site_slug') do |p|
45
+ p.required = 'Y'
46
+ p.type = 'string'
47
+ p.description = 'the site holding the basic page'
48
+ end
49
+
50
+ m.parameter('body') do |p|
51
+ p.required = 'Y'
52
+ p.type = 'json'
53
+ p.description = 'a JSON representation of the new basic page'
54
+ end
55
+
56
+ end
57
+
58
+ bp.method('Update') do |m|
59
+
60
+ m.synopsis = "Updates the attributes of a basic page"
61
+ m.http_method = "PUT"
62
+ m.uri = "/sites/:site_slug/pages/basic_pages/:id"
63
+
64
+ m.parameter('site_slug') do |p|
65
+ p.required = 'Y'
66
+ p.type = 'string'
67
+ p.description = 'the site holding the basic page'
68
+ end
69
+
70
+ m.parameter('id') do |p|
71
+ p.required = 'Y'
72
+ p.type = 'int'
73
+ p.description = 'the ID of the basic page'
74
+ end
75
+
76
+ m.parameter('body') do |p|
77
+ p.required = 'Y'
78
+ p.type = 'json'
79
+ p.description = 'JSON containing updates'
80
+ end
81
+
82
+ end
83
+
84
+ bp.method('Destroy') do |m|
85
+
86
+ m.synopsis = "Removes a basic page"
87
+ m.http_method = "DELETE"
88
+ m.uri = "/sites/:site_slug/pages/basic_pages/:id"
89
+
90
+ m.parameter('site_slug') do |p|
91
+ p.required = 'Y'
92
+ p.type = 'string'
93
+ p.description = 'the site holding the basic page'
94
+ end
95
+
96
+ m.parameter('id') do |p|
97
+ p.required = 'Y'
98
+ p.type = 'int'
99
+ p.description = 'the ID of the basic page'
100
+ end
101
+
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,160 @@
1
+ class ApiSpec::Spec
2
+
3
+ endpoint 'Blog Posts' do |bp|
4
+
5
+ bp.method('Index') do |m|
6
+
7
+ m.synopsis = "Shows a list of blog's posts"
8
+ m.http_method = "GET"
9
+ m.uri = "/sites/:site_slug/pages/blogs/:id/posts"
10
+
11
+ m.parameter('site_slug') do |p|
12
+ p.required = 'Y'
13
+ p.type = 'string'
14
+ p.description = 'the site holding the blog'
15
+ end
16
+
17
+ m.parameter('id') do |p|
18
+ p.required = 'Y'
19
+ p.type = 'int'
20
+ p.description = 'the ID of the blog'
21
+ end
22
+
23
+ m.parameter('__token') do |p|
24
+ p.required = 'N'
25
+ p.type = 'string'
26
+ p.description = 'pagination token'
27
+ end
28
+
29
+ m.parameter('__nonce') do |p|
30
+ p.required = 'N'
31
+ p.type = 'string'
32
+ p.description = 'pagination nonce'
33
+ end
34
+
35
+ m.parameter('limit') do |p|
36
+ p.required = 'N'
37
+ p.default = '10'
38
+ p.type = 'int'
39
+ p.description = 'maximum number of results to return'
40
+ end
41
+
42
+ end
43
+
44
+ bp.method('Match') do |m|
45
+
46
+ m.synopsis = "Find a blog post by its external id"
47
+ m.http_method = "GET"
48
+ m.uri = "/sites/:site_slug/pages/blogs/:id/match"
49
+
50
+ m.parameter('site_slug') do |p|
51
+ p.required = 'Y'
52
+ p.type = 'string'
53
+ p.description = 'the site holding the blog'
54
+ end
55
+
56
+ m.parameter('id') do |p|
57
+ p.required = 'Y'
58
+ p.type = 'int'
59
+ p.description = 'the ID of the blog'
60
+ end
61
+
62
+ m.parameter('external_id') do |p|
63
+ p.required = 'N'
64
+ p.default = '1'
65
+ p.type = 'int'
66
+ p.description = 'the external id of the post'
67
+ end
68
+
69
+ end
70
+
71
+ bp.method('Create') do |m|
72
+
73
+ m.synopsis = "Creates a new blog post"
74
+ m.http_method = "POST"
75
+ m.uri = "/sites/:site_slug/pages/blogs/:blog_id/posts"
76
+
77
+ m.parameter('site_slug') do |p|
78
+ p.required = 'Y'
79
+ p.type = 'string'
80
+ p.description = 'the site holding the blog'
81
+ end
82
+
83
+ m.parameter('blog_id') do |p|
84
+ p.required = 'Y'
85
+ p.type = 'int'
86
+ p.description = 'the ID of the blog'
87
+ end
88
+
89
+ m.parameter('body') do |p|
90
+ p.required = 'Y'
91
+ p.default = '1'
92
+ p.type = 'json'
93
+ p.description = 'a JSON representation of the new post'
94
+ end
95
+
96
+ end
97
+
98
+ bp.method('Update') do |m|
99
+
100
+ m.synopsis = "Updates the attributes of a blog post"
101
+ m.http_method = "PUT"
102
+ m.uri = "/sites/:site_slug/pages/blogs/:blog_id/posts/:blog_post_id"
103
+
104
+ m.parameter('site_slug') do |p|
105
+ p.required = 'Y'
106
+ p.type = 'string'
107
+ p.description = 'the site holding the blog'
108
+ end
109
+
110
+ m.parameter('blog_id') do |p|
111
+ p.required = 'Y'
112
+ p.type = 'int'
113
+ p.description = 'the ID of the blog'
114
+ end
115
+
116
+ m.parameter('blog_post_id') do |p|
117
+ p.required = 'Y'
118
+ p.type = 'int'
119
+ p.description = 'the ID of the blog'
120
+ end
121
+
122
+ m.parameter('body') do |p|
123
+ p.required = 'Y'
124
+ p.default = '1'
125
+ p.type = 'json'
126
+ p.description = 'JSON containing updates'
127
+ end
128
+
129
+ end
130
+
131
+ bp.method('Destroy') do |m|
132
+
133
+ m.synopsis = "Removes a blog post"
134
+ m.http_method = "DELETE"
135
+ m.uri = "/sites/:site_slug/pages/blogs/:blog_id/posts/:blog_post_id"
136
+
137
+ m.parameter('site_slug') do |p|
138
+ p.required = 'Y'
139
+ p.type = 'string'
140
+ p.description = 'the site holding the blog'
141
+ end
142
+
143
+ m.parameter('blog_id') do |p|
144
+ p.required = 'Y'
145
+ p.type = 'int'
146
+ p.description = 'the ID of the blog'
147
+ end
148
+
149
+ m.parameter('blog_post_id') do |p|
150
+ p.required = 'Y'
151
+ p.type = 'int'
152
+ p.description = 'the ID of the blog'
153
+ end
154
+
155
+
156
+ end
157
+
158
+ end
159
+
160
+ end