planning_center 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/lib/planning_center/base.rb +1 -1
- data/lib/planning_center/client.rb +24 -4
- data/lib/planning_center/version.rb +1 -1
- data/spec/planning_center/base_spec.rb +3 -3
- data/spec/planning_center/client_spec.rb +34 -2
- data/spec/spec_helper.rb +8 -0
- metadata +1 -1
data/.travis.yml
CHANGED
data/lib/planning_center/base.rb
CHANGED
@@ -24,12 +24,26 @@ module PlanningCenter
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def get(path, headers = {})
|
27
|
-
|
28
|
-
|
27
|
+
request(:get, path, headers)
|
28
|
+
end
|
29
|
+
|
30
|
+
def post(path, body, headers = {})
|
31
|
+
request_with_body(:post, path, body, headers)
|
32
|
+
end
|
33
|
+
|
34
|
+
def put(path, body, headers = {})
|
35
|
+
request_with_body(:put, path, body, headers)
|
29
36
|
end
|
30
37
|
|
31
38
|
private
|
32
39
|
|
40
|
+
def default_headers
|
41
|
+
{
|
42
|
+
'content-type' => 'application/json',
|
43
|
+
'accept' => 'application/json'
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
33
47
|
def oauth
|
34
48
|
@oauth ||= OAuth::AccessToken.new(
|
35
49
|
consumer,
|
@@ -47,8 +61,14 @@ module PlanningCenter
|
|
47
61
|
)
|
48
62
|
end
|
49
63
|
|
50
|
-
def request(type, path, headers)
|
51
|
-
oauth.
|
64
|
+
def request(type, path, headers = {})
|
65
|
+
response = oauth.request(type, path, default_headers.merge(headers))
|
66
|
+
parse_response(response)
|
67
|
+
end
|
68
|
+
|
69
|
+
def request_with_body(type, path, body, headers = {})
|
70
|
+
response = oauth.request(type, path, body, default_headers.merge(headers))
|
71
|
+
parse_response(response)
|
52
72
|
end
|
53
73
|
|
54
74
|
def parse_response(response)
|
@@ -26,20 +26,20 @@ describe PlanningCenter::Base do
|
|
26
26
|
attrs = { 'id' => 123 }
|
27
27
|
expect(
|
28
28
|
PlanningCenter::Base.new(attrs, client).respond_to?(:id)
|
29
|
-
).to
|
29
|
+
).to be true
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'responds to methods with nil values' do
|
33
33
|
attrs = { 'name' => nil }
|
34
34
|
expect(
|
35
35
|
PlanningCenter::Base.new(attrs, client).respond_to?(:name)
|
36
|
-
).to
|
36
|
+
).to be true
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'does not respond to methods not matching hash keys' do
|
40
40
|
expect(
|
41
41
|
PlanningCenter::Base.new({}, client).respond_to?(:giraffe)
|
42
|
-
).to
|
42
|
+
).to be false
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -15,17 +15,49 @@ describe PlanningCenter::Client do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#get' do
|
18
|
+
let(:url) { '/organization.json' }
|
19
|
+
|
18
20
|
it 'makes a get request via the oauth access token' do
|
19
|
-
url = '/organization.json'
|
20
21
|
org_request = stub_get(url).to_return(body: { abc: 123 }.to_json)
|
21
22
|
client.get(url)
|
22
23
|
assert_requested org_request
|
23
24
|
end
|
24
25
|
|
25
26
|
it 'raises an APIError for a bad response' do
|
26
|
-
url = '/organization.json'
|
27
27
|
stub_get(url).to_return(body: nil.to_json)
|
28
28
|
expect { client.get(url) }.to raise_error(PlanningCenter::APIError)
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
describe '#post' do
|
33
|
+
let(:url) { '/songs.json' }
|
34
|
+
let(:body) { { abc: 123 } }
|
35
|
+
|
36
|
+
it 'makes a post request via the oauth access token' do
|
37
|
+
song_request = stub_post(url).to_return(body: body.to_json)
|
38
|
+
client.post(url, body)
|
39
|
+
assert_requested song_request
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'raises an APIError for a bad response' do
|
43
|
+
stub_post(url).to_return(body: nil.to_json)
|
44
|
+
expect { client.post(url, body) }.to raise_error(PlanningCenter::APIError)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#put' do
|
49
|
+
let(:url) { '/songs/1.json' }
|
50
|
+
let(:body) { { abc: 123 } }
|
51
|
+
|
52
|
+
it 'makes a put request via the oauth access token' do
|
53
|
+
song_request = stub_put(url).to_return(body: body.to_json)
|
54
|
+
client.put(url, body)
|
55
|
+
assert_requested song_request
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'raises an APIError for a bad response' do
|
59
|
+
stub_put(url).to_return(body: nil.to_json)
|
60
|
+
expect { client.put(url, body) }.to raise_error(PlanningCenter::APIError)
|
61
|
+
end
|
62
|
+
end
|
31
63
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -40,6 +40,14 @@ def stub_get(path)
|
|
40
40
|
stub_request(:get, pco_url(path))
|
41
41
|
end
|
42
42
|
|
43
|
+
def stub_post(path)
|
44
|
+
stub_request(:post, pco_url(path))
|
45
|
+
end
|
46
|
+
|
47
|
+
def stub_put(path)
|
48
|
+
stub_request(:put, pco_url(path))
|
49
|
+
end
|
50
|
+
|
43
51
|
def pco_url(path)
|
44
52
|
[PlanningCenter::Client::SITE, path].join
|
45
53
|
end
|