Class: AUXHelper::Api
- Inherits:
-
Object
- Object
- AUXHelper::Api
- Defined in:
- lib/aux_helper.rb
Overview
Instance Attribute Summary collapse
-
#api_server ⇒ Object
readonly
Returns the value of attribute api_server.
Class Method Summary collapse
-
.validate_env_variables(env_vars) ⇒ Object
return true when all environment variables are set.
Instance Method Summary collapse
- #add_comment_tap(tap_id, comment_string) ⇒ Object
- #add_drop(tap_id, options) ⇒ Object
- #add_tap(options) ⇒ Object
-
#auth_user(auth) ⇒ Object
authenticates the user with the API and returns their profile.
-
#get_config(id) ⇒ Object
Hash with attributes passed in and readable_id.
-
#get_drop(tap_id, drop_id) ⇒ Object
Description.
-
#get_orgs_by_auth_domain(auth_domain) ⇒ Object
Find orgs associated with a domain.
-
#get_orgs_by_saml_issuer(issuer) ⇒ Object
Find orgs associated with an IdP.
-
#get_tap(tap_id) ⇒ Object
Description.
-
#get_taps ⇒ Object
Description.
- #get_user(id) ⇒ Object
- #get_whitelisted_users(account_id) ⇒ Object
-
#initialize(api_server, api_key = nil) ⇒ Api
constructor
A new instance of Api.
- #lookup_alias(element_alias) ⇒ Object
- #put_config(id, config) ⇒ Object
- #set_api_key(key) ⇒ Object
-
#set_tags_tap(tap_id, tags) ⇒ Object
TAGS.
-
#signup_email(email_address) ⇒ Object
add email address to signup list returns true if successful.
- #unset_tags_tap(tap_id, tags) ⇒ Object
-
#update_counters_tap(tap_id, counter_id, amount) ⇒ Object
COUNTERS.
- #update_drop(tap_id, drop_id, options) ⇒ Object
- #update_drop_feedback(tap_id, drop_id, update) ⇒ Object
- #update_location(drop_uri, longitude, latitude) ⇒ Object
- #update_tap(tap_id, options) ⇒ Object
- #update_user(user_id, body) ⇒ Object
Constructor Details
Instance Attribute Details
#api_server ⇒ Object (readonly)
Returns the value of attribute api_server.
38 39 40 |
# File 'lib/aux_helper.rb', line 38 def api_server @api_server end |
Class Method Details
.validate_env_variables(env_vars) ⇒ Object
return true when all environment variables are set
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/aux_helper.rb', line 41 def self.validate_env_variables(env_vars) p "Environment variables at runtime" env_vars.all? {|env_var| if ENV.has_key? env_var p " #{env_var}=#{ENV[env_var]}" true else p " #{env_var} is not set! The application will not start." false end } end |
Instance Method Details
#add_comment_tap(tap_id, comment_string) ⇒ Object
195 196 197 198 |
# File 'lib/aux_helper.rb', line 195 def add_comment_tap(tap_id, comment_string) return if are_invalid tap_id, comment_string post "#{@api_server.to_s}/v0/taps/#{tap_id}/update", { :feedback => { :comments => [comment_string] } } end |
#add_drop(tap_id, options) ⇒ Object
124 125 126 127 |
# File 'lib/aux_helper.rb', line 124 def add_drop(tap_id, ) return if are_invalid tap_id, post "#{@api_server.to_s}/v0/taps/#{tap_id.to_s}/drops", end |
#add_tap(options) ⇒ Object
119 120 121 122 |
# File 'lib/aux_helper.rb', line 119 def add_tap() return if are_invalid post "#{@api_server.to_s}/v0/taps", end |
#auth_user(auth) ⇒ Object
authenticates the user with the API and returns their profile
135 136 137 138 139 140 141 142 143 |
# File 'lib/aux_helper.rb', line 135 def auth_user(auth) return if are_invalid auth # note - differences from 'post': (1) no .to_json (2) return response hash response_json = RestClient.post "#{@api_server.to_s}/v0/users/authenticate", auth, compute_headers(false) response = JSON.parse(response_json) response['response'] rescue => e log_error auth, e end |
#get_config(id) ⇒ Object
Returns hash with attributes passed in and readable_id.
221 222 223 224 |
# File 'lib/aux_helper.rb', line 221 def get_config(id) return if are_invalid id get "#{@api_server.to_s}/v0/configs/#{id}" end |
#get_drop(tap_id, drop_id) ⇒ Object
Description
Fetch the drop with the specified IDs
Example:
tap = api.get_tap('0123456789abcdef01234567', 5) #=> {"id" => 5, "tap_id" => "7654321fedcba9876543210", ...}
Returns nil on error.
113 114 115 116 117 |
# File 'lib/aux_helper.rb', line 113 def get_drop(tap_id, drop_id) #return if are_invalid_mongo_key tap_id return if are_invalid drop_id get "#{@api_server.to_s}/v0/taps/#{tap_id}/drops/#{drop_id.to_i}" end |
#get_orgs_by_auth_domain(auth_domain) ⇒ Object
Find orgs associated with a domain
157 158 159 160 |
# File 'lib/aux_helper.rb', line 157 def get_orgs_by_auth_domain(auth_domain) return if are_invalid auth_domain get "#{@api_server.to_s}/v0/taps?auth_domain=#{auth_domain}" end |
#get_orgs_by_saml_issuer(issuer) ⇒ Object
Find orgs associated with an IdP
163 164 165 166 |
# File 'lib/aux_helper.rb', line 163 def get_orgs_by_saml_issuer(issuer) return if are_invalid issuer get "#{@api_server.to_s}/v0/taps?saml_issuer=#{issuer}" end |
#get_tap(tap_id) ⇒ Object
Description
Fetch the tap with the specified ID
will be returned as a hash
Example:
tap = api.get_tap('0123456789abcdef01234567') #=> {"id" => "0123456789abcdef01234567", ...}
Returns nil on error.
89 90 91 92 |
# File 'lib/aux_helper.rb', line 89 def get_tap(tap_id) #return if are_invalid_mongo_key tap_id get "#{@api_server.to_s}/v0/taps/#{tap_id}" end |
#get_taps ⇒ Object
Description
Fetch all recent taps from the Alpha UX API server
Example:
drops = api.get_taps #=> [{"id" => "0123456789abcdef01234567", ...}, ...]
Returns nil on error.
TODO - add limit parameter
71 72 73 |
# File 'lib/aux_helper.rb', line 71 def get_taps get "#{@api_server.to_s}/v0/taps" end |
#get_user(id) ⇒ Object
145 146 147 148 |
# File 'lib/aux_helper.rb', line 145 def get_user(id) #return if are_invalid_mongo_key id get "#{@api_server.to_s}/v0/users/#{id}" end |
#get_whitelisted_users(account_id) ⇒ Object
150 151 152 153 154 |
# File 'lib/aux_helper.rb', line 150 def get_whitelisted_users(account_id) return if are_invalid account_id # damn... it's broken: return if are_invalid_mongo_key account_id get "#{@api_server.to_s}/v0/users/whitelist/#{account_id}" end |
#lookup_alias(element_alias) ⇒ Object
180 181 182 183 |
# File 'lib/aux_helper.rb', line 180 def lookup_alias(element_alias) return if are_invalid element_alias get "#{@api_server.to_s}/v0/aliases/#{element_alias}" end |
#put_config(id, config) ⇒ Object
227 228 229 230 |
# File 'lib/aux_helper.rb', line 227 def put_config(id, config) return if are_invalid id, config put "#{@api_server.to_s}/v0/configs/#{id}", config end |
#set_api_key(key) ⇒ Object
54 55 56 |
# File 'lib/aux_helper.rb', line 54 def set_api_key(key) @api_key = key end |
#set_tags_tap(tap_id, tags) ⇒ Object
TAGS
210 211 212 213 |
# File 'lib/aux_helper.rb', line 210 def (tap_id, ) return if are_invalid tap_id, post "#{@api_server.to_s}/v0/taps/#{tap_id}/update", {:feedback => { :set_tags => }} end |
#signup_email(email_address) ⇒ Object
add email address to signup list returns true if successful
170 171 172 173 |
# File 'lib/aux_helper.rb', line 170 def signup_email(email_address) return if are_invalid email post "#{@api_server.to_s}/v0/register", { :address => email_address.to_s } end |
#unset_tags_tap(tap_id, tags) ⇒ Object
215 216 217 218 |
# File 'lib/aux_helper.rb', line 215 def (tap_id, ) return if are_invalid tap_id, post "#{@api_server.to_s}/v0/taps/#{tap_id}/update", {:feedback => { :unset_tags => }} end |
#update_counters_tap(tap_id, counter_id, amount) ⇒ Object
COUNTERS
202 203 204 205 206 207 |
# File 'lib/aux_helper.rb', line 202 def update_counters_tap(tap_id, counter_id, amount) return if are_invalid tap_id, counter_id, amount counters_hash = Hash.new counters_hash[counter_id] = amount post "#{@api_server.to_s}/v0/taps/#{tap_id}/update", { :feedback => { :counters => counters_hash } } end |
#update_drop(tap_id, drop_id, options) ⇒ Object
129 130 131 132 |
# File 'lib/aux_helper.rb', line 129 def update_drop(tap_id, drop_id, ) return if are_invalid tap_id, put "#{@api_server.to_s}/v0/taps/#{tap_id.to_s}/drops/#{drop_id.to_s}", end |
#update_drop_feedback(tap_id, drop_id, update) ⇒ Object
175 176 177 178 |
# File 'lib/aux_helper.rb', line 175 def update_drop_feedback(tap_id, drop_id, update) return if are_invalid tap_id, drop_id, update post "#{@api_server.to_s}/v0/taps/#{tap_id}/drops/#{drop_id}/update", update end |
#update_location(drop_uri, longitude, latitude) ⇒ Object
185 186 187 188 |
# File 'lib/aux_helper.rb', line 185 def update_location(drop_uri, longitude, latitude) return if are_invalid drop_uri, longitude, latitude put drop_uri, { :location => [longitude, latitude] } end |
#update_tap(tap_id, options) ⇒ Object
94 95 96 97 |
# File 'lib/aux_helper.rb', line 94 def update_tap(tap_id, ) return if are_invalid put "#{@api_server.to_s}/v0/taps/#{tap_id}", end |
#update_user(user_id, body) ⇒ Object
190 191 192 193 |
# File 'lib/aux_helper.rb', line 190 def update_user(user_id, body) return if are_invalid user_id, body put "#{@api_server.to_s}/v0/users/#{user_id}", body end |