Class: Tweethook::Search
- Inherits:
-
Object
- Object
- Tweethook::Search
- Defined in:
- lib/tweethook/search.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#id ⇒ Object
Returns the value of attribute id.
-
#search ⇒ Object
Returns the value of attribute search.
-
#webhook ⇒ Object
Returns the value of attribute webhook.
Class Method Summary collapse
-
.create(search, args) ⇒ Object
create a new search at Tweethook Tweethook::Search.create(‘monkey’, :webhook => ‘where.com/callback’ ).
- .find(id) ⇒ Object
- .list ⇒ Object
Instance Method Summary collapse
- #change_active_to_boolean ⇒ Object
- #destroy ⇒ Object
-
#initialize(args) ⇒ Search
constructor
A new instance of Search.
- #modify ⇒ Object
- #new_record? ⇒ Boolean
- #save ⇒ Object
- #start ⇒ Object (also: #resume)
- #stop ⇒ Object (also: #pause)
Constructor Details
#initialize(args) ⇒ Search
Returns a new instance of Search.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tweethook/search.rb', line 25 def initialize(args) # change string keys to symbols if args.any? { |arg| arg.is_a?(String) } args = args.inject({}) { |output,array| key,value = array; output[key.to_sym] = value;output } end # setup instance variable for every arg args.each { |key,value| instance_variable_set("@#{key}",value) } @format ||= 'json' change_active_to_boolean end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
23 24 25 |
# File 'lib/tweethook/search.rb', line 23 def active @active end |
#id ⇒ Object
Returns the value of attribute id.
23 24 25 |
# File 'lib/tweethook/search.rb', line 23 def id @id end |
#search ⇒ Object
Returns the value of attribute search.
23 24 25 |
# File 'lib/tweethook/search.rb', line 23 def search @search end |
#webhook ⇒ Object
Returns the value of attribute webhook.
23 24 25 |
# File 'lib/tweethook/search.rb', line 23 def webhook @webhook end |
Class Method Details
.create(search, args) ⇒ Object
create a new search at Tweethook Tweethook::Search.create(‘monkey’, :webhook => ‘where.com/callback’ )
5 6 7 8 9 |
# File 'lib/tweethook/search.rb', line 5 def self.create(search,args) args.merge!({:search => search}) search = new(args) search.save end |
Instance Method Details
#change_active_to_boolean ⇒ Object
38 39 40 41 42 43 |
# File 'lib/tweethook/search.rb', line 38 def change_active_to_boolean # @active defaults to true @active = true if @active.nil? # change @active to boolean value if it's an integer @active = !@active.to_i.zero? if @active.is_a?(String) end |
#destroy ⇒ Object
78 79 80 81 82 |
# File 'lib/tweethook/search.rb', line 78 def destroy response = Tweethook.post('/destroy.json',:id => @id) return false if response.nil? self.id = nil if response.first['id'].eql?(@id) end |
#modify ⇒ Object
53 54 55 56 57 |
# File 'lib/tweethook/search.rb', line 53 def modify response = Tweethook.post('/modify.json', :id => @id, :search => @search, :webhook => @webhook, :active => @active) return nil if response.nil? self end |
#new_record? ⇒ Boolean
59 60 61 |
# File 'lib/tweethook/search.rb', line 59 def new_record? not @id.nil? end |
#save ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/tweethook/search.rb', line 45 def save return modify unless new_record? response = Tweethook.post('/create.json',:search => @search, :webhook => @webhook, :active => @active) return nil if response.nil? @id = response.first['id'] self end |