Helper method to make API calls

        :param endpoint: The endpoint to make the API call to
        :param get_data: data send through GET
        :param post_data: data send through POST
766839
def _req(self, endpoint, get_data=dict(), post_data=dict()):

        

        if get_data:
            request_parameter = "{}?{}".format(endpoint, urlencode(get_data))
        else:
            request_parameter = endpoint

        try:
            encdata = urlencode(post_data, True).encode('utf-8')
            response = self.oauth.request(request_parameter, data=encdata)
            self._checkResponseForErrors(response)
        except HTTPError as e:
            raise DeviantartError(e)

        return response
679897
async def create_post_request(self, method: str, params: Dict = None):
        
        if params is None:
            params = {}
        headers = {"Content-Type": "application/json"}
        payload = {
            "method": method,
            "params": [params],
            "id": next(self.idgen),
            "version": "1.0",
        }

        if self.debug > 1:
            _LOGGER.debug("> POST %s with body: %s", self.guide_endpoint, payload)

        async with aiohttp.ClientSession(headers=headers) as session:
            res = await session.post(self.guide_endpoint, json=payload, headers=headers)
            if self.debug > 1:
                _LOGGER.debug("Received %s: %s" % (res.status_code, res.text))
            if res.status != 200:
                raise SongpalException(
                    "Got a non-ok (status %s) response for %s" % (res.status, method),
                    error=await res.json()["error"],
                )

            res = await res.json()

        # TODO handle exceptions from POST? This used to raise SongpalException
        #      on requests.RequestException (Unable to get APIs).

        if "error" in res:
            raise SongpalException("Got an error for %s" % method, error=res["error"])

        if self.debug > 1:
            _LOGGER.debug("Got %s: %s", method, pf(res))

        return res
79507
def do_request method, endpoint, data = {}
      url = get_url(endpoint, method)
      options = {
        format: :json
      }

      # Allow custom HTTParty args.
      options = options.merge(@httparty_args)

      # Set headers.
      options[:headers] = {
        "User-Agent" => "WooCommerce API Client-Ruby/#{WooCommerce::VERSION}",
        "Accept" => "application/json"
      }
      options[:headers]["Content-Type"] = "application/json;charset=utf-8" if !data.empty?

      # Set basic authentication.
      if @is_ssl
        options[:verify] = @verify_ssl

        if @query_string_auth
          options.merge!(query: {
            consumer_key: @consumer_key,
            consumer_secret: @consumer_secret
          })
        else
          options.merge!(basic_auth: {
            username: @consumer_key,
            password: @consumer_secret
          })
        end
      end

      options.merge!(debug_output: $stdout) if @debug_mode
      options.merge!(body: data.to_json) if !data.empty?

      HTTParty.send(method, url, options)
    end
784136
def call(self, method, params):
        
        msgid = self._endpoint.send_request(method, params)
        while True:
            if not self._endpoint.receive_messages():
                raise EOFError("EOF")
            res = self._endpoint.get_response(msgid)
            if res:
                result, error = res
                if error is None:
                    return result
                raise RPCError(error)
            self._process_input_notification()
            self._process_input_request()
506015
def post_data(self, url, params):
        
        url = urljoin(self.endpoint, url)
        headers = {'Authorization': self.token}
        req = requests.post(url, headers=headers, data=params, verify=False)

        if req.status_code == 204:
            return True

        if req.status_code == 404:
            raise NotFoundError()

        try:
            data = req.json()
        except ValueError as e:
            raise JSONReadError(
                'Read failed from API: %s' % str(e)
            )

        if not req.ok:
            msg = [data[m] for m in ("id", "message") if m in data][1]
            raise DataReadError(msg)

        return data
378790
def do_get(endpoint, access_token):
    '''
    '''
    headers = {"Authorization": 'Bearer ' + access_token}
    headers['User-Agent'] = get_user_agent()
    return requests.get(endpoint, headers=headers).json()
1343723
def api_get(self, action, data, headers=None):
        
        return self._api_request(action, data, 'GET', headers)
