planning_center 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ rvm:
5
5
  - 1.9.3
6
6
  - 2.0.0
7
7
  - 2.1.0
8
+ - 2.2.0
8
9
  addons:
9
10
  code_climate:
10
11
  repo_token:
@@ -14,7 +14,7 @@ module PlanningCenter
14
14
  end
15
15
 
16
16
  def respond_to_missing?(method_name, _include_private = false)
17
- attrs.key? method_name.to_s
17
+ attrs.key?(method_name.to_s) || super
18
18
  end
19
19
 
20
20
  private
@@ -24,12 +24,26 @@ module PlanningCenter
24
24
  end
25
25
 
26
26
  def get(path, headers = {})
27
- response = request(:get, path, headers)
28
- parse_response(response)
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.send(type.to_sym, path, headers)
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)
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module PlanningCenter
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -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 be_true
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 be_true
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 be_false
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: planning_center
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: