README.md in paypal-rest-api-0.4.0 vs README.md in paypal-rest-api-0.5.0
- old
+ new
@@ -13,16 +13,17 @@
## Features
- Supported Ruby Versions - *(2.6 .. 3.3), head, jruby-9.4, truffleruby-24*
- No dependencies;
-- Automatic authorization & reauthorization;
+- Automatic authorization & re-authorization;
- Auto-retries (configured);
- Automatically added Paypal-Request-Id header for idempotent requests if not
provided;
- Webhooks Offline verification (needs to download certificate once)
- Custom callbacks before/after request
+- Automatic pagination methods
## Usage
There are two options:
@@ -42,11 +43,11 @@
# in your business logic
PaypalAPI.live? # => false
PaypalAPI.api_url # => "https://api-m.sandbox.paypal.com"
PaypalAPI.web_url # => "https://sandbox.paypal.com"
-response = between redeploys::Orders.show(order_id)
+response = PaypalAPI::Orders.show(order_id)
response = PaypalAPI::Orders.create(body: body)
```
### Setting local client
@@ -83,27 +84,47 @@
response = PaypalAPI.patch(path, query: query, body: body, headers: headers)
response = PaypalAPI.put(path, query: query, body: body, headers: headers)
response = PaypalAPI.delete(path, query: query, body: body, headers: headers)
```
-### Parsing response
+### Response
-`response.body` is a main method that returns parsed JSON respoonse as a Hash.
+`Response` object is returned after each `API` request.
-There are also many others helpful methods:
+#### Original HTTP response data
-```ruby
-response.body # Parsed JSON. JSON is parsed lazyly, keys are symbolized.
-response[:foo] # Gets :foo attribute from parsed body
-response.fetch(:foo) # Fetches :foo attribute from parsed body
-response.http_response # original Net::HTTP::Response
-response.http_body # original response string
-response.http_status # Integer http status
-response.http_headers # Hash with response headers (keys are strings)
-response.request # Request that generates this response
-```
+- `response.http_status` - response HTTP status as Integer
+- `response.http_body` - response body as String
+- `response.http_headers` - response headers as Hash with String keys
+- `response.http_response` - original Net::HTTP::Response object
+- `response.request` - Request object that was used to get this response
+#### Parsed JSON body methods
+
+- `response.body` - parsed JSON body, keys are Symbols
+- `response[:field]` - gets `:field` attribute from parsed body,
+ returns nil if response have no such key
+- `response.fetch(:field)` - gets `:field` attribute from parsed body,
+ raises KeyError if response has no such key
+
+#### Error check methods
+
+- `response.success?` - checks HTTP status code is 2xx
+- `response.failed?` - checks HTTP status code is not 2xx
+
+#### Using HATEOAS links
+
+- `response.follow_up_link('approve', query: nil, body: nil, headers: nil)` -
+ Finds HATEOAS link is response with `rel=approve` and requests it. Returns
+ `nil` if no such link were found.
+
+#### Pagination (see [Automatic Pagination][automatic_pagination] for examples)
+
+- `response.each_page { |response| ... }` - iterates over each page in response
+- `response.each_page_item(items_field) { |item| ... }` - iterates over each
+ page item
+
## Configuration options
PaypalAPI client accepts this additional options:
- `:live`
@@ -171,10 +192,32 @@
cache: Rails.cache
# ...
)
```
+## Automatic pagination
+
+PayPal provides HATEOAS links in responses. This links can contain items with
+`rel=next` attribute. We request next pages using this links.
+
+We have two specific methods:
+
+- `Response#each_page` - iterates over each page `Response` object
+- `Response#each_page_item(items_field_name)` - iterates over items on each page
+
+Example:
+
+```ruby
+ PaypalAPI::WebhookEvents.list(page_size: 25).each_page do |response|
+ # ...
+ end
+
+ PaypalAPI::WebhookEvents.list(page_size: 25).each_page_item(:events) do |hash|
+ # ...
+ end
+```
+
## Webhoooks verification
Webhooks can be verified [offline](https://developer.paypal.com/api/rest/webhooks/rest/#link-selfverificationmethod)
or [online](https://developer.paypal.com/api/rest/webhooks/rest/#link-postbackmethod).
Method `PaypalAPI.verify_webhook(webhook_id:, headers:, raw_body:)`
@@ -512,10 +555,29 @@
- `PaypalAPI::ReferencedPayouts.create`
- `PaypalAPI::ReferencedPayouts.show`
- `PaypalAPI::ReferencedPayoutItems.create`
- `PaypalAPI::ReferencedPayoutItems.show`
+### PartnerReferrals
+
+- `PaypalAPI::PartnerReferrals.create`
+- `PaypalAPI::PartnerReferrals.show`
+
+### PaymentExperienceWebProfiles
+
+- `PaypalAPI::PaymentExperienceWebProfiles.create`
+- `PaypalAPI::PaymentExperienceWebProfiles.list`
+- `PaypalAPI::PaymentExperienceWebProfiles.show`
+- `PaypalAPI::PaymentExperienceWebProfiles.replace`
+- `PaypalAPI::PaymentExperienceWebProfiles.update`
+- `PaypalAPI::PaymentExperienceWebProfiles.delete`
+
+### TransactionSearch
+
+- `PaypalAPI::TransactionSearch.list_transactions`
+- `PaypalAPI::TransactionSearch.list_all_balances`
+
## Development
```bash
rubocop
rspec
@@ -527,5 +589,7 @@
Bug reports and pull requests are welcome on GitHub at <https://github.com/aglushkov/paypal-rest-api>.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
+
+[automatic_pagination]: #automatic-pagination