eventbright 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.markdown +92 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/eventbright.rb +5 -0
- data/lib/eventbright/api_object.rb +180 -0
- data/lib/eventbright/api_object_class_methods.rb +117 -0
- data/lib/eventbright/api_object_collection.rb +60 -0
- data/lib/eventbright/api_object_relationships.rb +72 -0
- data/lib/eventbright/api_objects/attendee.rb +51 -0
- data/lib/eventbright/api_objects/discount.rb +62 -0
- data/lib/eventbright/api_objects/event.rb +79 -0
- data/lib/eventbright/api_objects/organizer.rb +26 -0
- data/lib/eventbright/api_objects/ticket.rb +63 -0
- data/lib/eventbright/api_objects/user.rb +45 -0
- data/lib/eventbright/api_objects/venue.rb +18 -0
- data/lib/eventbright/error.rb +14 -0
- data/lib/eventbright/main.rb +57 -0
- data/spec/eventbright/api_object_class_spec.rb +113 -0
- data/spec/eventbright/api_object_collection_spec.rb +67 -0
- data/spec/eventbright/api_object_relationship_spec.rb +23 -0
- data/spec/eventbright/api_object_spec.rb +15 -0
- data/spec/eventbright/user_spec.rb +141 -0
- data/spec/eventbright_api_faker.rb +18 -0
- data/spec/eventbright_spec.rb +36 -0
- data/spec/faked_responses/auth_required.json +1 -0
- data/spec/faked_responses/event_get.json +1 -0
- data/spec/faked_responses/user_get.json +1 -0
- data/spec/faked_responses/user_list_events.json +1 -0
- data/spec/faked_responses/user_list_organizers.json +1 -0
- data/spec/faked_responses/user_list_venues.json +1 -0
- data/spec/faked_responses/user_update.json +1 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +35 -0
- metadata +132 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
module EventBright
|
2
|
+
class ApiObjectCollection
|
3
|
+
|
4
|
+
def initialize(owner = false, hash_array = [], parent = false)
|
5
|
+
@owner = owner
|
6
|
+
hash_array = [] if hash_array.nil?
|
7
|
+
arr = hash_array.map{|v| v[self.class.singlet_name]}.reject{|v| v.empty? }
|
8
|
+
@array = arr.map{|v| self.class.collection_for.new(owner, v)}
|
9
|
+
@array = @array.reject{|v| v.__send__(self.class.collection_for.requires.first).nil? || v.__send__(self.class.collection_for.requires.first) == ""} unless self.class.collection_for.requires.empty?
|
10
|
+
end
|
11
|
+
|
12
|
+
def inspect
|
13
|
+
"#{@array.inspect}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"#{@array.inspect}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def save
|
21
|
+
@array.each do |a|
|
22
|
+
a.save if a.dirty?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def dirty?
|
27
|
+
is_dirty = false
|
28
|
+
@array.each do |a|
|
29
|
+
is_dirty = true if a.dirty?
|
30
|
+
end
|
31
|
+
is_dirty
|
32
|
+
end
|
33
|
+
|
34
|
+
def method_missing(meth, *args, &block)
|
35
|
+
@array.__send__(meth, *args, &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def self.collection_for(type = false)
|
40
|
+
@collection_for = type if type
|
41
|
+
@collection_for
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.singlet_name(name = false)
|
45
|
+
@singlet_name = name if name
|
46
|
+
@singlet_name || @collection_for.singlet_name
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.plural_name(name = false)
|
50
|
+
@plural_name = name if name
|
51
|
+
@plural_name || @collection_for.plural_name || "#{self.singlet_name}s"
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
def self.getter(name = false)
|
56
|
+
@getter = name if name
|
57
|
+
@getter || "user_list_#{self.plural_name}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module EventBright
|
2
|
+
module ApiObjectRelationships
|
3
|
+
def relation_get(key); @relations[key]; end
|
4
|
+
def collection_get(key);
|
5
|
+
return @collections[key] unless @collections[key].nil? || collection_dirty?(key)
|
6
|
+
klass = self.class.collections[key]
|
7
|
+
begin
|
8
|
+
response = EventBright.call(klass.getter, nested_hash)
|
9
|
+
response = unnest_child_response(response)
|
10
|
+
c = klass.new(owner, response[klass.plural_name], self)
|
11
|
+
rescue EventBright::Error => e
|
12
|
+
if e.type == "Not Found" || e.type == "Discount error"
|
13
|
+
c = klass.new(owner, nil, self)
|
14
|
+
else
|
15
|
+
raise e
|
16
|
+
end
|
17
|
+
end
|
18
|
+
collection_clean!(key)
|
19
|
+
collection_set(key, c, self)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def collection_clean!(key); @dirty_collections[key] = false; end
|
24
|
+
def collection_dirty!(key); @dirty_collections[key] = true; end
|
25
|
+
def collection_dirty?(key); @dirty_collections[key] ? true : false; end
|
26
|
+
|
27
|
+
def relation_clean!(key); @dirty_relations[key] = false; end
|
28
|
+
def relation_dirty!(key); @dirty_relations[key] = true; end
|
29
|
+
def relation_dirty?(key); @dirty_relations[key] ? true : false; end
|
30
|
+
|
31
|
+
|
32
|
+
def relation_set(key, val, no_dirty = false)
|
33
|
+
@dirty_relations[key] = true
|
34
|
+
@relations[key] = val
|
35
|
+
end
|
36
|
+
|
37
|
+
def collection_set(key, val, no_dirty = false)
|
38
|
+
@collections[key] = val
|
39
|
+
end
|
40
|
+
|
41
|
+
def unnest_child_response(response)
|
42
|
+
response["#{self.class.singlet_name}"]
|
43
|
+
end
|
44
|
+
|
45
|
+
def load_relations_with_hash(hash, no_dirty = false)
|
46
|
+
self.class.relations.each do |rel, klass|
|
47
|
+
relation_set(rel, klass.new(owner, hash.delete(klass.singlet_name)), no_dirty) if hash[klass.singlet_name]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def load_collections_with_hash(hash, no_dirty = false)
|
52
|
+
self.class.relations.each do |rel, klass|
|
53
|
+
collection_set(rel, klass.new(owner, hash.delete(klass.plural_name)), false, self) if hash[klass.singlet_name]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def relations_save(opts)
|
58
|
+
self.class.relations.each do |rel, klass|
|
59
|
+
relation_get(rel).save if relation_get(rel) && relation_get(rel).dirty?
|
60
|
+
opts["#{rel.to_s}_id"] = relation_get(rel).id if relation_dirty?(rel)
|
61
|
+
opts.delete(rel)
|
62
|
+
end
|
63
|
+
opts
|
64
|
+
end
|
65
|
+
|
66
|
+
def collections_save
|
67
|
+
self.class.collections.each do |col, klass|
|
68
|
+
collection_get(col).save if collection_get(col)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'eventbright/api_objects/ticket'
|
2
|
+
module EventBright
|
3
|
+
|
4
|
+
class Attendee < ApiObject
|
5
|
+
|
6
|
+
readable :quantity, :currency, :amount_paid
|
7
|
+
readable :barcode, :order_id, :order_type
|
8
|
+
readable_date :created, :modified, :event_date
|
9
|
+
readable :discount, :notes
|
10
|
+
readable :email
|
11
|
+
readable :prefix, :first_name, :last_name, :suffix
|
12
|
+
readable :home_address, :home_address_2, :home_city, :home_postal_code
|
13
|
+
readable :home_country_code, :home_country, :home_region, :home_phone
|
14
|
+
readable :ship_address, :ship_address_2, :ship_city, :ship_postal_code
|
15
|
+
readable :ship_country_code, :ship_country, :ship_region
|
16
|
+
readable :work_address, :work_address_2, :work_city, :work_postal_code
|
17
|
+
readable :work_country_code, :work_country, :work_region, :work_phone
|
18
|
+
readable :job_title, :company, :website, :blog, :gender
|
19
|
+
readable :age, :birth_date
|
20
|
+
readable :affiliate # Doc error - affiliate?
|
21
|
+
ignores :answers
|
22
|
+
|
23
|
+
readable :ticket_id
|
24
|
+
attr_accessor :event
|
25
|
+
|
26
|
+
|
27
|
+
# Attendees can't live outside events, so we override standard owner to be event.
|
28
|
+
def initialize(event = nil, hash = {})
|
29
|
+
preinit
|
30
|
+
raise ArgumentError unless event.is_a? EventBright::Event
|
31
|
+
@id = hash.delete(:id)
|
32
|
+
@event = event
|
33
|
+
@owner = event.owner
|
34
|
+
init_with_hash(hash, true)
|
35
|
+
end
|
36
|
+
|
37
|
+
def save(*args)
|
38
|
+
# noop. Attendees can't be altered via api
|
39
|
+
end
|
40
|
+
end
|
41
|
+
class AttendeeCollection < ApiObjectCollection
|
42
|
+
collection_for Attendee
|
43
|
+
getter :event_list_attendees
|
44
|
+
def initialize(owner = false, hash_array = [], event = false)
|
45
|
+
super(event, hash_array)
|
46
|
+
end
|
47
|
+
def save(*args)
|
48
|
+
# noop. Attendees can't be altered via api
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module EventBright
|
2
|
+
|
3
|
+
class Discount < ApiObject
|
4
|
+
|
5
|
+
updatable :code
|
6
|
+
updatable :amount_off, :percent_off
|
7
|
+
updatable :tickets
|
8
|
+
updatable :quantity_available
|
9
|
+
updatable_date :start_date, :end_date
|
10
|
+
readable :quantity_sold
|
11
|
+
|
12
|
+
requires :code
|
13
|
+
|
14
|
+
# Tickets can't live outside events, so we override standard owner to be event.
|
15
|
+
def initialize(event = nil, hash = {})
|
16
|
+
preinit
|
17
|
+
raise ArgumentError unless event.is_a? EventBright::Event
|
18
|
+
@id = hash.delete(:id)
|
19
|
+
@event = event
|
20
|
+
@owner = event.owner
|
21
|
+
init_with_hash(hash, true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def discount_id=(val, no_dirty = false)
|
25
|
+
id = val
|
26
|
+
end
|
27
|
+
|
28
|
+
def new_hash
|
29
|
+
{:event_id => @event.id}
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def after_new
|
34
|
+
@event.dirty_discounts!
|
35
|
+
end
|
36
|
+
|
37
|
+
def after_save
|
38
|
+
@event.dirty_discounts!
|
39
|
+
end
|
40
|
+
|
41
|
+
def after_attribute_set
|
42
|
+
@event.dirty_discounts! unless @event.nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
def amount_off=(val, no_dirty = false)
|
46
|
+
attribute_set(:amount_off, val, no_dirty)
|
47
|
+
attribute_set(:percent_off, "", no_dirty)
|
48
|
+
end
|
49
|
+
|
50
|
+
def percent_off=(val, no_dirty = false)
|
51
|
+
attribute_set(:percent_off, val, no_dirty)
|
52
|
+
attribute_set(:amount_off, "", no_dirty)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
class DiscountCollection < ApiObjectCollection
|
56
|
+
collection_for Discount
|
57
|
+
getter :event_list_discounts
|
58
|
+
def initialize(owner = false, hash_array = [], event = false)
|
59
|
+
super(event, hash_array)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'tzinfo'
|
2
|
+
require 'eventbright/api_objects/organizer'
|
3
|
+
require 'eventbright/api_objects/venue'
|
4
|
+
require 'eventbright/api_objects/ticket'
|
5
|
+
require 'eventbright/api_objects/organizer'
|
6
|
+
require 'eventbright/api_objects/discount'
|
7
|
+
module EventBright
|
8
|
+
class Event < EventBright::ApiObject
|
9
|
+
|
10
|
+
updatable :title, :description, :tags, :timezone
|
11
|
+
updatable_date :start_date, :end_date
|
12
|
+
updatable :capacity, :url
|
13
|
+
updatable :privacy, :password, :status
|
14
|
+
updatable :created, :modified, :logo, :logo_ssl
|
15
|
+
updatable :text_color, :link_color, :title_text_color, :background_color
|
16
|
+
updatable :box_background_color, :box_text_color, :box_border_color
|
17
|
+
updatable :box_header_background_color, :box_header_text_color
|
18
|
+
updatable :currency
|
19
|
+
updatable :venue_id, :organizer_id
|
20
|
+
readable :category
|
21
|
+
reformats :privacy, :timezone, :start_date, :end_date
|
22
|
+
|
23
|
+
requires :title
|
24
|
+
ignores :organizer, :venue, :tickets
|
25
|
+
renames :id => :event_id
|
26
|
+
attr_accessor :organizer, :venue
|
27
|
+
|
28
|
+
has :organizer => EventBright::Organizer
|
29
|
+
has :venue => EventBright::Venue
|
30
|
+
collection :tickets => EventBright::TicketCollection
|
31
|
+
collection :attendees => EventBright::AttendeeCollection
|
32
|
+
collection :discounts => EventBright::DiscountCollection
|
33
|
+
|
34
|
+
def privacy
|
35
|
+
case attribute_get(:privacy)
|
36
|
+
when "Private"
|
37
|
+
attribute_set(:privacy, 0)
|
38
|
+
when "Public"
|
39
|
+
attribute_set(:privacy, 1)
|
40
|
+
end
|
41
|
+
attribute_get(:privacy)
|
42
|
+
end
|
43
|
+
|
44
|
+
def currency
|
45
|
+
attribute_get(:currency) || attribute_set(:currency, "USD")
|
46
|
+
end
|
47
|
+
|
48
|
+
def timezone
|
49
|
+
return attribute_get(:timezone) if attribute_get(:timezone) =~ /GMT[+-]\d{1,2}/
|
50
|
+
time = TZInfo::Timezone.get(attribute_get(:timezone)).current_period
|
51
|
+
seconds = time.utc_offset
|
52
|
+
offset = (seconds / (60*60))
|
53
|
+
attribute_set(:timezone, (offset < 0 ? "GMT#{offset}" : "GMT+#{offset}"))
|
54
|
+
attribute_get(:timezone)
|
55
|
+
end
|
56
|
+
|
57
|
+
def private?
|
58
|
+
privacy == 0 ? true : false
|
59
|
+
end
|
60
|
+
|
61
|
+
def public?
|
62
|
+
!private?
|
63
|
+
end
|
64
|
+
|
65
|
+
def unnest_child_response(response)
|
66
|
+
response.has_key?('event') ? response['event'] : response
|
67
|
+
end
|
68
|
+
|
69
|
+
def after_new
|
70
|
+
@owner.dirty_events!
|
71
|
+
end
|
72
|
+
|
73
|
+
def nested_hash
|
74
|
+
{:id => id, :count => 99999, :user => owner} # It's over 9000!
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
class EventCollection < ApiObjectCollection; collection_for Event; end
|
79
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module EventBright
|
2
|
+
class Event < EventBright::ApiObject; end
|
3
|
+
class OrganizerEventCollection < ApiObjectCollection
|
4
|
+
collection_for Event
|
5
|
+
getter :organizer_list_events
|
6
|
+
end
|
7
|
+
|
8
|
+
class Organizer < EventBright::ApiObject
|
9
|
+
|
10
|
+
updatable :name, :description
|
11
|
+
readable :url
|
12
|
+
|
13
|
+
requires :name
|
14
|
+
collection :events => EventBright::OrganizerEventCollection
|
15
|
+
def after_new
|
16
|
+
@owner.dirty_organizers!
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def unnest_child_response(response)
|
21
|
+
response
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class OrganizerCollection < ApiObjectCollection; collection_for Organizer; end
|
26
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module EventBright
|
2
|
+
|
3
|
+
class Ticket < ApiObject
|
4
|
+
|
5
|
+
updatable :is_donation
|
6
|
+
updatable :name, :description
|
7
|
+
updatable :price, :quantity
|
8
|
+
updatable :include_fee
|
9
|
+
updatable :min, :max
|
10
|
+
updatable :hide
|
11
|
+
updatable_date :start_sales, :end_sales
|
12
|
+
readable :quantity_sold, :currency
|
13
|
+
attr_accessor :event
|
14
|
+
|
15
|
+
# Remapping some API inconsistencies
|
16
|
+
remap :type => :is_donation, :visible => :hide, :quantity_available => :quantity
|
17
|
+
remap :end_date => :end_sales, :start_date => :start_sales
|
18
|
+
|
19
|
+
requires :name, :price, :quantity
|
20
|
+
reformats :hide
|
21
|
+
|
22
|
+
# Tickets can't live outside events, so we override standard owner to be event.
|
23
|
+
def initialize(event = nil, hash = {})
|
24
|
+
preinit
|
25
|
+
raise ArgumentError unless event.is_a? EventBright::Event
|
26
|
+
@id = hash.delete(:id)
|
27
|
+
@event = event
|
28
|
+
@owner = event.owner
|
29
|
+
init_with_hash(hash, true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def visible=(val,*args)
|
33
|
+
val == "1" || val == 1 ? attribute_set(:hide, 0, true) : attribute_set(:hide, 1, true)
|
34
|
+
end
|
35
|
+
|
36
|
+
def hide
|
37
|
+
(["1", 1, "y", "Y"].include? attribute_get(:hide)) ? "y" : "n"
|
38
|
+
end
|
39
|
+
|
40
|
+
def new_hash
|
41
|
+
{:event_id => @event.id}
|
42
|
+
end
|
43
|
+
|
44
|
+
def after_new
|
45
|
+
@event.dirty_tickets!
|
46
|
+
end
|
47
|
+
|
48
|
+
def after_save
|
49
|
+
@event.dirty_tickets!
|
50
|
+
end
|
51
|
+
|
52
|
+
def after_attribute_set
|
53
|
+
@event.dirty_tickets! unless @event.nil?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
class TicketCollection < ApiObjectCollection
|
57
|
+
collection_for Ticket
|
58
|
+
getter :event_get
|
59
|
+
def initialize(owner = false, hash_array = [], event = false)
|
60
|
+
super(event, hash_array)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module EventBright
|
2
|
+
class User < EventBright::ApiObject
|
3
|
+
|
4
|
+
updatable :email, :password
|
5
|
+
readable :user_key
|
6
|
+
readable :first_name, :last_name
|
7
|
+
readable_date :date_created, :date_modified
|
8
|
+
remap :user_id => :id
|
9
|
+
ignores ['subusers']
|
10
|
+
|
11
|
+
collection :events => EventBright::EventCollection
|
12
|
+
collection :organizers => EventBright::OrganizerCollection
|
13
|
+
collection :venues => EventBright::VenueCollection
|
14
|
+
|
15
|
+
def initialize(user, no_load = false)
|
16
|
+
preinit
|
17
|
+
case user
|
18
|
+
when Array
|
19
|
+
email, password = user
|
20
|
+
attribute_set(:email, email, true)
|
21
|
+
attribute_set(:password, password, true)
|
22
|
+
else
|
23
|
+
attribute_set(:user_key, user, true)
|
24
|
+
end
|
25
|
+
load! unless no_load
|
26
|
+
end
|
27
|
+
|
28
|
+
def prep_api_hash(method = 'get', hash = {})
|
29
|
+
{:user => self}
|
30
|
+
end
|
31
|
+
|
32
|
+
def unnest_child_response(response)
|
33
|
+
response
|
34
|
+
end
|
35
|
+
|
36
|
+
def owner
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def auth
|
41
|
+
attribute_get(:user_key) ? {'user_key' => attribute_get(:user_key)} : {'user' => attribute_get(:email), 'password' => attribute_get(:password)}
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|