Comments (3)
I had this exact same problem and used a Middleware to solve it:
module Thing
module Middleware
class APIUsage < Faraday::Response::Middleware
def initialize(app, options = {})
@app = app
@options = options
end
def call(env)
ap api_usage(env[:response_headers])
@app.call(env)
end
def api_usage(response)
return nil unless response['sforce-limit-info']
matches = response['sforce-limit-info'].match(%r{api-usage=(?<used>\d+)/(?<max>\d+)})
{ used: matches['used'].to_i, max: matches['max'].to_i } if matches
end
end
end
end
# ...
Faraday::Response.register_middleware :api_usage => lambda { Thing::Middleware::APIUsage }
client = Restforce.new
client.middleware.response :api_usage
I'm open to suggetions on how to improve this.
from restforce.
I think a configuration option that determines whether or not the client
should return the full faraday response or just the body would make sense.
On Friday, October 4, 2013, Anton Litvinenko wrote:
Salesforce returns API usage rate in Sforce-Limit-Info header:
api-usage=49/5000000.I would like to have access to that information. Is it possible with
current implementation? If not, any ideas how this could be implemented in
a most reasonable way?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/88
.
from restforce.
That would have effect on all requests. Which means that I would need to process the whole response manually. Couple of other ideas:
- to have some sort of back reference to original response or only its headers in
Restforce::Collection
orRestforce::Mash
objects - Another idea is to have an attribute on the client (e.g.
api_rates
) that would be updated with each response through middleware (I noticed thatRestforce::Middleware
has a proxy back to a client)
Wouldn't one of these work better?
from restforce.
Related Issues (20)
- Tooling API link is broken HOT 1
- Unhandled Salesforce error: INSUFFICIENT_ACCESS
- Unhandled Salesforce error: Faraday::ConnectionFailed HOT 3
- Unhandled Salesforce error: InvalidMarkup HOT 3
- Unhandled Salesforce error: Restforce::UnauthorizedError: INVALID_AUTH_HEADER: INVALID_HEADER_TYPE
- Undefined method `call' for "https://login.salesforce.com":String
- Cache is shared between different Salesforce logins HOT 2
- NoMethodError: undefined method `destroy!' for #<Restforce::Collection>
- UNKNOWN_EXCEPTION error returned by Salesforce HOT 2
- How to access next page when specifying LIMIT
- Unknown auth error from Salesforce: activation secret invalid
- Client Credentials flow for more secure server-to-server integration
- Unhandled Salesforce error: APEX_REST_SERVICES_DISABLED HOT 2
- Unhandled Salesforce error: <Faraday::ParsingError> HOT 9
- Make sure replay id is saved after processing callback HOT 7
- Minimum required version for Ruby 3.1 HOT 2
- There's no way to know if `upsert` performed a `creation` or an `update`
- Trouble Using Restforce with Ruby 3.2.2 - uninitialized constant Restforce::Middleware::Gzip::StringIO (NameError) HOT 13
- Unhandled Salesforce error: `status: 406` HOT 2
- Version 7.x requires faraday 2.x HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from restforce.