Class: BrownPaperTickets::Event
- Inherits:
-
Object
- Object
- BrownPaperTickets::Event
- Includes:
- HTTParty
- Defined in:
- lib/brownpapertickets/event.rb
Constant Summary collapse
- REQUIRED_ATTR =
["e_name","e_city","e_state", "e_short_description", "e_description"]
- ATTRS =
["e_name","e_city","e_state", "e_short_description", "e_description","e_address1","e_address2","e_zip","e_phone","e_web","end_of_event_message", "end_of_sale_message","date_notes","e_notes","keywords","c_name","c_email","c_phone","c_fax","c_address1","c_address2","c_city","c_state","c_zip", "c_country","public", "title","link", "description", "event_id", "tickets_sold"]
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#server_response ⇒ Object
readonly
Returns the value of attribute server_response.
Instance Method Summary collapse
-
#all ⇒ Object
Returns all the account’s events from brownpapersticker.
- #create(params = {}) ⇒ Object
- #e_name=(param) ⇒ Object
-
#find(event_id) ⇒ Object
This method get an event from brownpapersticker.
-
#initialize(id, account, attributes = {}) ⇒ Event
constructor
A new instance of Event.
- #live ⇒ Object
- #live=(param) ⇒ Object
- #method_missing(m, *args, &block) ⇒ Object
- #new(params = {}) ⇒ Object
- #new_save(param) ⇒ Object
- #process_create_response(response, event_id) ⇒ Object
- #process_update_response(response) ⇒ Object
- #public ⇒ Object
- #public=(param) ⇒ Object
-
#save! ⇒ Object
300037 - Unknown error while posting info to DB 000000 - Success.
- #title=(param) ⇒ Object
-
#update_attribute(key, value) ⇒ Object
resultcode 300049 - Required variables are missing 300050 - Unknown error 300051 - Unable to find event 300052 - Event does not belong to account 300053 - Required variables are missing 300054 - Unable to update event 000000 - Success.
- #update_attributes(params) ⇒ Object
- #validates_required_attr ⇒ Object
Constructor Details
#initialize(id, account, attributes = {}) ⇒ Event
Returns a new instance of Event.
16 17 18 19 20 |
# File 'lib/brownpapertickets/event.rb', line 16 def initialize(id, account, attributes={}) @@id = id @@account = account @attributes = attributes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/brownpapertickets/event.rb', line 46 def method_missing(m, *args, &block) if ATTRS.include?(m.to_s.gsub("=","")) if m.to_s.include?("=") self.attributes[m.to_s.gsub("=","")] = *args.to_s else result = self.attributes[m.to_s] end else raise NoMethodError.new("Method missing #{m}") end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/brownpapertickets/event.rb', line 8 def attributes @attributes end |
#server_response ⇒ Object (readonly)
Returns the value of attribute server_response.
8 9 10 |
# File 'lib/brownpapertickets/event.rb', line 8 def server_response @server_response end |
Instance Method Details
#all ⇒ Object
Returns all the account’s events from brownpapersticker
26 27 28 29 30 31 32 33 34 |
# File 'lib/brownpapertickets/event.rb', line 26 def all events = Event.get("/eventlist", :query =>{"id" => @@id , "account" => @@account }) event_sales = Event.get("/eventsales", :query =>{"id" => @@id , "account" => @@account }) parsed_event = [] events.parsed_response["document"]["event"].each do |event| parsed_event << Event.new(@id,@account, event) end return parsed_event end |
#create(params = {}) ⇒ Object
113 114 115 116 |
# File 'lib/brownpapertickets/event.rb', line 113 def create(params={}) event = Event.new(@@id,@@account, params) event.save! end |
#e_name=(param) ⇒ Object
108 109 110 111 |
# File 'lib/brownpapertickets/event.rb', line 108 def e_name=(param) self.attributes["e_name"] = param self.attributes["title"] = param end |
#find(event_id) ⇒ Object
This method get an event from brownpapersticker. The event should belong to the account.
39 40 41 42 43 44 |
# File 'lib/brownpapertickets/event.rb', line 39 def find(event_id) event = Event.get("/eventlist",:query =>{"id" => @@id , "account" => @@account, "event_id" => event_id }) event_sales=Event.get("/eventsales",:query =>{"id" => @@id , "account" => @@account, "event_id" => event_id }) @attributes = event.parsed_response["document"]["event"] return self end |
#live ⇒ Object
118 119 120 121 |
# File 'lib/brownpapertickets/event.rb', line 118 def live return true if self.attributes["live"] == "y" return false end |
#live=(param) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/brownpapertickets/event.rb', line 123 def live=(param) if param self.attributes["live"] = "y" else self.attributes["live"] = "f" end end |
#new(params = {}) ⇒ Object
22 23 24 |
# File 'lib/brownpapertickets/event.rb', line 22 def new(params={}) Event.new(@@id,@@account, params) end |
#new_save(param) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/brownpapertickets/event.rb', line 87 def new_save(param) body = {"id" => @@id, "account" => @@account} p @@account query = self.attributes.merge("id" => @@id, "account" => @@account) response = BrownPaperTickets::Httpost.new(Net::HTTP::Post, "https://www.brownpapertickets.com/api2/#{param}",:query => query) response.[:body] = query st = response.perform xml = Hpricot(st.response.body) if param == "createevent" self.event_id = (xml/:event_id).inner_html if (xml/:resultcode).inner_html == "000000" process_create_response( (xml/:resultcode).inner_html, event_id) else process_update_response( (xml/:resultcode).inner_html) end end |
#process_create_response(response, event_id) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/brownpapertickets/event.rb', line 206 def process_create_response(response, event_id) case response when "000000" then self.event_id = event_id @server_response = "success" return true when "300036" then @server_response = "There are some missing attr" return false when "300037" then @server_response = "Unknown error while posting info to DB" return false else @server_response = "Unknown error" return false end end |
#process_update_response(response) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/brownpapertickets/event.rb', line 177 def process_update_response(response) case response when "000000" then @server_response = "success" return true when "300049" then @server_response = "Required variables are missing" return false when "300050" then @server_response = "Unknown error" return false when "300051" then @server_response = "Unable to find event" return false when "300052" then @server_response = "Event does not belong to account" return false when "300053" then @server_response = "Required variables are missing" return false when "300054" then @server_response = "Unable to update event" return false else @server_response = "Unknown error" return false end end |
#public ⇒ Object
131 132 133 134 |
# File 'lib/brownpapertickets/event.rb', line 131 def public return true if self.attributes["public"] == "t" return false end |
#public=(param) ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/brownpapertickets/event.rb', line 136 def public=(param) if param self.attributes["public"] = "t" else self.attributes["public"] = "n" end end |
#save! ⇒ Object
300037 - Unknown error while posting info to DB
000000 - Success
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/brownpapertickets/event.rb', line 76 def save! if self.event_id.blank? #changeevent return false unless validates_required_attr new_save("createevent") else #createevent new_save("changeevent") end end |
#title=(param) ⇒ Object
103 104 105 106 |
# File 'lib/brownpapertickets/event.rb', line 103 def title=(param) self.attributes["e_name"] = param self.attributes["title"] = param end |
#update_attribute(key, value) ⇒ Object
resultcode
300049 - Required variables are missing
300050 - Unknown error
300051 - Unable to find event
300052 - Event does not belong to account
300053 - Required variables are missing
300054 - Unable to update event
000000 - Success
153 154 155 156 157 158 159 160 161 162 |
# File 'lib/brownpapertickets/event.rb', line 153 def update_attribute(key, value) assign = key.to_s + "=" self.send(assign,value) query = {"id" => @@id, "account" => @@account, key.to_s => value, "event_id" => self.event_id} response = BrownPaperTickets::Httpost.new(Net::HTTP::Post, "https://www.brownpapertickets.com/api2/changeevent",:query => query) response.[:body] = query st = response.perform xml = Hpricot(st.response.body) return process_update_response((xml/:resultcode).inner_html) end |
#update_attributes(params) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/brownpapertickets/event.rb', line 164 def update_attributes(params) params.each do |key, value| assign = key.to_s + "=" self.send(assign,value) end query = {"id" => @@id, "account" => @@account, "event_id" => self.event_id}.merge(params) response = BrownPaperTickets::Httpost.new(Net::HTTP::Post, "https://www.brownpapertickets.com/api2/changeevent",:query => query) response.[:body] = query st = response.perform xml = Hpricot(st.response.body) return process_update_response((xml/:resultcode).inner_html) end |
#validates_required_attr ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/brownpapertickets/event.rb', line 58 def validates_required_attr missing_field = [] REQUIRED_ATTR.each do |attr| missing_field << attr if self.send(attr,nil,nil).blank? end unless missing_field.blank? @server_response = "The following attributes are missing:" missing_field.each{|att| @server_response = @server_response + " " + att } return false end return true end |