import requests


class SlackRequest(object):

    @staticmethod
    def do(token, request="?", post_data=None, domain="slack.com"):
        post_data = post_data or {}
        return requests.post(
            'https://{0}/api/{1}'.format(domain, request),
            data=dict(post_data, token=token),
        )

import json
import requests


class SlackRequest(object):

    @staticmethod
    def do(token, request="?", post_data=None, domain="slack.com"):
        post_data = post_data or {}

        for k, v in post_data.items():
            if not isinstance(v, (str, unicode)):
                post_data[k] = json.dumps(v)

        url = 'https://{0}/api/{1}'.format(domain, request)
        post_data['token'] = token

        return requests.post(url, data=post_data)

Add support for nested structure, e.g. attachments.
Add support for nested structure, e.g. attachments.

> The optional attachments argument should contain a JSON-encoded array of
> attachments.
>
> https://api.slack.com/methods/chat.postMessage

This enables simpler calls like this:

    sc.api_call('chat.postMessage', {'attachments': [{'title': 'hello'}]})

+ import json
  import requests
  
  
  class SlackRequest(object):
  
      @staticmethod
      def do(token, request="?", post_data=None, domain="slack.com"):
          post_data = post_data or {}
-         return requests.post(
-             'https://{0}/api/{1}'.format(domain, request),
-             data=dict(post_data, token=token),
-         )
  
+         for k, v in post_data.items():
+             if not isinstance(v, (str, unicode)):
+                 post_data[k] = json.dumps(v)
+ 
+         url = 'https://{0}/api/{1}'.format(domain, request)
+         post_data['token'] = token
+ 
+         return requests.post(url, data=post_data)
+ 
Add support for nested structure, e.g. attachments.
## Code Before:
import requests


class SlackRequest(object):

    @staticmethod
    def do(token, request="?", post_data=None, domain="slack.com"):
        post_data = post_data or {}
        return requests.post(
            'https://{0}/api/{1}'.format(domain, request),
            data=dict(post_data, token=token),
        )

## Instruction:
Add support for nested structure, e.g. attachments.
## Code After:
import json
import requests


class SlackRequest(object):

    @staticmethod
    def do(token, request="?", post_data=None, domain="slack.com"):
        post_data = post_data or {}

        for k, v in post_data.items():
            if not isinstance(v, (str, unicode)):
                post_data[k] = json.dumps(v)

        url = 'https://{0}/api/{1}'.format(domain, request)
        post_data['token'] = token

        return requests.post(url, data=post_data)
