Class: BrownPaperTickets::Eventsales

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/brownpapertickets/eventsales.rb

Constant Summary collapse

REQUIRED_ATTR =
["event_id"]
ATTRS =
["event_id", "title", "link", "event_status", "tickets_sold", "collected_value", "paid_value", "date_id", "price_id"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, account, attributes = {}) ⇒ Eventsales

Returns a new instance of Eventsales.



13
14
15
16
17
# File 'lib/brownpapertickets/eventsales.rb', line 13

def initialize(id, , attributes={})
  @@id       = id
  @@account  = 
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/brownpapertickets/eventsales.rb', line 23

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

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/brownpapertickets/eventsales.rb', line 7

def attributes
  @attributes
end

#server_responseObject (readonly)

Returns the value of attribute server_response.



7
8
9
# File 'lib/brownpapertickets/eventsales.rb', line 7

def server_response
  @server_response
end

Instance Method Details

#create_reportObject



48
49
50
51
52
53
54
55
# File 'lib/brownpapertickets/eventsales.rb', line 48

def create_report
  body = {"id" => @@id, "account" => @@account, "event_id" => event_id}
  query = self.attributes.merge("id" => @@id, "account" => @@account)
  response = BrownPaperTickets::Httpost.new(Net::HTTP::Get, "https://www.brownpapertickets.com/api2/eventsales",:query => query)
  response.options[:body] = query
  st = response.perform
  xml = st.response.body
end

#new(params = {}) ⇒ Object



19
20
21
# File 'lib/brownpapertickets/eventsales.rb', line 19

def new(params={})
  Event.new(@@id,@@account, params, event_id)
end

#validates_required_attrObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/brownpapertickets/eventsales.rb', line 35

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