Skip to content

Commit

Permalink
Add section on JSON arguments to readme (#453)
Browse files Browse the repository at this point in the history
* add section on json to readme

* add PR to changelog
  • Loading branch information
jmanian committed Mar 21, 2023
1 parent df9f27c commit e1338c4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -2,7 +2,7 @@

* Your contribution here.
* [#452](https://github.com/slack-ruby/slack-ruby-client/pull/452): Automatically generate Web API multi-argument requirements from docs - [@jmanian](https://github.com/jmanian).
* [#448](https://github.com/slack-ruby/slack-ruby-client/pull/448): Automatically convert more Web API arguments to JSON-encoded strings - [@jmanian](https://github.com/jmanian).
* [#448](https://github.com/slack-ruby/slack-ruby-client/pull/448), [#453](https://github.com/slack-ruby/slack-ruby-client/pull/453): Automatically convert more Web API arguments to JSON-encoded strings - [@jmanian](https://github.com/jmanian).

### 2.1.0 (2023/03/17)

Expand Down
26 changes: 26 additions & 0 deletions README.md
Expand Up @@ -30,6 +30,7 @@ A Ruby client for the Slack [Web](https://api.slack.com/web), [RealTime Messagin
- [Get User Info](#get-user-info)
- [Search for a User](#search-for-a-user)
- [Other](#other)
- [JSON Arguments](#json-arguments)
- [Web Client Options](#web-client-options)
- [Pagination Support](#pagination-support)
- [Character Encoding](#character-encoding)
Expand Down Expand Up @@ -210,6 +211,31 @@ client.users_search(user: 'dblock')

Refer to the [Slack Web API Method Reference](https://api.slack.com/methods) for the list of all available functions.

#### JSON Arguments

The Web API expects certain arguments to be sent as JSON-encoded strings. With the client you can pass these args as ruby hashes or arrays and they will be converted automatically to JSON, or you can provide the JSON directly.

```ruby
# As ruby objects
client.chat_postMessage(
channel: 'C123456',
text: 'Hello World',
blocks: [{type: 'section', text: {type: 'mrkdwn', text: 'Hello World'}}]
)

# As a JSON string
client.chat_postMessage(
channel: 'C123456',
text: 'Hello World',
blocks: JSON.dump([{type: 'section', text: {type: 'mrkdwn', text: 'Hello World'}}])
)
client.chat_postMessage(
channel: 'C123456',
text: 'Hello World',
blocks: '[{"type":"section","text":{"type":"mrkdwn","text":"Hello World"}}]'
)
```

#### Web Client Options

You can configure the Web client either globally or via the initializer.
Expand Down

0 comments on commit e1338c4

Please sign in to comment.