Class: Agents::StravaAgent
- Inherits:
-
Agent
- Object
- Agent
- Agents::StravaAgent
- Includes:
- FormConfigurable
- Defined in:
- lib/huginn_strava_agent/strava_agent.rb
Instance Method Summary collapse
- #check ⇒ Object
- #default_options ⇒ Object
- #receive(incoming_events) ⇒ Object
- #validate_options ⇒ Object
- #working? ⇒ Boolean
Instance Method Details
#check ⇒ Object
165 166 167 |
# File 'lib/huginn_strava_agent/strava_agent.rb', line 165 def check trigger_action end |
#default_options ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/huginn_strava_agent/strava_agent.rb', line 99 def { 'type' => 'get_activities', 'client_id' => '', 'client_secret' => '', 'refresh_token' => '{% credential strava_refresh_token %}', 'bearer_token' => '{% credential strava_bearer_token %}', 'per_page' => '5', 'debug' => 'false', 'expected_receive_period_in_days' => '2', } end |
#receive(incoming_events) ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'lib/huginn_strava_agent/strava_agent.rb', line 156 def receive(incoming_events) incoming_events.each do |event| interpolate_with(event) do log event trigger_action end end end |
#validate_options ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/huginn_strava_agent/strava_agent.rb', line 120 def errors.add(:base, "type has invalid value: should be 'token_refresh' 'get_activities'") if interpolated['type'].present? && !%w(token_refresh get_activities).include?(interpolated['type']) unless ['per_page'].present? || !['get_activities'].include?(['type']) errors.add(:base, "per_page is a required field") end unless ['client_id'].present? errors.add(:base, "client_id is a required field") end unless ['client_secret'].present? errors.add(:base, "client_secret is a required field") end unless ['refresh_token'].present? errors.add(:base, "refresh_token is a required field") end unless ['bearer_token'].present? errors.add(:base, "bearer_token is a required field") end if .has_key?('debug') && boolify(['debug']).nil? errors.add(:base, "if provided, debug must be true or false") end unless ['expected_receive_period_in_days'].present? && ['expected_receive_period_in_days'].to_i > 0 errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working") end end |
#working? ⇒ Boolean
152 153 154 |
# File 'lib/huginn_strava_agent/strava_agent.rb', line 152 def working? event_created_within?(['expected_receive_period_in_days']) && !recent_error_logs? end |