class Geotrigger::Tag

Tag objects offer ORM-ish access to all attributes of a Tag.

Public Class Methods

create(session, opts) click to toggle source

Create a Tag with the given Session and options. Note that Tags are automatically created by the API, if needed, when added to a Trigger or Device. This offers a way to create the Tag before applying it to anything.

s = Geotrigger::Session.new
tag = Geotrigger::Tag.create s, name: 'foo', deviceTagging: false
#=> <Geotrigger::Tag ... >
# File lib/geotrigger/tag.rb, line 16
def self.create session, opts
  t = ::Geotrigger::Tag.new session: session
  t.data = opts
  t.data[:tags] = t.data.delete :name if t.data[:name]
  t.post_create
end
new(opts = {}) click to toggle source

Create a new Tag instance and load +@data+ from the API given a Hash with options:

name

String name of the tag

Calls superclass method Geotrigger::Model::new
# File lib/geotrigger/tag.rb, line 28
def initialize opts = {}
  super opts
  if opts[:name] and @data.nil?
    grok_self_from post('tag/list', tags: opts[:name]), opts[:name]
  end
end

Public Instance Methods

devices(params = {}) click to toggle source

Return an Array of Device objects in this Application that have this tag applied to them.

params

Hash any additional parameters to include in the request (device/list)

# File lib/geotrigger/tag.rb, line 49
def devices params = {}
  post_list 'devices', params, tags: name
end
grok_self_from(data, name = nil) click to toggle source

Reads the data specific to this Tag from the API response and sets it in +@data+.

data

Hash the API response

name

String the name of the Tag to pull out

# File lib/geotrigger/tag.rb, line 79
def grok_self_from data, name = nil
  @data = data['tags'].select {|t| t['name'] == (name || @data['name'])}.first
end
post_create() click to toggle source

Creates a tag by POSTing to tag/permissions/update with +@data+.

# File lib/geotrigger/tag.rb, line 55
def post_create
  post_data = @data.dup
  grok_self_from post('tag/permissions/update', post_data), @data[:tags]
  self
end
post_update() click to toggle source

POST the tag’s +@data+ to the API via ‘tag/permissions/update’, and return the same object with the new +@data+ returned from API call.

# File lib/geotrigger/tag.rb, line 64
def post_update
  raise StateError.new 'device access_token prohibited' if @session.device?
  post_data = @data.dup
  post_data['tags'] = post_data.delete 'name'
  grok_self_from post 'tag/permissions/update', post_data
  self
end
Also aliased as: save
save()
Alias for: post_update
triggers(params = {}) click to toggle source

Return an Array of Trigger objects in this Application that have this tag applied to them.

params

Hash any additional parameters to include in the request (trigger/list)

# File lib/geotrigger/tag.rb, line 40
def triggers params = {}
  post_list 'triggers', params, tags: name
end