pco_api 1.1.2 → 1.2.0

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: d2a0b33bcc7a92d15c4bc6aac5fb0056c6d06aeb
4
- data.tar.gz: d679b3d3923bba077c046e80b273a6f72a82ab74
3
+ metadata.gz: d1dc3d66fb23d3d8a8c5c76b90518ffc7782d797
4
+ data.tar.gz: 45679ff9c0d32e87f7f29004295070d85db456df
5
5
  SHA512:
6
- metadata.gz: 2b814cf14e00f50caecb6676e1064bfe2e218b8dc46ea41e495a67edf1a5ad2daf2bb693c54afbbbbd74301c415bf5509e450d394f743729a731c90ed2226a5e
7
- data.tar.gz: 305313b12a741a953a3f82f945e07dffcc70c3b86395212227b7d3a5046f6e6f33bca80815f5e994e3ea236022fdf64579cdb654670534c49cdcbf8fc3c63b2a
6
+ metadata.gz: 336847bc5528ccc12b316646a889b72475aad57e8ad27f7eae91e13c53444733517c4bf8564f32719255f1abe30182babe9ac97adf30742f9ddafd2284258f25
7
+ data.tar.gz: 9ebecfee7f1c1006047bfc967d28693e0cd6eef8a1fbed23e781b14e8290cd270bd9beb8338c05e8a9e05312f38d8a3bf7077f072d235fc78c91d6ffe14c4001
data/README.md CHANGED
@@ -63,22 +63,24 @@ api.people.v2.people.get(order: 'last_name')
63
63
  {
64
64
  "type" => "Person",
65
65
  "id" => "271",
66
- "first_name" => "Jean",
67
- "middle_name" => nil,
68
- "last_name" => "Abernathy",
69
- "birthdate" => "1885-01-01",
70
- "anniversary" => nil,
71
- "gender" => "F",
72
- "grade" => -1,
73
- "child" => false,
74
- "status" => "active",
75
- "school_type" => nil,
76
- "graduation_year" => nil,
77
- "site_administrator" => false,
78
- "people_permissions" => nil,
79
- "created_at" => "2015-04-01T20:18:22Z",
80
- "updated_at" => "2015-04-10T18:59:51Z",
81
- "avatar" => nil,
66
+ "attributes" => {
67
+ "first_name" => "Jean",
68
+ "middle_name" => nil,
69
+ "last_name" => "Abernathy",
70
+ "birthdate" => "1885-01-01",
71
+ "anniversary" => nil,
72
+ "gender" => "F",
73
+ "grade" => -1,
74
+ "child" => false,
75
+ "status" => "active",
76
+ "school_type" => nil,
77
+ "graduation_year" => nil,
78
+ "site_administrator" => false,
79
+ "people_permissions" => nil,
80
+ "created_at" => "2015-04-01T20:18:22Z",
81
+ "updated_at" => "2015-04-10T18:59:51Z",
82
+ "avatar" => nil,
83
+ },
82
84
  "links" => {
83
85
  "self" => "https://api.planningcenteronline.com/people/v2/people/271"
84
86
  }
@@ -91,7 +93,7 @@ api.people.v2.people.get(order: 'last_name')
91
93
  "next" => {
92
94
  "offset" => 25
93
95
  },
94
- "orderable_by" => [
96
+ "can_order_by" => [
95
97
  "first_name",
96
98
  "middle_name",
97
99
  "last_name",
@@ -108,7 +110,7 @@ api.people.v2.people.get(order: 'last_name')
108
110
  "created_at",
109
111
  "updated_at"
110
112
  ],
111
- "filterable_by" => [
113
+ "can_query_by" => [
112
114
  "first_name",
113
115
  "middle_name",
114
116
  "last_name",
@@ -137,7 +139,11 @@ api.people.v2.people.get(order: 'last_name')
137
139
  "name_suffix",
138
140
  "field_data",
139
141
  "apps"
140
- ]
142
+ ],
143
+ "parent" => {
144
+ "id" => "1",
145
+ "type" => "Organization"
146
+ }
141
147
  }
142
148
  }
