pco_api 1.1.0 → 1.1.1

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: 98876042745a7cd20d3682c5c55b9fab8a92a465
4
- data.tar.gz: edcdf7afa5cdf072b108b04f14a7be227764dfa3
3
+ metadata.gz: fdf363aaf74caadf35c535566554358fbabe8a86
4
+ data.tar.gz: b1222c3d2349a5617827b3256e63f53ac908d938
5
5
  SHA512:
6
- metadata.gz: f14acb70bde82951bbe7734cba538330a244c6008bc8a345895d8b843fa135f04a8e0231d6ff6885b1f481699cfc045ef08f055872c62d5cbf156d6c2f6b0d77
7
- data.tar.gz: db31e5122f5f2853cba8d16a1d0701b15d8905e5c89e4c3f9272c7c1aaa73e5b90ac31b6beeb395011b2a05dcc3bc19d976b68faf1d294e4724bb8d6f0fc89e4
6
+ metadata.gz: f2d8c40236d7c1cc27c3e51858aa42586fdfbc779143707da8293d960d2618b107ed8cd1a44a7d4be01b6b8cd929c48504ddd8f731e61d627879c783123c242a
7
+ data.tar.gz: 0d75528107787fb437955582c5492aa57d7585ddbec65ebc40f2e1435a20b4e01d908fce67a8d7235f4c41780f0dd619b83e1fd11dd8daa3244d9e0ed3f65fad
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # pco_api
2
2
 
