Class: Playapi::Feature
- Extended by:
- Utils
- Defined in:
- lib/playapi/feature.rb
Direct Known Subclasses
Foursquare, Instagrabber, Picking, Snapchatter, TwitterScraper, VineScraper, Voting
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#campaign_id ⇒ Object
readonly
Returns the value of attribute campaign_id.
-
#default_points ⇒ Object
readonly
Returns the value of attribute default_points.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#live ⇒ Object
readonly
Returns the value of attribute live.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.create(type, opts) ⇒ Object
Create a new feature for authed campaign.
-
.destroy(id) ⇒ Object
destroy a feature.
-
.find_by_facet(opts) ⇒ Object
pass in a hash of options to find things, options include: type and name returns an array name=String type=String.
-
.get(id) ⇒ Object
Fetch a feature by id.
-
.list ⇒ Object
Get a list of features for auth campaign TODO: add filters and options.
-
.update(id, opts) ⇒ Object
Update a feature with the given id See create for field details.
Instance Method Summary collapse
Methods included from Utils
Methods inherited from Identity
#==, fetch, #initialize, store
Methods inherited from Base
#[], attr_reader, fetch, fetch_or_new, from_response, identity_map, #initialize, store, #update
Constructor Details
This class inherits a constructor from Playapi::Identity
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
12 13 14 |
# File 'lib/playapi/feature.rb', line 12 def attrs @attrs end |
#campaign_id ⇒ Object (readonly)
Returns the value of attribute campaign_id.
12 13 14 |
# File 'lib/playapi/feature.rb', line 12 def campaign_id @campaign_id end |
#default_points ⇒ Object (readonly)
Returns the value of attribute default_points.
12 13 14 |
# File 'lib/playapi/feature.rb', line 12 def default_points @default_points end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/playapi/feature.rb', line 12 def id @id end |
#live ⇒ Object (readonly)
Returns the value of attribute live.
12 13 14 |
# File 'lib/playapi/feature.rb', line 12 def live @live end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/playapi/feature.rb', line 12 def name @name end |
Class Method Details
.create(type, opts) ⇒ Object
Create a new feature for authed campaign
Type is a string that corresponds to a Playapi Feature class
Valid options are:
type=STRING (Valid Options: Picking, Voting, Instagrabber, TwitterScraper, Foursquare)
Required fields for ALL types (opts) :name=STRING :description=STRING
Required fields for Instagrabber, TwitterScraper, Foursquare :default_points=FLOAT (Default is 0)
Required fields for Instagrabber, TwitterScraper :hashtags=Array (Array of hashtags to watch)
61 62 63 64 65 66 |
# File 'lib/playapi/feature.rb', line 61 def create(type, opts) url = "api/v2/features" #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, "feature", url, {:feature => opts, :type => type}) end |
.destroy(id) ⇒ Object
destroy a feature
77 78 79 80 |
# File 'lib/playapi/feature.rb', line 77 def destroy(id) url = "api/v2/features/#{id}" get_object(:delete, "feature", url) end |
.find_by_facet(opts) ⇒ Object
pass in a hash of options to find things, options include: type and name returns an array name=String type=String
85 86 87 88 |
# File 'lib/playapi/feature.rb', line 85 def find_by_facet(opts) url = "api/v2/features/facet" get_objects(:get, :features, url, opts) end |
.get(id) ⇒ Object
Fetch a feature by id
39 40 41 42 |
# File 'lib/playapi/feature.rb', line 39 def get(id) url = "api/v2/features/#{id}" get_object(:get, "feature", url) end |
.list ⇒ Object
Get a list of features for auth campaign TODO: add filters and options
33 34 35 36 |
# File 'lib/playapi/feature.rb', line 33 def list url = "api/v2/features" get_objects(:get, "features", url) end |
.update(id, opts) ⇒ Object
Update a feature with the given id See create for field details.
71 72 73 74 |
# File 'lib/playapi/feature.rb', line 71 def update(id, opts) url = "api/v2/features/#{id}" get_object(:put, "feature", url, {:feature => opts}) end |
Instance Method Details
#campaign ⇒ Object
26 27 28 |
# File 'lib/playapi/feature.rb', line 26 def campaign Playapi::Campaign.get(@attrs["campaign_id"]) end |
#destroy ⇒ Object
22 23 24 |
# File 'lib/playapi/feature.rb', line 22 def destroy Playapi::Feature.destroy(id) end |
#interactions ⇒ Object
14 15 16 |
# File 'lib/playapi/feature.rb', line 14 def interactions Playapi::Interaction.by_feature(id) end |
#push ⇒ Object
18 19 20 |
# File 'lib/playapi/feature.rb', line 18 def push Playapi::Feature.update(id, @attrs) end |