Method: Wechat::Api::Client#with_access_token

Defined in:
lib/wechat/api/client.rb

#with_access_token(uri, params, tried = 2) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/wechat/api/client.rb', line 74

def with_access_token(uri, params, tried = 2)
  url = format('%s%s', API_BASE, uri)
  begin
    resp = yield(url, params.merge(access_token: access_token))
    response = MultiJson.load(resp.body)
    handle_error(response)
  rescue AccessTokenExpiredError => e
    refresh
    retry unless (tried -= 1).zero?
    raise e
  end
end