pco_api 1.1.2 → 1.3.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
- SHA1:
3
- metadata.gz: d2a0b33bcc7a92d15c4bc6aac5fb0056c6d06aeb
4
- data.tar.gz: d679b3d3923bba077c046e80b273a6f72a82ab74
2
+ SHA256:
3
+ metadata.gz: eee1d9d3e7b4407dfc0b5f183021246c34a1467936fb77743c4cd45a1767b9b7
4
+ data.tar.gz: 014ec30ad0b2c1b814b10da5ee26716f55cea5bf85a782e4230feaadf7f0c260
5
5
  SHA512:
6
- metadata.gz: 2b814cf14e00f50caecb6676e1064bfe2e218b8dc46ea41e495a67edf1a5ad2daf2bb693c54afbbbbd74301c415bf5509e450d394f743729a731c90ed2226a5e
7
- data.tar.gz: 305313b12a741a953a3f82f945e07dffcc70c3b86395212227b7d3a5046f6e6f33bca80815f5e994e3ea236022fdf64579cdb654670534c49cdcbf8fc3c63b2a
6
+ metadata.gz: b36cca693f502f4c4b123aa22c61b72d41ccd51457eee7c2aef87454559d1fb7ffe85241ec97ab8832925830f864e773ce22b319d278f474245826f44bfe20e1
7
+ data.tar.gz: 3c16320118da5aee58fcec347cae41df8c215d176331863d61d079a0b47bbc23998816ff09dbecbce888177faa7847da2f13f66fe4c984622fb74cb641eb9372
data/README.md CHANGED
@@ -42,6 +42,13 @@ gem install pco_api
42
42
  # GET /people/v2/households?order=name
43
43
  ```
44
44
 
45
+ 5. To query dataset according to `can_query_by` variables:
46
+
47
+ ```ruby
48
+ api.people.v2.people.get('where[membership]': 'Member')
49
+ # GET /people/v2/people?where[membership]=Member
50
+ ```
51
+
45
52
  ## Example
46
53
 
47
54
  ```ruby
@@ -63,22 +70,24 @@ api.people.v2.people.get(order: 'last_name')
63
70
  {
64
71
  "type" => "Person",
65
72
  "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,
73
+ "attributes" => {
74
+ "first_name" => "Jean",
75
+ "middle_name" => nil,
76
+ "last_name" => "Abernathy",
77
+ "birthdate" => "1885-01-01",
78
+ "anniversary" => nil,
79
+ "gender" => "F",
80
+ "grade" => -1,
81
+ "child" => false,
82
+ "status" => "active",
83
+ "school_type" => nil,
84
+ "graduation_year" => nil,
85
+ "site_administrator" => false,
86
+ "people_permissions" => nil,
87
+ "created_at" => "2015-04-01T20:18:22Z",
88
+ "updated_at" => "2015-04-10T18:59:51Z",
89
+ "avatar" => nil,
90
+ },
82
91
  "links" => {
83
92
  "self" => "https://api.planningcenteronline.com/people/v2/people/271"
84
93
  }
@@ -91,7 +100,7 @@ api.people.v2.people.get(order: 'last_name')
91
100
  "next" => {
92
101
  "offset" => 25
93
102
  },
94
- "orderable_by" => [
103
+ "can_order_by" => [
95
104
  "first_name",
96
105
  "middle_name",
97
106
  "last_name",
@@ -108,7 +117,7 @@ api.people.v2.people.get(order: 'last_name')
108
117
  "created_at",
109
118
  "updated_at"
110
119
  ],
111
- "filterable_by" => [
120
+ "can_query_by" => [
112
121
  "first_name",
113
122
  "middle_name",
114
123
  "last_name",
@@ -137,7 +146,11 @@ api.people.v2.people.get(order: 'last_name')
137
146
  "name_suffix",
138
147
  "field_data",
139
148
  "apps"
140
- ]
149
+ ],
150
+ "parent" => {
151
+ "id" => "1",
152
+ "type" => "Organization"
153
+ }
141
154
  }
142
155
  }