1295161
def call_api(self, url, data, files={}, print_response=True):
        
        if type(url) != str:
            return False, "Url must be string"

        if type(data) != dict:
            return False, "Data must be a dict"

        if type(files) != dict:
            return False, "Files must be a dict"

        if type(print_response) != bool:
            return False, "Print_response must be boolean"

        url = self.HOST + url
        data["format"] = "json"
        cookies = {"JSESSIONID": self.JSESSIONID}

        # Add rinputs to post data
        if self.r_inputs:
            data["inputs"] = json.dumps(self.r_inputs)

        # Add routputs to post data
        if self.r_outputs:
            data["robjects"] = ",".join(self.r_outputs)

        try:
            response = requests.post(url, data=data, files=files, cookies=cookies)
        except requests.exceptions.RequestException as exception:
            self.clear_rdata()
            return 500, {"error": str(exception)}

        status_code = response.status_code

        # Print log only if required
        if print_response:
            print status_code
            print DeployRConnection.pretty_json(response.json())

        # remove rinputs and routputs
        self.clear_rdata()

        return status_code, response.json()
1158018
def users_request_create(self, data, **kwargs):
        ""
        api_path = "/api/v2/users/request_create.json"
        return self.call(api_path, method="POST", data=data, **kwargs)
768300
def get(self, data_type, options=None):
        
        if options is None:
            options = {}
        response = self._client.session.get(
            '{url}/{type}'.format(
                url=self.endpoint_url, type=data_type
            ),
            params=options
        )
        return self.process_response(response)
1035935
def get_oncall(self, **kwargs):
        """"""

        endpoint = '/'.join((self.endpoint, self.id, 'users'))

        return self.request('GET', endpoint=endpoint, query_params=kwargs)
100484
def _call(self, endpoint, data=None):
        
        data = {} if data is None else data
        try:
            data['access_token'] = self.access_token()
            return self._request(endpoint, data)
        except AccessTokenExpired:
            self._cached_access_token = None
            data['access_token'] = self.access_token()
            return self._request(endpoint, data)
800248
def post(self, endpoint, data):
        
        headers = {
            "Content-Type": "application/json",
            "Accept": "application/json",
            "x-standardize-only": "true" if self.standardize else "false",
            "x-include-invalid": "true" if self.invalid else "false",
            "x-accept-keypair": "true" if self.accept_keypair else "false",
        }
        if not self.logging:
            headers["x-suppress-logging"] = "true"

        params = {"auth-id": self.auth_id, "auth-token": self.auth_token}
        url = self.BASE_URL + endpoint
        response = self.session.post(
            url,
            json.dumps(stringify(data)),
            params=params,
            headers=headers,
            timeout=self.timeout,
        )
        if response.status_code == 200:
            return response.json()

        raise ERROR_CODES.get(response.status_code, SmartyStreetsError)
44657
def put(self, endpoint, **kwargs):
        
        return self._request(requests.put, endpoint, **kwargs)
734439
def call(self, client_data=None, api_data=None, aux_data=None, *args, **kwargs):
        
        self.build_request(client_data=client_data, api_data=api_data, aux_data=aux_data)
        self.caller = RequestCall(self.request)

        try:
            self.caller.call()
            self.response = self.caller.response

            if self.response is None:
                raise ValueError('Empty response')
            if self.response.response is None \
                    or 'response' not in self.response.response \
                    or self.response.response['response'] is None:
                raise ValueError('No result data')

            return self.response.response['response']

        except Exception as e:
            logger.debug('Exception traceback: %s' % traceback.format_exc())
            logger.info('Exception thrown %s' % e)
            raise
        pass
1254561
def get(self, endpoint: str, **kwargs) -> dict:
        """"""

        return self._request('GET', endpoint, **kwargs)
263538
def add_query_params endpoint, data
      return endpoint if data.nil? || data.empty?

      endpoint += "?" unless endpoint.include? "?"
      endpoint += "&" unless endpoint.end_with? "?"
      endpoint + URI.encode(flatten_hash(data).join("&"))
    end