Class: API::V1::TagsController
- Inherits:
-
ApiApplicationController
- Object
- ApiApplicationController
- API::V1::TagsController
- Defined in:
- app/controllers/api/v1/tags_controller.rb
Overview
The API tag controller.
Instance Method Summary (collapse)
-
- (Object) add_hardware_id_to_tag
Add a hardware to a nearspeak tag.
-
- (Object) create
Create a new nearspeak tag in the system.
-
- (Object) get_all_uuids
Get all supported iBeacon UUIDs from the server.
-
- (String) show
Get infos about a specific tag via the nearspeak ID.
-
- (String) show_by_hardware_id
Get infos about a specific tag via the hardware identifier.
-
- (String) show_my_tags
Show all tags from the current customer.
-
- (Object) supported_language_codes
Get all supported translation languages by bing back.
Instance Method Details
- (Object) add_hardware_id_to_tag
Add a hardware to a nearspeak tag.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'app/controllers/api/v1/tags_controller.rb', line 191 def add_hardware_id_to_tag tag = Tag.find_by_tag_identifier(params[:id]) hardware_id = params[:hardware_id] hardware_type = params[:hardware_type] #optional latitude = params[:lat] longitude = params[:lon] ble_major = params[:major] ble_minor = params[:minor] if hardware_id.nil? return_error_infos(400, 'Hardware ID is missing', 'HardwareIDMissing', nil) return end error = [] if hardware_type.nil? error << 'hardware_type' end # also require major und minor id by bluetooth beacons unless hardware_type.nil? if hardware_type == HardwaresHelper::TYPE_BLE if ble_major.nil? error << 'major' end if ble_minor.nil? error << 'minor' end end end if error.length > 0 return_error_infos(400, 'Request values are missing', 'InvalidRequest', error) return end if tag.nil? return_error_infos(400, 'Tag not found', 'TagNotFound', nil) else status, tag, error_msg, error_code = tag.add_hardware_id_to_tag(hardware_id, hardware_type, ble_major, ble_minor, latitude, longitude) if status.nil? return_error_infos(400, 'Error while updating tag', 'InvalidRequest', nil) else if status != 200 return_error_infos(status, error_msg, error_code, nil) else return_tag_infos(tag, nil) end end end end |
- (Object) create
Create a new nearspeak tag in the system.
108 109 110 111 112 113 114 115 116 117 118 119 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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'app/controllers/api/v1/tags_controller.rb', line 108 def create text = params[:text] lang_code = params[:lang] purchase_id = params[:purchase_id] # optional gender = params[:gender] auth_token = params[:auth_token] hardware_id = params[:hardware_id] hardware_type = params[:hardware_type] name = params[:name] parent_id = params[:parent_id] latitude = params[:lat] longitude = params[:lon] ble_major = params[:major] ble_minor = params[:minor] customer = nil error = [] if text.nil? error << 'text' end if lang_code.nil? error << 'lang' end if purchase_id.nil? error << 'purchase_id' end # also require major und minor id by bluetooth beacons unless hardware_type.nil? if hardware_type == HardwaresHelper::TYPE_BLE if ble_major.nil? error << 'major' end if ble_minor.nil? error << 'minor' end end end if error.length > 0 return_error_infos(400, 'Request values are missing', 'InvalidRequest', error) return end unless TranslationsHelper.is_valid_language(lang_code) return_error_infos(400, 'Wrong language code', 'WrongLanguageCode', nil) return end unless auth_token.nil? customer_token = params[:auth_token].presence customer = customer_token && Customer.find_by_auth_token(customer_token) if customer && Devise.secure_compare(customer.get_devise_auth_token, customer_token) sign_in customer, store: false end end status, tag, error_msg, error_code = Tag.create_with_data(text, lang_code, purchase_id, gender, hardware_id, hardware_type, ble_major, ble_minor, name, parent_id, latitude, longitude, customer) if status.nil? return_error_infos(400, 'Error while creating new tag', 'CreationError', nil) else if status != 200 return_error_infos(status, error_msg, error_code, nil) else if lang_code.nil? return_tag_infos(tag, nil) else return_tag_infos(tag, lang_code) end end end end |
- (Object) get_all_uuids
Get all supported iBeacon UUIDs from the server.
263 264 265 266 267 |
# File 'app/controllers/api/v1/tags_controller.rb', line 263 def get_all_uuids ble_uuids = Hardware.all_ble_uuids.map { |hw| hw.identifier } render :status => 200, :json => { :uuids => ble_uuids } end |
- (String) show
Get infos about a specific tag via the nearspeak ID.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/api/v1/tags_controller.rb', line 9 def show tag_identifier = params[:id] lang_code = params[:lang] tag = Tag.with_tag_identifier(tag_identifier).active.first unless tag.nil? # check if the tag is currently active unless tag.currently_active tag = nil end tag_scanned(tag) end return_tag_infos(tag, lang_code) end |
- (String) show_by_hardware_id
Get infos about a specific tag via the hardware identifier.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/api/v1/tags_controller.rb', line 31 def show_by_hardware_id hardware_id = params[:id] hardware_type = params[:type] # optional lang_code = params[:lang] latitude = params[:lat] longitude = params[:lon] ble_major = params[:major] ble_minor = params[:minor] error = [] if hardware_id.nil? error << 'id' end if hardware_type.nil? error << 'type' end # also require major und minor id by bluetooth beacons unless hardware_type.nil? if hardware_type == HardwaresHelper::TYPE_BLE if ble_major.nil? error << 'major' end if ble_minor.nil? error << 'minor' end end end if error.length > 0 return_error_infos(400, 'Request values are missing', 'InvalidRequest', error) return end if hardware_type == HardwaresHelper::TYPE_BLE tag = Tag.show_by_ble_hardware_id(hardware_id, hardware_type, ble_major, ble_minor) else tag = Tag.show_by_hardware_id(hardware_id, hardware_type) end # add location to hardware unless latitude.nil? and longitude.nil? and tag.nil? tag.add_location_to_hardware(hardware_id, latitude, longitude) end # update scan counter unless tag.nil? tag_scanned(tag) end return_tag_infos(tag, lang_code) end |
- (String) show_my_tags
Show all tags from the current customer.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/api/v1/tags_controller.rb', line 92 def = Tag.where('customer_id = ? AND active = ?', current_customer.id, true) if .nil? return_error_infos(400, 'No tags found', 'NoTagsFound', nil) else = [] .each { |tag| << create_tag_infos(tag, nil) } render :status => 200, :json => { :tags => } end end |
- (Object) supported_language_codes
Get all supported translation languages by bing back.
251 252 253 254 255 256 257 258 259 |
# File 'app/controllers/api/v1/tags_controller.rb', line 251 def supported_language_codes language_codes = TranslationsHelper.supported_language_codes if language_codes.empty? return_error_infos(400, 'Error no supported languages', 'TranslationError', nil) else render :status => 200, :json => { :language_codes => language_codes } end end |