nation_builder 0.0.3 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +5 -4
- data/VERSION +1 -1
- data/lib/nation_builder/client.rb +5 -1
- data/lib/nation_builder/people.rb +17 -2
- data/nation_builder.gemspec +10 -3
- data/spec/client_spec.rb +1 -0
- data/spec/fixtures/not_found +1 -0
- data/spec/fixtures/people_list_empty +1 -0
- data/spec/fixtures/people_list_success +1 -0
- data/spec/people_spec.rb +32 -1
- data/spec/spec_helper.rb +5 -1
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e5da2ccce139f8e49b386b72018157e0f5d4d1a
|
4
|
+
data.tar.gz: 62663da2e7aecc665b36d1950a26df7949bfbc6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 801be53fd22a2e9fd90aacbc5369e6c27bec40bdd9d243f5a9d0e43f82706943c6b176caece51917908355aa97605e5bd17253ea68187e8b56488759ac162181
|
7
|
+
data.tar.gz: 8c1fc92e0f1df84b200e2bac16d0deceb0c592ab7508008140c87ce320520bc3372a229b9c92083947f9fe4ea69dcb1cf9a059f284c0927659017c8d8d96a60f
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -36,8 +36,8 @@ GEM
|
|
36
36
|
nokogiri (~> 1.5.2)
|
37
37
|
oauth2
|
38
38
|
hashie (2.0.5)
|
39
|
-
highline (1.6.
|
40
|
-
jeweler (1.8.
|
39
|
+
highline (1.6.20)
|
40
|
+
jeweler (1.8.8)
|
41
41
|
builder
|
42
42
|
bundler (~> 1.0)
|
43
43
|
git (>= 1.2.5)
|
@@ -46,11 +46,11 @@ GEM
|
|
46
46
|
nokogiri (= 1.5.10)
|
47
47
|
rake
|
48
48
|
rdoc
|
49
|
-
json (1.8.
|
49
|
+
json (1.8.1)
|
50
50
|
jwt (0.1.8)
|
51
51
|
multi_json (>= 1.5)
|
52
52
|
method_source (0.8.2)
|
53
|
-
multi_json (1.8.
|
53
|
+
multi_json (1.8.2)
|
54
54
|
multi_xml (0.5.5)
|
55
55
|
multipart-post (1.2.0)
|
56
56
|
nokogiri (1.5.10)
|
@@ -85,6 +85,7 @@ PLATFORMS
|
|
85
85
|
DEPENDENCIES
|
86
86
|
bundler
|
87
87
|
jeweler (~> 1.8.7)
|
88
|
+
json
|
88
89
|
oauth2!
|
89
90
|
pry
|
90
91
|
pry-debugger
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
@@ -20,6 +20,10 @@ module NationBuilder
|
|
20
20
|
def post(path, opts={})
|
21
21
|
self.token.post "#{base_uri}#{path}", opts.merge(headers: headers)
|
22
22
|
end
|
23
|
+
|
24
|
+
def put(path, opts={})
|
25
|
+
self.token.put "#{base_uri}#{path}", opts.merge(headers: headers)
|
26
|
+
end
|
23
27
|
|
24
28
|
private
|
25
29
|
|
@@ -39,4 +43,4 @@ module NationBuilder
|
|
39
43
|
"https://#{hostname}/"
|
40
44
|
end
|
41
45
|
end
|
42
|
-
end
|
46
|
+
end
|
@@ -10,7 +10,7 @@ module NationBuilder
|
|
10
10
|
begin
|
11
11
|
JSON.parse(client.get('/api/v1/people/match', params: params).response.env[:body])
|
12
12
|
rescue OAuth2::Error => e
|
13
|
-
if e.code == 'no_matches'
|
13
|
+
if e.response.parsed['code'] == 'no_matches'
|
14
14
|
return nil
|
15
15
|
else
|
16
16
|
raise e
|
@@ -26,5 +26,20 @@ module NationBuilder
|
|
26
26
|
body = JSON.generate(params)
|
27
27
|
JSON.parse(client.post('/api/v1/people', body: body).response.env[:body])
|
28
28
|
end
|
29
|
+
|
30
|
+
def update id, params
|
31
|
+
body = JSON.generate(params)
|
32
|
+
JSON.parse(client.put("/api/v1/people/#{id}", body: body).response.env[:body])
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_or_update params
|
36
|
+
person = self.match('email' => params['person']['email'])
|
37
|
+
if(person)
|
38
|
+
new_person = person['person'].merge(params['person'])
|
39
|
+
self.update new_person['id'], 'person' => new_person
|
40
|
+
else
|
41
|
+
self.create params
|
42
|
+
end
|
43
|
+
end
|
29
44
|
end
|
30
|
-
end
|
45
|
+
end
|
data/nation_builder.gemspec
CHANGED
@@ -2,14 +2,15 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: nation_builder 0.0.6 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "nation_builder"
|
8
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.6"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
12
|
s.authors = ["Nathan Woodhull", "Dan Schneiderman"]
|
12
|
-
s.date = "2013-
|
13
|
+
s.date = "2013-10-28"
|
13
14
|
s.description = "Ruby wrapper for NationBuilder API"
|
14
15
|
s.email = "nathan@controlshiftlabs.com"
|
15
16
|
s.extra_rdoc_files = [
|
@@ -33,6 +34,9 @@ Gem::Specification.new do |s|
|
|
33
34
|
"lib/nation_builder/people.rb",
|
34
35
|
"nation_builder.gemspec",
|
35
36
|
"spec/client_spec.rb",
|
37
|
+
"spec/fixtures/not_found",
|
38
|
+
"spec/fixtures/people_list_empty",
|
39
|
+
"spec/fixtures/people_list_success",
|
36
40
|
"spec/nation_builder_spec.rb",
|
37
41
|
"spec/people_spec.rb",
|
38
42
|
"spec/spec_helper.rb"
|
@@ -40,7 +44,7 @@ Gem::Specification.new do |s|
|
|
40
44
|
s.homepage = "http://github.com/controlshift/nation_builder"
|
41
45
|
s.licenses = ["MIT"]
|
42
46
|
s.require_paths = ["lib"]
|
43
|
-
s.rubygems_version = "2.
|
47
|
+
s.rubygems_version = "2.1.10"
|
44
48
|
s.summary = "NationBuilder API wrapper"
|
45
49
|
|
46
50
|
if s.respond_to? :specification_version then
|
@@ -48,6 +52,7 @@ Gem::Specification.new do |s|
|
|
48
52
|
|
49
53
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
54
|
s.add_runtime_dependency(%q<oauth2>, [">= 0"])
|
55
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
51
56
|
s.add_development_dependency(%q<webmock>, [">= 0"])
|
52
57
|
s.add_development_dependency(%q<pry>, [">= 0"])
|
53
58
|
s.add_development_dependency(%q<pry-debugger>, [">= 0"])
|
@@ -56,6 +61,7 @@ Gem::Specification.new do |s|
|
|
56
61
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
|
57
62
|
else
|
58
63
|
s.add_dependency(%q<oauth2>, [">= 0"])
|
64
|
+
s.add_dependency(%q<json>, [">= 0"])
|
59
65
|
s.add_dependency(%q<webmock>, [">= 0"])
|
60
66
|
s.add_dependency(%q<pry>, [">= 0"])
|
61
67
|
s.add_dependency(%q<pry-debugger>, [">= 0"])
|
@@ -65,6 +71,7 @@ Gem::Specification.new do |s|
|
|
65
71
|
end
|
66
72
|
else
|
67
73
|
s.add_dependency(%q<oauth2>, [">= 0"])
|
74
|
+
s.add_dependency(%q<json>, [">= 0"])
|
68
75
|
s.add_dependency(%q<webmock>, [">= 0"])
|
69
76
|
s.add_dependency(%q<pry>, [">= 0"])
|
70
77
|
s.add_dependency(%q<pry-debugger>, [">= 0"])
|
data/spec/client_spec.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"code"=>"not_found", "message"=>"Record not found"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{\"page\":20,\"total_pages\":1,\"per_page\":10,\"total\":4,\"results\":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{\"page\":1,\"total_pages\":1,\"per_page\":10,\"total\":4,\"results\":[{\"id\":4,\"external_id\":null,\"support_level\":null,\"first_name\":\"John\",\"last_name\":\"Doe\",\"email\":\"johndoe@gmail.com\",\"phone\":null,\"mobile\":null,\"birthdate\":null,\"sex\":null,\"note\":null,\"primary_address\":null,\"tags\":[],\"recruiter_id\":null,\"created_at\":\"2013-09-17T15:23:44-07:00\",\"updated_at\":\"2013-09-17T15:23:44-07:00\",\"mobile_opt_in\":true,\"email_opt_in\":true,\"is_volunteer\":false,\"is_twitter_follower\":false,\"has_facebook\":false,\"state_file_id\":null,\"nbec_guid\":null,\"van_id\":null,\"dw_id\":null,\"ngp_id\":null,\"pf_strat_id\":null,\"county_file_id\":null,\"twitter_name\":null,\"twitter_id\":null,\"salesforce_id\":null,\"civicrm_id\":null,\"linkedin_id\":null,\"employer\":null,\"occupation\":null,\"supranational_district\":null,\"federal_district\":null,\"labour_region\":null,\"state_upper_district\":null,\"state_lower_district\":null,\"city_district\":null,\"county_district\":null,\"judicial_district\":null,\"school_district\":null,\"school_sub_district\":null,\"village_district\":null,\"fire_district\":null,\"precinct_id\":null},{\"id\":3,\"external_id\":null,\"support_level\":null,\"first_name\":\"Nathan\",\"last_name\":\"Woodhull\",\"email\":\"woodhull@gmail.com\",\"phone\":null,\"mobile\":null,\"birthdate\":null,\"sex\":null,\"note\":null,\"primary_address\":{\"address1\":null,\"address2\":null,\"city\":\"Brooklyn\",\"state\":\"NY\",\"country_code\":\"US\",\"zip\":null,\"lat\":\"40.6528762\",\"lng\":\"-73.959494\"},\"tags\":[],\"recruiter_id\":null,\"created_at\":\"2013-09-16T07:39:14-07:00\",\"updated_at\":\"2013-09-16T07:40:34-07:00\",\"mobile_opt_in\":true,\"email_opt_in\":true,\"is_volunteer\":false,\"is_twitter_follower\":false,\"has_facebook\":true,\"state_file_id\":null,\"nbec_guid\":null,\"van_id\":null,\"dw_id\":null,\"ngp_id\":null,\"pf_strat_id\":null,\"county_file_id\":null,\"twitter_name\":null,\"twitter_id\":null,\"salesforce_id\":null,\"civicrm_id\":null,\"linkedin_id\":null,\"employer\":null,\"occupation\":null,\"supranational_district\":null,\"federal_district\":null,\"labour_region\":null,\"state_upper_district\":null,\"state_lower_district\":null,\"city_district\":null,\"county_district\":null,\"judicial_district\":null,\"school_district\":null,\"school_sub_district\":null,\"village_district\":null,\"fire_district\":null,\"precinct_id\":null},{\"id\":2,\"external_id\":null,\"support_level\":null,\"first_name\":\"Nathan\",\"last_name\":\"Woodhull\",\"email\":\"nathan@controlshiftlabs.com\",\"phone\":\"518-207-6768\",\"mobile\":null,\"birthdate\":null,\"sex\":null,\"note\":null,\"primary_address\":null,\"tags\":[\"customer - signed in\"],\"recruiter_id\":null,\"created_at\":\"2012-09-20T07:03:26-07:00\",\"updated_at\":\"2013-09-16T14:11:28-07:00\",\"mobile_opt_in\":true,\"email_opt_in\":true,\"is_volunteer\":false,\"is_twitter_follower\":false,\"has_facebook\":false,\"state_file_id\":null,\"nbec_guid\":null,\"van_id\":null,\"dw_id\":null,\"ngp_id\":null,\"pf_strat_id\":null,\"county_file_id\":null,\"twitter_name\":null,\"twitter_id\":null,\"salesforce_id\":null,\"civicrm_id\":null,\"linkedin_id\":null,\"employer\":null,\"occupation\":null,\"supranational_district\":null,\"federal_district\":null,\"labour_region\":null,\"state_upper_district\":null,\"state_lower_district\":null,\"city_district\":null,\"county_district\":null,\"judicial_district\":null,\"school_district\":null,\"school_sub_district\":null,\"village_district\":null,\"fire_district\":null,\"precinct_id\":null},{\"id\":1,\"external_id\":null,\"support_level\":null,\"first_name\":\"NationBuilder\",\"last_name\":\"Support\",\"email\":\"help@nationbuilder.com\",\"phone\":null,\"mobile\":null,\"birthdate\":null,\"sex\":null,\"note\":null,\"primary_address\":null,\"tags\":[],\"recruiter_id\":null,\"created_at\":\"2012-09-20T07:03:26-07:00\",\"updated_at\":\"2013-09-16T11:18:53-07:00\",\"mobile_opt_in\":true,\"email_opt_in\":false,\"is_volunteer\":false,\"is_twitter_follower\":false,\"has_facebook\":false,\"state_file_id\":null,\"nbec_guid\":null,\"van_id\":null,\"dw_id\":null,\"ngp_id\":null,\"pf_strat_id\":null,\"county_file_id\":null,\"twitter_name\":null,\"twitter_id\":null,\"salesforce_id\":null,\"civicrm_id\":null,\"linkedin_id\":null,\"employer\":null,\"occupation\":null,\"supranational_district\":null,\"federal_district\":null,\"labour_region\":null,\"state_upper_district\":null,\"state_lower_district\":null,\"city_district\":null,\"county_district\":null,\"judicial_district\":null,\"school_district\":null,\"school_sub_district\":null,\"village_district\":null,\"fire_district\":null,\"precinct_id\":null}]}
|
data/spec/people_spec.rb
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe 'People' do
|
4
|
-
|
4
|
+
describe 'list' do
|
5
|
+
|
6
|
+
let(:body) { fixture('people_get') }
|
7
|
+
let(:request_path) { '/api/v1/people' }
|
8
|
+
let(:status) { 200 }
|
9
|
+
let(:client) { NationBuilder::Client.new(hostname: 'controlshifttest.nationbuilder.com', client_id: 'be4e96f9c1c664b1903764cc425f522e4adbc3f26f0e6b52603f7e68e1ed025e', client_secret: '3dbafb54fb670fb6b2323a617d3cafbee7a83943cf5340347dcbe40fe13d93f7', username: 'nathan@controlshiftlabs.com', password: '9WRv9pZRwaUJuv') }
|
10
|
+
before(:each) do
|
11
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
12
|
+
:headers => { content_type: "application/json; charset=utf-8"})
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'on success' do
|
16
|
+
describe 'empty list' do
|
17
|
+
let(:body) { fixture('people_list_empty') }
|
18
|
+
it 'should return an empty result set if the nation is empty' do
|
19
|
+
pending "figure out how to stub oauth2"
|
20
|
+
client.people.list.should be_a(Hash)
|
21
|
+
client.people.list['results'].should be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'succesful response' do
|
26
|
+
let(:body) { fixture('people_list_success') }
|
27
|
+
it 'should return a list of people in the nation' do
|
28
|
+
pending "figure out how to stub oauth2"
|
29
|
+
|
30
|
+
client.people.list.should be_a(Hash)
|
31
|
+
client.people.list.should_not be_empty
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
5
36
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'rspec'
|
4
4
|
require 'nation_builder'
|
5
5
|
require 'webmock/rspec'
|
6
|
-
|
6
|
+
require 'json'
|
7
7
|
|
8
8
|
# Requires supporting files with custom matchers and macros, etc,
|
9
9
|
# in ./support/ and its subdirectories.
|
@@ -19,12 +19,16 @@ RSpec.configure do |config|
|
|
19
19
|
|
20
20
|
config.before(:each) do
|
21
21
|
WebMock.reset!
|
22
|
+
WebMock.allow_net_connect!
|
22
23
|
end
|
23
24
|
config.after(:each) do
|
24
25
|
WebMock.reset!
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
29
|
+
|
30
|
+
# Allow real connections
|
31
|
+
|
28
32
|
def stub_get(path)
|
29
33
|
stub_nation_builder_request(:get, path)
|
30
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nation_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Woodhull
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: json
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: webmock
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,6 +147,9 @@ files:
|
|
133
147
|
- lib/nation_builder/people.rb
|
134
148
|
- nation_builder.gemspec
|
135
149
|
- spec/client_spec.rb
|
150
|
+
- spec/fixtures/not_found
|
151
|
+
- spec/fixtures/people_list_empty
|
152
|
+
- spec/fixtures/people_list_success
|
136
153
|
- spec/nation_builder_spec.rb
|
137
154
|
- spec/people_spec.rb
|
138
155
|
- spec/spec_helper.rb
|
@@ -156,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
173
|
version: '0'
|
157
174
|
requirements: []
|
158
175
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.1.10
|
160
177
|
signing_key:
|
161
178
|
specification_version: 4
|
162
179
|
summary: NationBuilder API wrapper
|