Module: Forecast
- Defined in:
- lib/forecasted.rb,
lib/forecast/base.rb,
lib/forecast/model.rb,
lib/forecast/client.rb,
lib/forecast/errors.rb,
lib/forecast/project.rb,
lib/forecast/version.rb,
lib/forecast/api/base.rb,
lib/forecast/aggregate.rb,
lib/forecast/timezones.rb,
lib/forecast/assignment.rb,
lib/forecast/credentials.rb,
lib/forecast/api/projects.rb,
lib/forecast/hardy_client.rb,
lib/forecast/behavior/crud.rb,
lib/forecast/api/aggregates.rb,
lib/forecast/api/assignments.rb,
lib/forecast/behavior/activatable.rb
Defined Under Namespace
Modules: API, Behavior, Model, Timezones Classes: Aggregate, Assignment, AuthenticationFailed, BadRequest, Base, Client, HTTPError, HardyClient, InformHarvest, NotFound, OAuthCredentials, Project, RateLimited, ServerError, Unavailable
Constant Summary collapse
- VERSION =
"0.1.0"- FORECAST_DATE_FORMAT =
"%Y-%m-%d"
Class Method Summary collapse
-
.client(ops = {}) ⇒ Forecast::Base
Creates a standard client that will raise all errors it encounters.
-
.hardy_client(ops = {}, retries = 5) ⇒ Forecast::HardyClient
Creates a hardy client that will retry common HTTP errors it encounters and sleep() if it determines it is over your rate limit.
Class Method Details
.client(ops = {}) ⇒ Forecast::Base
Creates a standard client that will raise all errors it encounters
Options
-
Basic Authentication
-
:subdomain- Your HarvestForecast subdomain -
:username- Your HarvestForecast username -
:password- Your HarvestForecast password
-
-
OAuth
-
:access_token- An OAuth 2.0 access token
-
Examples
Forecast.client(subdomain: 'mysubdomain', username: 'myusername', password: 'mypassword')
Forecast.client(access_token: 'myaccesstoken')
def client(subdomain: nil, username: nil, password: nil, access_token: nil)
46 47 48 49 |
# File 'lib/forecasted.rb', line 46 def client(ops={}) # Forecast::Base.new(subdomain: subdomain, username: username, password: password, access_token: access_token) Forecast::Base.new(ops) end |
.hardy_client(ops = {}, retries = 5) ⇒ Forecast::HardyClient
Creates a hardy client that will retry common HTTP errors it encounters and sleep() if it determines it is over your rate limit
Options
-
Basic Authentication
-
:subdomain- Your HarvestForecast subdomain -
:username- Your HarvestForecast username -
:password- Your HarvestForecast password
-
-
OAuth
-
:access_token- An OAuth 2.0 access token
-
-
:retry- How many times the hardy client should retry errors. Set to5by default.
Examples
Forecast.hardy_client(subdomain: 'mysubdomain', username: 'myusername', password: 'mypassword', retry: 3)
Forecast.hardy_client(access_token: 'myaccesstoken', retries: 3)
Errors
The hardy client will retry the following errors
-
Forecast::Unavailable
-
Forecast::InformHarvest
-
Net::HTTPError
-
Net::HTTPFatalError
-
Errno::ECONNRESET
Rate Limits
The hardy client will make as many requests as it can until it detects it has gone over the rate limit. Then it will sleep() for the how ever long it takes for the limit to reset. You can find more information about the Rate Limiting at www.getforecast.com/api
def hardy_client(subdomain: nil, username: nil, password: nil, access_token: nil, retries: 5)
82 83 84 85 |
# File 'lib/forecasted.rb', line 82 def hardy_client(ops={}, retries=5) # Forecast::HardyClient.new(client(subdomain: subdomain, username: username, password: password, access_token: access_token), retries) Forecast::HardyClient.new(client(ops), retries) end |