pco_api 1.1.2 → 1.2.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 +4 -4
- data/README.md +32 -23
- data/lib/pco/api/errors.rb +38 -13
- data/lib/pco/api/version.rb +1 -1
- metadata +4 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d1dc3d66fb23d3d8a8c5c76b90518ffc7782d797
         | 
| 4 | 
            +
              data.tar.gz: 45679ff9c0d32e87f7f29004295070d85db456df
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 | 
            -
                  " | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 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 | 
            -
                " | 
| 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 | 
            -
                " | 
| 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 |  | 
    
        data/lib/pco/api/errors.rb
    CHANGED
    
    | @@ -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 | 
            -
                      @ | 
| 11 | 
            +
                      @detail = response.body
         | 
| 12 12 | 
             
                    end
         | 
| 13 13 |  | 
| 14 14 | 
             
                    def to_s
         | 
| 15 | 
            -
                       | 
| 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=#{ | 
| 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 | 
| 24 | 
            -
                  class BadRequest | 
| 25 | 
            -
                  class Unauthorized | 
| 26 | 
            -
                  class Forbidden | 
| 27 | 
            -
                  class NotFound | 
| 28 | 
            -
                  class MethodNotAllowed | 
| 29 | 
            -
                  class UnprocessableEntity | 
| 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 | 
| 32 | 
            -
                  class InternalServerError | 
| 56 | 
            +
                  class ServerError         < BaseError;   end # 500..599
         | 
| 57 | 
            +
                  class InternalServerError < ServerError; end # 500
         | 
| 33 58 | 
             
                end
         | 
| 34 59 | 
             
              end
         | 
| 35 60 | 
             
            end
         | 
    
        data/lib/pco/api/version.rb
    CHANGED
    
    
    
        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. | 
| 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- | 
| 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. | 
| 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: 
         |