3
- `pco_api` is a Rubygem that provides a simple wrapper around our RESTful JSON api at https://api.planningcenteronline.com.
3
+ [![Circle CI](https://circleci.com/gh/planningcenter/pco_api_ruby/tree/master.svg?style=svg)](https://circleci.com/gh/planningcenter/pco_api_ruby/tree/master)
4
+
5
+ `pco_api` is a Rubygem that provides a simple wrapper around our RESTful JSON API at https://api.planningcenteronline.com.
4
6
 
5
7
  ## Installation
6
8
 
@@ -22,22 +24,22 @@ gem install pco_api
22
24
  2. Chain path elements together as method calls.
23
25
 
24
26
  ```ruby
25
- api.people.v1.households
26
- # /people/v1/households
27
+ api.people.v2.households
28
+ # /people/v2/households
27
29
  ```
28
30
 
29
31
  3. For IDs, treat the object like a hash (use square brackets).
30
32
 
31
33
  ```ruby
32
- api.people.v1.households[1]
33
- # /people/v1/households/1
34
+ api.people.v2.households[1]
35
+ # /people/v2/households/1
34
36
  ```
35
37
 
36
38
  4. To execute the request, use `get`, `post`, `patch`, or `delete`, optionally passing arguments.
37
39
 
38
40
  ```ruby
39
- api.people.v1.households.get(order: 'name')
40
- # GET /people/v1/households?order=name
41
+ api.people.v2.households.get(order: 'name')
42
+ # GET /people/v2/households?order=name
41
43
  ```
42
44
 
43
45
  ## Example
@@ -45,8 +47,8 @@ gem install pco_api
45
47
  ```ruby
46
48
  require 'pco_api'
47
49
 
48
- api = PCO::API.new(auth_token: 'token', auth_secret: 'secret')
49
- api.people.v1.people.get(order: 'last_name')
50
+ api = PCO::API.new(basic_auth_token: 'token', basic_auth_secret: 'secret')
51
+ api.people.v2.people.get(order: 'last_name')
50
52
  ```
51
53
 
52
54
  ...which returns something like:
@@ -54,8 +56,8 @@ api.people.v1.people.get(order: 'last_name')
54
56
  ```ruby
55
57
  {
56
58
  "links" => {
57
- "self" => "https://api.planningcenteronline.com/people/v1/people?order=last_name",
58
- "next" => "https://api.planningcenteronline.com/people/v1/people?offset=25&order=last_name"
59
+ "self" => "https://api.planningcenteronline.com/people/v2/people?order=last_name",
60
+ "next" => "https://api.planningcenteronline.com/people/v2/people?offset=25&order=last_name"
59
61
  },
60
62
  "data"=> [
61
63
  {
@@ -78,7 +80,7 @@ api.people.v1.people.get(order: 'last_name')
78
80
  "updated_at" => "2015-04-10T18:59:51Z",
79
81
  "avatar" => nil,
80
82
  "links" => {
81
- "self" => "https://api.planningcenteronline.com/people/v1/people/271"
83
+ "self" => "https://api.planningcenteronline.com/people/v2/people/271"
82
84
  }
83
85
  },
84
86
  # ...
@@ -146,11 +148,11 @@ api.people.v1.people.get(order: 'last_name')
146
148
 
147
149
  ```ruby
148
150
  # collection
149
- api.people.v1.people.get(order: 'last_name')
151
+ api.people.v2.people.get(order: 'last_name')
150
152
  # => { data: array_of_resources }
151
153
 
152
154
  # single resource
153
- api.people.v1.people[1].get
155
+ api.people.v2.people[1].get
154
156
  # => { data: resource_hash }
155
157
  ```
156
158
 
@@ -160,7 +162,7 @@ api.people.v1.people[1].get
160
162
  a `{ data: { ... } }` hash.
161
163
 
162
164
  ```ruby
163
- api.people.v1.people.post(data: { first_name: 'Tim', last_name: 'Morgan' })
165
+ api.people.v2.people.post(data: { type: 'Person', attributes: { first_name: 'Tim', last_name: 'Morgan' } })
164
166
  # => { data: resource_hash }
165
167
  ```
166
168
 
@@ -170,7 +172,7 @@ api.people.v1.people.post(data: { first_name: 'Tim', last_name: 'Morgan' })
170
172
  a `{ data: { ... } }` hash.
171
173
 
172
174
  ```ruby
173
- api.people.v1.people[1].patch(data: { first_name: 'Tim', last_name: 'Morgan' })
175
+ api.people.v2.people[1].patch(data: { type: 'Person', id: 1, attributes: { first_name: 'Tim', last_name: 'Morgan' } })
174
176
  # => { data: resource_hash }
175
177
  ```
176
178
 
@@ -179,13 +181,13 @@ api.people.v1.people[1].patch(data: { first_name: 'Tim', last_name: 'Morgan' })
179
181
  `delete()` sends a DELETE request to delete an existing resource. This method returns `true` if the delete was successful.
180
182
 
181
183
  ```ruby
182
- api.people.v1.people[1].delete
184
+ api.people.v2.people[1].delete
183
185
  # => true
184
186
  ```
185
187
 
186
188
  ## Errors
187
189
 
188
- The following errors may be raised, which you should rescue in most circumstances.
190
+ The following errors may be raised by the library, depending on the API response status code.
189
191
 
190
192
  | HTTP Status Codes | Error Class |
191
193
  | ------------------- | ------------------------------------------------------------------------- |
@@ -199,15 +201,17 @@ The following errors may be raised, which you should rescue in most circumstance
199
201
  | 500 | `PCO::API::Errors::InternalServerError` < `PCO::API::Errors::ServerError` |
200
202
  | other 5xx errors | `PCO::API::Errors::ServerError` |
201
203
 
202
- The exception class has the following methods:
204
+ The exception object has the following methods:
205
+
206
+ | Method | Content |
207
+ | ------- | --------------------------------------- |
208
+ | status | HTTP status code returned by the server |
209
+ | message | the message returned by the API |
203
210
 
204
- | Method | Content |
205
- | ------- | ----------------------------------------------- |
206
- | status | HTTP status code returned by the server |
207
- | message | the body of the response returned by the server |
211
+ The `message` should be a simple string given by the API, e.g. "Resource Not Found".
208
212
 
209
- The `message` will usually be a hash (produced by parsing the response JSON),
210
- but in the case of some server errors, may be a string containing the raw response.
213
+ Alternatively, you may rescue `PCO::API::Errors::BaseError` and branch your code based on
214
+ the status code returned by calling `error.status`.
211
215
 
212
216
  ## Copyright & License
213
217
 
@@ -8,7 +8,7 @@ module PCO
8
8
 
9
9
  def initialize(response)
10
10
  @status = response.status
11
- @message = response.body
11
+ @message = response.body.is_a?(Hash) && response.body['message'] || response.body.to_s
12
12
  end
13
13
 
14
14
  def to_s
@@ -1,5 +1,5 @@
1
1
  module PCO
2
2
  module API
3
- VERSION = '1.1.0'
3
+ VERSION = '1.1.1'
4
4
  end
5
5
  end
@@ -2,35 +2,35 @@ require_relative '../../spec_helper'
2
2
  require 'json'
3
3
 
4
4
  describe PCO::API::Endpoint do
5
- let(:base) { described_class.new(auth_token: 'token', auth_secret: 'secret') }
5
+ let(:base) { described_class.new(basic_auth_token: 'token', basic_auth_secret: 'secret') }
6
6
 
7
7
  subject { base }
8
8
 
9
9
  describe '#method_missing' do
10
10
  before do
11
- @result = subject.people.v1
11
+ @result = subject.people.v2
12
12
  end
13
13
 
14
14
  it 'returns a wrapper object with updated url' do
15
15
  expect(@result).to be_a(described_class)
16
- expect(@result.url).to match(%r{/people/v1$})
16
+ expect(@result.url).to match(%r{/people/v2$})
17
17
  end
18
18
  end
19
19
 
20
20
  describe '#[]' do
21
21
  before do
22
- @result = subject.people.v1.people[1]
22
+ @result = subject.people.v2.people[1]
23
23
  end
24
24
 
25
25
  it 'returns a wrapper object with updated url' do
26
26
  expect(@result).to be_a(described_class)
27
- expect(@result.url).to match(%r{/people/v1/people/1$})
27
+ expect(@result.url).to match(%r{/people/v2/people/1$})
28
28
  end
29
29
  end
30
30
 
31
31
  describe '#get' do
32
32
  context 'given a good URL' do
33
- subject { base.people.v1 }
33
+ subject { base.people.v2 }
34
34
 
35
35
  let(:result) do
36
36
  {
@@ -42,7 +42,7 @@ describe PCO::API::Endpoint do
42
42
  end
43
43
 
44
44
  before do
45
- stub_request(:get, 'https://api.planningcenteronline.com/people/v1')
45
+ stub_request(:get, 'https://api.planningcenteronline.com/people/v2')
46
46
  .to_return(status: 200, body: { data: result }.to_json, headers: { 'Content-Type' => 'application/vnd.api+json' })
47
47
  @result = subject.get
48
48
  end
@@ -54,7 +54,7 @@ describe PCO::API::Endpoint do
54
54
  end
55
55
 
56
56
  context 'given a non-existent URL' do
57
- subject { base.people.v1.non_existent }
57
+ subject { base.people.v2.non_existent }
58
58
 
59
59
  let(:result) do
60
60
  {
@@ -64,19 +64,23 @@ describe PCO::API::Endpoint do
64
64
  end
65
65
 
66
66
  before do
67
- stub_request(:get, 'https://api.planningcenteronline.com/people/v1/non_existent')
67
+ stub_request(:get, 'https://api.planningcenteronline.com/people/v2/non_existent')
68
68
  .to_return(status: 404, body: result.to_json, headers: { 'Content-Type' => 'application/vnd.api+json' })
69
69
  end
70
70
 
71
71
  it 'raises a NotFound error' do
72
- expect {
73
- subject.get
74
- }.to raise_error(PCO::API::Errors::NotFound)
72
+ error = begin
73
+ subject.get
74
+ rescue PCO::API::Errors::NotFound => e
75
+ e
76
+ end
77
+ expect(error.status).to eq(404)
78
+ expect(error.message).to eq('Resource Not Found')
75
79
  end
76
80
  end
77
81
 
78
82
  context 'given a client error' do
79
- subject { base.people.v1.error }
83
+ subject { base.people.v2.error }
80
84
 
81
85
  let(:result) do
82
86
  {
@@ -86,7 +90,7 @@ describe PCO::API::Endpoint do
86
90
  end
87
91
 
88
92
  before do
89
- stub_request(:get, 'https://api.planningcenteronline.com/people/v1/error')
93
+ stub_request(:get, 'https://api.planningcenteronline.com/people/v2/error')
90
94
  .to_return(status: 400, body: result.to_json, headers: { 'Content-Type' => 'application/vnd.api+json' })
91
95
  end
92
96
 
@@ -98,7 +102,7 @@ describe PCO::API::Endpoint do
98
102
  end
99
103
 
100
104
  context 'given a server error' do
101
- subject { base.people.v1.error }
105
+ subject { base.people.v2.error }
102
106
 
103
107
  let(:result) do
104
108
  {
@@ -108,7 +112,7 @@ describe PCO::API::Endpoint do
108
112
  end
109
113
 
110
114
  before do
111
- stub_request(:get, 'https://api.planningcenteronline.com/people/v1/error')
115
+ stub_request(:get, 'https://api.planningcenteronline.com/people/v2/error')
112
116
  .to_return(status: 500, body: result.to_json, headers: { 'Content-Type' => 'application/vnd.api+json' })
113
117
  end
114
118
 
@@ -121,7 +125,7 @@ describe PCO::API::Endpoint do
121
125
  end
122
126
 
123
127
  describe '#post' do
124
- subject { base.people.v1.people }
128
+ subject { base.people.v2.people }
125
129
 
126
130
  let(:resource) do
127
131
  {
@@ -141,7 +145,7 @@ describe PCO::API::Endpoint do
141
145
  end
142
146
 
143
147
  before do
144
- stub_request(:post, 'https://api.planningcenteronline.com/people/v1/people')
148
+ stub_request(:post, 'https://api.planningcenteronline.com/people/v2/people')
145
149
  .to_return(status: 201, body: { data: result }.to_json, headers: { 'Content-Type' => 'application/vnd.api+json' })
146
150
  @result = subject.post(data: resource)
147
151
  end
@@ -153,7 +157,7 @@ describe PCO::API::Endpoint do
153
157
  end
154
158
 
155
159
  describe '#patch' do
156
- subject { base.people.v1.people[1] }
160
+ subject { base.people.v2.people[1] }
157
161
 
158
162
  let(:resource) do
159
163
  {
@@ -173,7 +177,7 @@ describe PCO::API::Endpoint do
173
177
  end
174
178
 
175
179
  before do
176
- stub_request(:patch, 'https://api.planningcenteronline.com/people/v1/people/1')
180
+ stub_request(:patch, 'https://api.planningcenteronline.com/people/v2/people/1')
177
181
  .to_return(status: 200, body: { data: result }.to_json, headers: { 'Content-Type' => 'application/vnd.api+json' })
178
182
  @result = subject.patch(data: resource)
179
183
  end
@@ -185,10 +189,10 @@ describe PCO::API::Endpoint do
185
189
  end
186
190
 
187
191
  describe '#delete' do
188
- subject { base.people.v1.people[1] }
192
+ subject { base.people.v2.people[1] }
189
193
 
190
194
  before do
191
- stub_request(:delete, 'https://api.planningcenteronline.com/people/v1/people/1')
195
+ stub_request(:delete, 'https://api.planningcenteronline.com/people/v2/people/1')
192
196
  .to_return(status: 204, body: '')
193
197
  @result = subject.delete
194
198
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pco_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Planning Center Online
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-05 00:00:00.000000000 Z
11
+ date: 2015-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -42,14 +42,14 @@ dependencies:
42
42
  name: excon
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.30.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.30.0
55
55
  - !ruby/object:Gem::Dependency
@@ -58,44 +58,46 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 3.2.0
61
+ version: '3.2'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 3.2.0
68
+ version: '3.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.21.0
75
+ version: '1.21'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.21.0
82
+ version: '1.21'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.10.1
89
+ version: '0.10'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.10.1
97
- description: Ruby wrapper for api.planningcenteronline.com
98
- email:
96
+ version: '0.10'
97
+ description: pco_api is a gem for working with the RESTful JSON API at api.planningcenteronline.com
98
+ using HTTP basic auth or OAuth 2.0. This library can talk to any endpoint the API
99
+ provides, since it is written to build endpoint URLs dynamically using method_missing.
100
+ email: support@planningcenteronline.com
99
101
  executables: []
100
102
  extensions: []
101
103
  extra_rdoc_files: []
@@ -109,7 +111,8 @@ files:
109
111
  - spec/pco/api/endpoint_spec.rb
110
112
  - spec/spec_helper.rb
111
113
  homepage: https://github.com/planningcenter/pco_api_ruby
112
- licenses: []
114
+ licenses:
115
+ - MIT
113
116
  metadata: {}
114
117
  post_install_message:
115
118
  rdoc_options: []
@@ -119,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
122
  requirements:
120
123
  - - ">="
121
124
  - !ruby/object:Gem::Version
122
- version: '0'
125
+ version: 2.0.0
123
126
  required_rubygems_version: !ruby/object:Gem::Requirement
124
127
  requirements:
125
128
  - - ">="
@@ -130,7 +133,7 @@ rubyforge_project:
130
133
  rubygems_version: 2.4.6
131
134
  signing_key:
132
135
  specification_version: 4
133
- summary: Ruby wrapper for api.planningcenteronline.com
136
+ summary: API wrapper for api.planningcenteronline.com
134
137
  test_files:
135
138
  - spec/pco/api/endpoint_spec.rb
136
139
  - spec/spec_helper.rb