143
149
  ```
@@ -203,13 +209,16 @@ The following errors may be raised by the library, depending on the API response
203
209
 
204
210
  The exception object has the following methods:
205
211
 
206
- | Method | Content |
207
- | ------- | --------------------------------------- |
208
- | status | HTTP status code returned by the server |
209
- | message | the message returned by the API |
212
+ | Method | Content |
213
+ | ------- | ------------------------------------------- |
214
+ | status | HTTP status code returned by the server |
215
+ | message | the message returned by the API |
216
+ | detail | the full error response returned by the API |
210
217
 
211
218
  The `message` should be a simple string given by the API, e.g. "Resource Not Found".
212
219
 
220
+ In the case of validation errors, the `message` is a summary string built from the raw `detail`.
221
+
213
222
  Alternatively, you may rescue `PCO::API::Errors::BaseError` and branch your code based on
214
223
  the status code returned by calling `error.status`.
215
224
 
@@ -4,32 +4,57 @@ module PCO
4
4
  class AuthRequiredError < StandardError; end
5
5
 
6
6
  class BaseError < StandardError
7
- attr_reader :status
7
+ attr_reader :status, :detail
8
8
 
9
9
  def initialize(response)
10
10
  @status = response.status
11
- @message = response.body.is_a?(Hash) && response.body['message'] || response.body.to_s
11
+ @detail = response.body
12
12
  end
13
13
 
14
14
  def to_s
15
- @message
15
+ message
16
+ end
17
+
18
+ def message
19
+ return detail.to_s unless detail.is_a?(Hash)
20
+ detail['message'] || validation_message || detail.to_s
16
21
  end
17
22
 
18
23
  def inspect
19
- "<#{self.class.name} status=#{@status} message=#{@message}>"
24
+ "<#{self.class.name} status=#{status} message=#{message.inspect} detail=#{detail.inspect}>"
25
+ end
26
+
27
+ private
28
+
29
+ def validation_message
30
+ return if Array(detail['errors']).empty?
31
+ errors = detail['errors'].map do |error|
32
+ error_to_string(error)
33
+ end
34
+ errors.uniq.join('; ')
35
+ end
36
+
37
+ def error_to_string(error)
38
+ return unless error.is_a?(Hash)
39
+ [
40
+ "#{error['title']}:",
41
+ error.fetch('meta', {})['resource'],
42
+ error.fetch('source', {})['parameter'],
43
+ error['detail']
44
+ ].compact.join(' ')
20
45
  end
21
46
  end
22
47
 
23
- class ClientError < BaseError; end # 400..499
24
- class BadRequest < ClientError; end # 400
25
- class Unauthorized < ClientError; end # 401
26
- class Forbidden < ClientError; end # 403
27
- class NotFound < ClientError; end # 404
28
- class MethodNotAllowed < ClientError; end # 405
29
- class UnprocessableEntity < ClientError; end # 422
48
+ class ClientError < BaseError; end # 400..499
49
+ class BadRequest < ClientError; end # 400
50
+ class Unauthorized < ClientError; end # 401
51
+ class Forbidden < ClientError; end # 403
52
+ class NotFound < ClientError; end # 404
53
+ class MethodNotAllowed < ClientError; end # 405
54
+ class UnprocessableEntity < ClientError; end # 422
30
55
 
31
- class ServerError < BaseError; end # 500..599
32
- class InternalServerError < ServerError; end # 500
56
+ class ServerError < BaseError; end # 500..599
57
+ class InternalServerError < ServerError; end # 500
33
58
  end
34
59
  end
35
60
  end
@@ -1,5 +1,5 @@
1
1
  module PCO
2
2
  module API
3
- VERSION = '1.1.2'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  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.2
4
+ version: 1.2.0
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-08 00:00:00.000000000 Z
11
+ date: 2015-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -130,10 +130,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  requirements: []
132
132
  rubyforge_project:
133
- rubygems_version: 2.4.6
133
+ rubygems_version: 2.4.5
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: API wrapper for api.planningcenteronline.com
137
137
  test_files:
138
138
  - spec/pco/api/endpoint_spec.rb
139
139
  - spec/spec_helper.rb
140
+ has_rdoc: