Class: ShareProgress::Button
- Inherits:
-
Object
- Object
- ShareProgress::Button
- Defined in:
- lib/share_progress/button.rb
Instance Attribute Summary collapse
-
#advanced_options ⇒ Object
Returns the value of attribute advanced_options.
-
#auto_fill ⇒ Object
Returns the value of attribute auto_fill.
-
#button_template ⇒ Object
Returns the value of attribute button_template.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#id ⇒ Object
Returns the value of attribute id.
-
#include ⇒ Object
Returns the value of attribute include.
-
#is_active ⇒ Object
Returns the value of attribute is_active.
-
#page_title ⇒ Object
Returns the value of attribute page_title.
-
#page_url ⇒ Object
Returns the value of attribute page_url.
-
#share_button_html ⇒ Object
Returns the value of attribute share_button_html.
-
#variants ⇒ Object
Returns the value of attribute variants.
Class Method Summary collapse
- .all(limit: 100, offset: 0) ⇒ Object
- .allowed_keys ⇒ Object
- .create(page_url:, button_template:, **options) ⇒ Object
- .destroy(id) ⇒ Object
- .find(id) ⇒ Object
-
.update(options = {}) ⇒ Object
this method is used by instance.save and Button.create.
Instance Method Summary collapse
- #add_or_update_variant(variant) ⇒ Object
- #destroy ⇒ Object
- #find_variant(variant) ⇒ Object
-
#initialize(params) ⇒ Button
constructor
A new instance of Button.
- #remove_variant(variant) ⇒ Object
- #save ⇒ Object
- #update_attributes(params) ⇒ Object
Constructor Details
#initialize(params) ⇒ Button
Returns a new instance of Button.
69 70 71 72 |
# File 'lib/share_progress/button.rb', line 69 def initialize(params) @variant_collection = VariantCollection.new update_attributes(params) end |
Instance Attribute Details
#advanced_options ⇒ Object
Returns the value of attribute advanced_options.
10 11 12 |
# File 'lib/share_progress/button.rb', line 10 def @advanced_options end |
#auto_fill ⇒ Object
Returns the value of attribute auto_fill.
10 11 12 |
# File 'lib/share_progress/button.rb', line 10 def auto_fill @auto_fill end |
#button_template ⇒ Object
Returns the value of attribute button_template.
10 11 12 |
# File 'lib/share_progress/button.rb', line 10 def @button_template end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/share_progress/button.rb', line 11 def errors @errors end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/share_progress/button.rb', line 10 def id @id end |
#include ⇒ Object
Returns the value of attribute include.
10 11 12 |
# File 'lib/share_progress/button.rb', line 10 def include @include end |
#is_active ⇒ Object
Returns the value of attribute is_active.
10 11 12 |
# File 'lib/share_progress/button.rb', line 10 def is_active @is_active end |
#page_title ⇒ Object
Returns the value of attribute page_title.
10 11 12 |
# File 'lib/share_progress/button.rb', line 10 def page_title @page_title end |
#page_url ⇒ Object
Returns the value of attribute page_url.
10 11 12 |
# File 'lib/share_progress/button.rb', line 10 def page_url @page_url end |
#share_button_html ⇒ Object
Returns the value of attribute share_button_html.
10 11 12 |
# File 'lib/share_progress/button.rb', line 10 def @share_button_html end |
#variants ⇒ Object
Returns the value of attribute variants.
10 11 12 |
# File 'lib/share_progress/button.rb', line 10 def variants @variants end |
Class Method Details
.all(limit: 100, offset: 0) ⇒ Object
39 40 41 42 |
# File 'lib/share_progress/button.rb', line 39 def all(limit: 100, offset: 0) matches = Client.get endpoint, { query: { limit: limit, offset: offset } } matches.map{ |match| new(match) } end |
.allowed_keys ⇒ Object
44 45 46 |
# File 'lib/share_progress/button.rb', line 44 def allowed_keys optional_keys + required_keys end |
.create(page_url:, button_template:, **options) ⇒ Object
15 16 17 18 |
# File 'lib/share_progress/button.rb', line 15 def create(page_url:, button_template:, **) created = update(.merge(page_url: page_url, button_template: )) created.nil? ? new({}) : new(created) end |
.destroy(id) ⇒ Object
34 35 36 37 |
# File 'lib/share_progress/button.rb', line 34 def destroy(id) deleted = Client.post endpoint('delete'), { query: { id: id } } (deleted.size > 0) end |
.find(id) ⇒ Object
28 29 30 31 32 |
# File 'lib/share_progress/button.rb', line 28 def find(id) matches = Client.get endpoint('read'), { query: { id: id } } raise RecordNotFound.new("No button exists with id #{id}") if matches.size < 1 new(matches[0]) end |
.update(options = {}) ⇒ Object
this method is used by instance.save and Button.create
21 22 23 24 25 26 |
# File 'lib/share_progress/button.rb', line 21 def update(={}) Utils.filter_keys(, allowed_keys) Utils.filter_keys([:advanced_options], ) created = Client.post endpoint('update'), { body: } created[0] # the API returns a list of length 1 end |
Instance Method Details
#add_or_update_variant(variant) ⇒ Object
96 97 98 |
# File 'lib/share_progress/button.rb', line 96 def add_or_update_variant(variant) @variant_collection.add_or_update(variant) end |
#destroy ⇒ Object
108 109 110 |
# File 'lib/share_progress/button.rb', line 108 def destroy self.class.destroy(id) ? self : false end |
#find_variant(variant) ⇒ Object
104 105 106 |
# File 'lib/share_progress/button.rb', line 104 def find_variant(variant) @variant_collection.find(variant) end |
#remove_variant(variant) ⇒ Object
100 101 102 |
# File 'lib/share_progress/button.rb', line 100 def remove_variant(variant) @variant_collection.remove(variant) end |
#save ⇒ Object
82 83 84 85 86 |
# File 'lib/share_progress/button.rb', line 82 def save result = self.class.update(serialize) update_attributes(result) (errors.size == 0) end |
#update_attributes(params) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/share_progress/button.rb', line 74 def update_attributes(params) params = Utils.symbolize_keys(params) params.each_pair do |key, value| instance_variable_set("@#{key}", value) unless key == :variants end self.variants = params[:variants] if params.include? :variants end |