143
156
  ```
@@ -197,22 +210,27 @@ The following errors may be raised by the library, depending on the API response
197
210
  | 404 | `PCO::API::Errors::NotFound` < `PCO::API::Errors::ClientError` |
198
211
  | 405 | `PCO::API::Errors::MethodNotAllowed` < `PCO::API::Errors::ClientError` |
199
212
  | 422 | `PCO::API::Errors::UnprocessableEntity` < `PCO::API::Errors::ClientError` |
213
+ | 429 | `PCO::API::Errors::TooManyRequests` < `PCO::API::Errors::ClientError` |
200
214
  | other 4xx errors | `PCO::API::Errors::ClientError` |
201
215
  | 500 | `PCO::API::Errors::InternalServerError` < `PCO::API::Errors::ServerError` |
202
216
  | other 5xx errors | `PCO::API::Errors::ServerError` |
203
217
 
204
218
  The exception object has the following methods:
205
219
 
206
- | Method | Content |
207
- | ------- | --------------------------------------- |
208
- | status | HTTP status code returned by the server |
209
- | message | the message returned by the API |
220
+ | Method | Content |
221
+ | ------- | ------------------------------------------- |
222
+ | status | HTTP status code returned by the server |
223
+ | message | the message returned by the API |
224
+ | detail | the full error response returned by the API |
225
+ | headers | hash of HTTP headers returned by the API |
210
226
 
211
227
  The `message` should be a simple string given by the API, e.g. "Resource Not Found".
212
228
 
229
+ In the case of validation errors, the `message` is a summary string built from the raw `detail`.
230
+
213
231
  Alternatively, you may rescue `PCO::API::Errors::BaseError` and branch your code based on
214
232
  the status code returned by calling `error.status`.
215
233
 
216
234
  ## Copyright & License
217
235
 
218
- Copyright 2015, Ministry Centered Technologies. Licensed MIT.
236
+ Copyright Ministry Centered Technologies. Licensed MIT.
data/lib/pco/api.rb CHANGED
@@ -4,8 +4,8 @@ require_relative 'api/errors'
4
4
  module PCO
5
5
  module API
6
6
  module_function
7
- def new(*args)
8
- Endpoint.new(*args)
7
+ def new(**args)
8
+ Endpoint.new(**args)
9
9
  end
10
10
  end
11
11
  end
@@ -5,6 +5,10 @@ module PCO
5
5
  module API
6
6
  URL = 'https://api.planningcenteronline.com'
7
7
 
8
+ class Response < Hash
9
+ attr_accessor :headers
10
+ end
11
+
8
12
  class Endpoint
9
13
  attr_reader :url, :last_result
10
14
 
@@ -69,7 +73,9 @@ module PCO
69
73
  def _build_response(result)
70
74
  case result.status
71
75
  when 200..299
72
- result.body
76
+ res = Response[result.body]
77
+ res.headers = result.headers
78
+ res
73
79
  when 400
74
80
  fail Errors::BadRequest, result
75
81
  when 401
@@ -82,6 +88,8 @@ module PCO
82
88
  fail Errors::MethodNotAllowed, result
83
89
  when 422
84
90
  fail Errors::UnprocessableEntity, result
91
+ when 429
92
+ fail Errors::TooManyRequests, result
85
93
  when 400..499
86
94
  fail Errors::ClientError, result
87
95
  when 500
@@ -116,7 +124,6 @@ module PCO
116
124
 
117
125
  def _build_connection
118
126
  Faraday.new(url: url) do |faraday|
119
- faraday.adapter :excon
120
127
  faraday.response :json, content_type: /\bjson$/
121
128
  if @basic_auth_token && @basic_auth_secret
122
129
  faraday.basic_auth @basic_auth_token, @basic_auth_secret
@@ -125,6 +132,7 @@ module PCO
125
132
  else
126
133
  fail Errors::AuthRequiredError, "You must specify either HTTP basic auth credentials or an OAuth2 access token."
127
134
  end
135
+ faraday.adapter :excon
128
136
  end
129
137
  end
130
138
  end
@@ -4,32 +4,59 @@ module PCO
4
4
  class AuthRequiredError < StandardError; end
5
5
 
6
6
  class BaseError < StandardError
7
- attr_reader :status
7
+ attr_reader :status, :detail, :headers
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
+ @headers = response.headers
12
13
  end
13
14
 
14
15
  def to_s
15
- @message
16
+ message
17
+ end
18
+
19
+ def message
20
+ return detail.to_s unless detail.is_a?(Hash)
21
+ detail['message'] || validation_message || detail.to_s
16
22
  end
17
23
 
18
24
  def inspect
19
- "<#{self.class.name} status=#{@status} message=#{@message}>"
25
+ "<#{self.class.name} status=#{status} message=#{message.inspect} detail=#{detail.inspect}>"
26
+ end
27
+
28
+ private
29
+
30
+ def validation_message
31
+ return if Array(detail['errors']).empty?
32
+ errors = detail['errors'].map do |error|
33
+ error_to_string(error)
34
+ end
35
+ errors.uniq.join('; ')
36
+ end
37
+
38
+ def error_to_string(error)
39
+ return unless error.is_a?(Hash)
40
+ [
41
+ "#{error['title']}:",
42
+ error.fetch('meta', {})['resource'],
43
+ error.fetch('source', {})['parameter'],
44
+ error['detail']
45
+ ].compact.join(' ')
20
46
  end
21
47
  end
22
48
 
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
49
+ class ClientError < BaseError; end # 400..499
50
+ class BadRequest < ClientError; end # 400
51
+ class Unauthorized < ClientError; end # 401
52
+ class Forbidden < ClientError; end # 403
53
+ class NotFound < ClientError; end # 404
54
+ class MethodNotAllowed < ClientError; end # 405
55
+ class UnprocessableEntity < ClientError; end # 422
56
+ class TooManyRequests < ClientError; end # 429
30
57
 
31
- class ServerError < BaseError; end # 500..599
32
- class InternalServerError < ServerError; end # 500
58
+ class ServerError < BaseError; end # 500..599
59
+ class InternalServerError < ServerError; end # 500
33
60
  end
34
61
  end
35
62
  end
@@ -1,5 +1,5 @@
1
1
  module PCO
2
2
  module API
3
- VERSION = '1.1.2'
3
+ VERSION = '1.3.1'
4
4
  end
5
5
  end
@@ -50,6 +50,7 @@ describe PCO::API::Endpoint do
50
50
  it 'returns the result of making a GET request to the endpoint' do
51
51
  expect(@result).to be_a(Hash)
52
52
  expect(@result['data']).to eq(result)
53
+ expect(@result.headers).to eq('Content-Type' => 'application/vnd.api+json')
53
54
  end
54
55
  end
55
56
 
@@ -76,6 +77,7 @@ describe PCO::API::Endpoint do
76
77
  end
77
78
  expect(error.status).to eq(404)
78
79
  expect(error.message).to eq('Resource Not Found')
80
+ expect(error.headers).to eq('Content-Type' => 'application/vnd.api+json')
79
81
  end
80
82
  end
81
83
 
@@ -0,0 +1,9 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe PCO::API do
4
+ describe '.new' do
5
+ it 'creates a new Endpoint instance' do
6
+ expect(described_class.new(basic_auth_token: 'abc123', basic_auth_secret: 'xyz789').class).to eq(PCO::API::Endpoint)
7
+ end
8
+ end
9
+ 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.3.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-08 00:00:00.000000000 Z
11
+ date: 2021-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.1
19
+ version: '0.10'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.1
26
+ version: '0.10'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday_middleware
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.1
33
+ version: '0.10'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.9.1
40
+ version: '0.10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: excon
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.45.3
47
+ version: 0.71.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
- version: 0.45.3
54
+ version: 0.71.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -109,6 +109,7 @@ files:
109
109
  - lib/pco/api/version.rb
110
110
  - lib/pco_api.rb
111
111
  - spec/pco/api/endpoint_spec.rb
112
+ - spec/pco/api_spec.rb
112
113
  - spec/spec_helper.rb
113
114
  homepage: https://github.com/planningcenter/pco_api_ruby
114
115
  licenses:
@@ -129,11 +130,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  - !ruby/object:Gem::Version
130
131
  version: '0'
131
132
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.4.6
133
+ rubygems_version: 3.0.3
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: API wrapper for api.planningcenteronline.com
137
137
  test_files:
138
+ - spec/pco/api_spec.rb
138
139
  - spec/pco/api/endpoint_spec.rb
139
140
  - spec/spec_helper.rb