Class: Playapi::Interaction

Inherits:
Identity show all
Extended by:
Utils
Defined in:
lib/playapi/interaction.rb

Direct Known Subclasses

Checkin, Custom, Instapic, Snap, Tweet, Vine

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

hi

Methods inherited from Identity

#==, fetch, #initialize, store

Methods inherited from Base

#[], attr_reader, #attrs, fetch, fetch_or_new, from_response, identity_map, #initialize, store, #update

Constructor Details

This class inherits a constructor from Playapi::Identity

Instance Attribute Details

#campaign_idObject (readonly)

Returns the value of attribute campaign_id.



13
14
15
# File 'lib/playapi/interaction.rb', line 13

def campaign_id
  @campaign_id
end

#entity_idObject (readonly)

Returns the value of attribute entity_id.



13
14
15
# File 'lib/playapi/interaction.rb', line 13

def entity_id
  @entity_id
end

#feature_idObject (readonly)

Returns the value of attribute feature_id.



13
14
15
# File 'lib/playapi/interaction.rb', line 13

def feature_id
  @feature_id
end

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/playapi/interaction.rb', line 13

def id
  @id
end

#textObject (readonly)

Returns the value of attribute text.



13
14
15
# File 'lib/playapi/interaction.rb', line 13

def text
  @text
end

Class Method Details

.classed_interaction(type = "Custom", opts = {}) ⇒ Object

Create a classed interaction for authed campaign

Type is a string corresponds to a Playapi Interaction class

Valid options are: :type=STRING (Valid Options: Custom, Instapic, Tweet)

      Instapic(:content_id, :)

ID VALUES FOR THIS CLASS ARE PROVIDED BY PLAYAPI AND MUST MATCH !!! IF THE ID VALUES DON’T MATCH, YOUR GONNA HAVE A BAD TIME !!!

Required fields for ALL types (opts) :feature_id=STRING (Playapi Feature ID ) :points=FLOAT (Points for this interaction)

:content_id=STRING  (3rd party (twitter status_id, etc) id from which content was sourced)

Required fields for Instapics :asset_url=STRING (URL of the instagram image)

Required fields for Tweet

:text=STRING        (Text from a Tweet)


108
109
110
111
112
113
# File 'lib/playapi/interaction.rb', line 108

def classed_interaction(type="Custom", opts = {})
  url = "api/v2/interactions"
  validator = "Playapi::Validation::#{type.split('_').map {|w| w.capitalize}.join}".split("::").inject(Module) {|acc, val| acc.const_get(val)}
  validator.validate(opts)
  get_object(:post, "interaction", url, {:interaction => opts, :type => type})
end

.create(opts) ⇒ Object

Create a custom interaction for your campaign Optional fields (opts) :entity_id=STRING (Playapi Entity ID - ONLY USE THIS IF YOU HAVE A PLAYAPI PROVIDED ENTITY_ID) :points=Float (Points for this interaction) WILL BE DEPRECATED IN VERSION 0.0.2, please use classed_interaction! NOT A JOKE



61
62
63
64
# File 'lib/playapi/interaction.rb', line 61

def create(opts)
  url = "api/v2/interactions"
  get_object(:post, "interaction", url, {:interaction => opts})
end

.destroy(id) ⇒ Object



72
73
74
75
# File 'lib/playapi/interaction.rb', line 72

def destroy(id)
  url = "api/v2/interactions/#{id}"
  get_object(:delete, "interaction", url)
end

.find_by_facet(opts) ⇒ Object

pass in a hash of options to find things, currently the only one that is applicable is content_id returns an array content_id=String



80
81
82
83
# File 'lib/playapi/interaction.rb', line 80

def find_by_facet(opts)
  url = "api/v2/interactions/facet"
  get_objects(:get, :interactions, url, opts)
end

.get(id) ⇒ Object

Get an interaction with the given id



51
52
53
54
# File 'lib/playapi/interaction.rb', line 51

def get(id)
  url = "api/v2/interactions/#{id}"
  get_object(:get, "interaction", url)
end

.listObject

Get interactions for a campaign, optional paramaters include Optional params hash (opts) :sort=STRING (Valid options are: leaders, newest, oldest) :approved=BOOL (Show only approved interactions) :pending=BOOL (Show only pending (unapproved) interactions) :limit=INTEGER (Limit to a number of entries, defaults to 10) :page=INTEGER (Determines the offset for limit, defaults to 1) :type=STRING (Valid options are Instapic, Tweet, Checkin)



45
46
47
48
# File 'lib/playapi/interaction.rb', line 45

def list
  url = "api/v2/interactions"
  get_objects(:get, "interactions", url)
end

.update(id, opts) ⇒ Object

Update a specific interaction for your campaign



67
68
69
70
# File 'lib/playapi/interaction.rb', line 67

def update(id, opts)
  url = "api/v2/interactions/#{id}"
  get_object(:put, "interaction", url, {:interaction => opts})
end

Instance Method Details

#campaignObject



31
32
33
# File 'lib/playapi/interaction.rb', line 31

def campaign
  Playapi::Campaign.get(@attrs["campaign_id"])
end

#destroyObject



27
28
29
# File 'lib/playapi/interaction.rb', line 27

def destroy
  Playapi::Interaction.destroy(id)
end

#entityObject



19
20
21
# File 'lib/playapi/interaction.rb', line 19

def entity
  Playapi::Entity.get(@attrs["entity_id"])
end

#featureObject



15
16
17
# File 'lib/playapi/interaction.rb', line 15

def feature
  Playapi::Feature.get(@attrs["feature_id"])
end

#pushObject



23
24
25
# File 'lib/playapi/interaction.rb', line 23

def push
  self.attrs = Playapi::Interaction.update(id, @attrs).attrs
end