class Geotrigger::Tag
Tag
objects offer ORM-ish access to all attributes of a Tag
.
Public Class Methods
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
Create a new Tag
instance and load +@data+ from the API given a Hash
with options:
- name
-
String
name of the tag
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
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
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 theTag
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
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 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
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