pco_api 1.0.0 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6389ae53bf68d7cd03849bc44f51776dd0c8705a
4
- data.tar.gz: d0a6ef6c002c42787f00e8e3525f407959eebbf0
3
+ metadata.gz: 98876042745a7cd20d3682c5c55b9fab8a92a465
4
+ data.tar.gz: edcdf7afa5cdf072b108b04f14a7be227764dfa3
5
5
  SHA512:
6
- metadata.gz: edad5401340bd1a6c87f7cc360c8fc09af04d2eebc61de5fed0eba57dbc8d92ce6db43253d810d786b25c475a5e8b17367e42af5d475d4276573034ca90bc374
7
- data.tar.gz: ff3c7b758c84e4331b16356689111ff717c1bf322fd2fa2888a4af3838c59360c56263e1e020c18b0a9884fcf26f8af3726d973b35d94b4928651bfc9782f0e4
6
+ metadata.gz: f14acb70bde82951bbe7734cba538330a244c6008bc8a345895d8b843fa135f04a8e0231d6ff6885b1f481699cfc045ef08f055872c62d5cbf156d6c2f6b0d77
7
+ data.tar.gz: db31e5122f5f2853cba8d16a1d0701b15d8905e5c89e4c3f9272c7c1aaa73e5b90ac31b6beeb395011b2a05dcc3bc19d976b68faf1d294e4724bb8d6f0fc89e4
data/README.md CHANGED
@@ -187,11 +187,17 @@ api.people.v1.people[1].delete
187
187
 
188
188
  The following errors may be raised, which you should rescue in most circumstances.
189
189
 
190
- | HTTP Status Codes | Error Class |
191
- | ------------------- | ------------------------------- |
192
- | 404 | `PCO::API::Errors::NotFound` |
193
- | 4xx (except 404) | `PCO::API::Errors::ClientError` |
194
- | 5xx | `PCO::API::Errors::ServerError` |
190
+ | HTTP Status Codes | Error Class |
191
+ | ------------------- | ------------------------------------------------------------------------- |
192
+ | 400 | `PCO::API::Errors::BadRequest` < `PCO::API::Errors::ClientError` |
193
+ | 401 | `PCO::API::Errors::Unauthorized` < `PCO::API::Errors::ClientError` |
194
+ | 403 | `PCO::API::Errors::Forbidden` < `PCO::API::Errors::ClientError` |
195
+ | 404 | `PCO::API::Errors::NotFound` < `PCO::API::Errors::ClientError` |
196
+ | 405 | `PCO::API::Errors::MethodNotAllowed` < `PCO::API::Errors::ClientError` |
197
+ | 422 | `PCO::API::Errors::UnprocessableEntity` < `PCO::API::Errors::ClientError` |
198
+ | other 4xx errors | `PCO::API::Errors::ClientError` |
199
+ | 500 | `PCO::API::Errors::InternalServerError` < `PCO::API::Errors::ServerError` |
200
+ | other 5xx errors | `PCO::API::Errors::ServerError` |
195
201
 
196
202
  The exception class has the following methods:
197
203
 
@@ -43,14 +43,14 @@ module PCO
43
43
 
44
44
  def post(body = {})
45
45
  @last_result = @connection.post(@url) do |req|
46
- req.body = body.to_json
46
+ req.body = _build_body(body)
47
47
  end
48
48
  _build_response(@last_result)
49
49
  end
50
50
 
51
51
  def patch(body = {})
52
52
  @last_result = @connection.patch(@url) do |req|
53
- req.body = body.to_json
53
+ req.body = _build_body(body)
54
54
  end
55
55
  _build_response(@last_result)
56
56
  end
@@ -70,10 +70,22 @@ module PCO
70
70
  case result.status
71
71
  when 200..299
72
72
  result.body
73
+ when 400
74
+ fail Errors::BadRequest, result
75
+ when 401
76
+ fail Errors::Unauthorized, result
77
+ when 403
78
+ fail Errors::Forbidden, result
73
79
  when 404
74
80
  fail Errors::NotFound, result
81
+ when 405
82
+ fail Errors::MethodNotAllowed, result
83
+ when 422
84
+ fail Errors::UnprocessableEntity, result
75
85
  when 400..499
76
86
  fail Errors::ClientError, result
87
+ when 500
88
+ fail Errors::InternalServerError, result
77
89
  when 500..599
78
90
  fail Errors::ServerError, result
79
91
  else
@@ -81,6 +93,18 @@ module PCO
81
93
  end
82
94
  end
83
95
 
96
+ def _build_body(body)
97
+ if _needs_url_encoded?
98
+ Faraday::Utils.build_nested_query(body)
99
+ else
100
+ body.to_json
101
+ end
102
+ end
103
+
104
+ def _needs_url_encoded?
105
+ @url =~ /oauth\/[a-z]+\z/
106
+ end
107
+
84
108
  def _build_endpoint(path)
85
109
  @cache[path] ||= begin
86
110
  self.class.new(
@@ -20,9 +20,16 @@ module PCO
20
20
  end
21
21
  end
22
22
 
23
- class NotFound < BaseError; end
24
- class ClientError < BaseError; end
25
- class ServerError < BaseError; end
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
30
+
31
+ class ServerError < BaseError; end # 500..599
32
+ class InternalServerError < ServerError; end # 500
26
33
  end
27
34
  end
28
35
  end
@@ -1,5 +1,5 @@
1
1
  module PCO
2
2
  module API
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.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.0.0
4
+ version: 1.1.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-03 00:00:00.000000000 Z
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.10.1
97
- description: Ruby wrapper for the RESTful PCO API
97
+ description: Ruby wrapper for api.planningcenteronline.com
98
98
  email:
99
99
  executables: []
100
100
  extensions: []
@@ -130,7 +130,7 @@ rubyforge_project:
130
130
  rubygems_version: 2.4.6
131
131
  signing_key:
132
132
  specification_version: 4
133
- summary: Ruby wrapper for the RESTful PCO API
133
+ summary: Ruby wrapper for api.planningcenteronline.com
134
134
  test_files:
135
135
  - spec/pco/api/endpoint_spec.rb
136
136
  - spec/spec_helper.rb