Skip to content

Commit

Permalink
more doc improvements (Shopify#1185)
Browse files Browse the repository at this point in the history
* Rails context links, cleaned up  removed methods

* remove session issues docs as session storage has been removed
  • Loading branch information
nelsonwittwer committed Jul 20, 2023
1 parent f341d99 commit 77ab36c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 60 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ You can use this library in any application that has a Ruby backend, since it do

**Note**: These instructions apply to v10 or later of this package. If you're running v9 in your app, you can find the documentation [in this branch](https://github.com/Shopify/shopify-api-ruby/tree/v9).

## Use with Rails
If using in the Rails framework, we highly recommend you use the [shopify_app](https://github.com/Shopify/shopify_app) gem to interact with this gem. Authentication, session storage, webhook regirstration, and other frequenly implemented paths are managed in that gem with easy to use configurations.

## Requirements

To follow these usage guides, you will need to:
Expand Down Expand Up @@ -93,7 +96,7 @@ Please refer to [the documentation](docs/getting_started.md) in this repository
With this, a lot changed in how apps access the library. Here are the updates you should make when migrating to v10:

- Call `ShopifyAPI::Context.setup` when setting up your app. This class holds global configurations for your app and defines how the library behaves.
- If not using the `shopify_app` gem, your app needs to provide an implementation of `ShopifyAPI::Auth::SessionStorage` for production. Read more about this [in our documentation](docs/usage/session_storage.md).
- If not using the [shopify_app](https://github.com/Shopify/shopify_app) gem, your app needs to provide an implementation of `ShopifyAPI::Auth::SessionStorage` for production. Read more about this [in our documentation](docs/usage/session_storage.md).
- To change the `User-Agent` header, use `user_agent_prefix` in `ShopifyAPI::Context.setup`.
- Usages of the `ActiveResource` classes for REST API requests need to be refactored into the new format. You can find detailed examples on how each of the endpoints work in our [reference documentation](https://shopify.dev/docs/api/admin-rest).

Expand Down
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ You can follow our getting started guide to learn how to use this library.
- [Make a GraphQL API call](usage/graphql.md)
- [Make a Storefront API call](usage/graphql_storefront.md)
- [Webhooks](usage/webhooks.md)
- [Known issues and caveats](issues.md)
39 changes: 0 additions & 39 deletions docs/issues.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/usage/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ Once you have a [session](oauth.md#fetching-sessions) after completing oauth, yo
Below is an example

```ruby
# load the current session with SessionUtils.load_current_session
session = ShopifyAPI::Utils::SessionUtils.load_current_session(auth_header: <auth-header>, cookies: <cookies>, is_online: <true|false>)

# initalize the client
client = ShopifyAPI::Clients::Graphql::Admin.new(session: session)

Expand Down
5 changes: 5 additions & 0 deletions docs/usage/oauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Once the library is set up for your project, you'll be able to use it to start a
To do this, you can follow the steps below.
For more information on authenticating a Shopify app please see the [Types of Authentication](https://shopify.dev/docs/apps/auth#types-of-authentication) page.

## Note about Rails
If using in the Rails framework, we highly recommend you use the [shopify_app](https://github.com/Shopify/shopify_app) gem to perform OAuth.

If you aren't using Rails, you can look at how that [gem creates / stores sessions from the OAuth flow](https://github.com/Shopify/shopify_app/blob/2f90af43173041d145f578dcd6448f238b69f9fe/app/controllers/shopify_app/callback_controller.rb#L9) for further examples.

## Add a route to start OAuth

The route for starting the OAuth process (in this case `/login`) will use the library's `begin_auth` method. The method will return an `auth_route` URI that will be used for redirecting the user to the Shopify Authentication screen and a session cookie to store on the user's browser. These return values will be a hash in the form of {`auth_route`: `String`, `cookie`: `ShopifyAPI::Auth::Oauth::SessionCookie`}
Expand Down
15 changes: 5 additions & 10 deletions docs/usage/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ The Rest Admin client offers the 4 core request methods: `get`, `delete`, `post`
**Note:** _These paramaters can still be used in all methods regardless of if they are required._

## Usage Examples:
### Required Session
Every request requires a valid
[ShopifyAPI::Auth::Session](https://github.com/Shopify/shopify-api-ruby/blob/f341d998cce7429b841c2c3b4ce55a18a52823e4/lib/shopify_api/auth/session.rb).

To instantiate a session, we recommend you either use the `shopify_app` if working in Rails or refer to our [OAuth docs on constructing a session](oauth.md#fetching-sessions)

### Perform a `GET` request:

```ruby
# Load the current session to get the `accessToken`.
session = ShopifyAPI::Utils::SessionUtils.load_current_session(headers, cookies, is_online)

# Create a new client.
client = ShopifyAPI::Clients::Rest::Admin.new(session: session)

Expand All @@ -37,9 +39,6 @@ some_function(response.body)
### Perform a `POST` request:

```ruby
# Load the current session to get the `accessToken`.
session = ShopifyAPI::Utils::SessionUtils.load_current_session(headers, cookies, is_online)

# Create a new client.
client = ShopifyAPI::Clients::Rest::Admin.new(session: session)

Expand Down Expand Up @@ -78,7 +77,6 @@ After making a request, the `next_page_info` and `prev_page_info` can be found o
An example of this is shown below:

```ruby
session = ShopifyAPI::Utils::SessionUtils.load_current_session(headers, cookies, is_online)
client = ShopifyAPI::Clients::Rest::Admin.new(session: session)

response = client.get(path: "products", query: { limit: 10 })
Expand All @@ -95,8 +93,6 @@ Similarly, when using REST resources the `next_page_info` and `prev_page_info` c
An example of this is shown below:

```ruby
session = ShopifyAPI::Utils::SessionUtils.load_current_session(headers, cookies, is_online)

products = ShopifyAPI::Product.all(session: session, limit: 10)

loop do
Expand All @@ -111,7 +107,6 @@ The next/previous page_info strings can also be retrieved from the response obje
An example of this is shown below:

```ruby
session = ShopifyAPI::Utils::SessionUtils.load_current_session(headers, cookies, is_online)
client = ShopifyAPI::Clients::Rest::Admin.new(session: session)

response = client.get(path: "products", query: { limit: 10 })
Expand Down
15 changes: 9 additions & 6 deletions docs/usage/webhooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

The `shopify_api` gem provides webhook functionality to make it easy to both subscribe to and process webhooks. To implement in your app follow the steps outlined below.

## Use with Rails
If using in the Rails framework, we highly recommend you use the [shopify_app](https://github.com/Shopify/shopify_app) gem to interact with this gem. That gem handles [webhooks with a declarative configuration](https://github.com/Shopify/shopify_app/blob/main/docs/shopify_app/webhooks.md).

## Create a Webhook Handler

If you want to register for an http webhook you need to implement a webhook handler which the `shopify_api` gem can use to determine how to process your webhook. You can make multiple implementations (one per topic) or you can make one implementation capable of handling all the topics you want to subscribe to. To do this simply make a module or class that includes or extends `ShopifyAPI::Webhooks::WebhookHandler` and implement the handle method which accepts the following named parameters: topic: `String`, shop: `String`, and body: `Hash[String, untyped]`. An example implementation is shown below:

```ruby
module WebhookHandler
module WebhookHandler
include ShopifyAPI::Webhooks::Handler

class << self
Expand All @@ -31,11 +34,11 @@ If you are only interested in particular fields, you can optionally filter the d

```ruby
registration = ShopifyAPI::Webhooks::Registry.add_registration(
topic: "orders/create",
delivery_method: :http,
handler: WebhookHandler,
topic: "orders/create",
delivery_method: :http,
handler: WebhookHandler,
fields: ["number","note"] # this can also be a single comma separated string
)
)
```

**Note**: The webhooks you register with Shopify are saved in the Shopify platform, but the local `ShopifyAPI::Webhooks::Registry` needs to be reloaded whenever your server restarts.
Expand Down Expand Up @@ -75,7 +78,7 @@ ShopifyAPI::Webhooks::Registry.register(topic: "<specific-topic>", session: shop

This will return a single `ShopifyAPI::Webhooks::RegisterResult`.

## Unregister a Webhook
## Unregister a Webhook

To unregister a topic from a shop you can simply call:
```ruby
Expand Down

0 comments on commit 77ab36c

Please sign in to comment.