Class: Amiando::Event

Inherits:
Resource show all
Defined in:
lib/amiando/event.rb

Overview

Instance Attribute Summary

Attributes inherited from Resource

#attributes, #request, #response, #success

Class Method Summary (collapse)

Methods inherited from Resource

#==, #[], #extract_attributes_from, #id, #initialize, map, map_params, mapping, #method_missing, method_missing, #populate_create, reverse_map_params, typecasting

Methods included from Autorun

included

Constructor Details

This class inherits a constructor from Amiando::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Amiando::Resource

Class Method Details

+ (Result) activate(id)

Activate an event

Parameters:

  • the (Integer)

    event id

Returns:

  • (Result)

    if it was activated or not.



82
83
84
85
86
87
# File 'lib/amiando/event.rb', line 82

def self.activate(id)
  object = Result.new
  post object, "/api/event/#{id}/activate"

  object
end

+ (Event) create(attributes)

Creates an event.

Returns:

  • (Event)

    will not return the full event and only the id attribute will be available.



25
26
27
28
29
30
31
32
# File 'lib/amiando/event.rb', line 25

def self.create(attributes)
  object = new
  post object, '/api/event/create',
    :params          => map_params(attributes),
    :populate_method => :populate_create

  object
end

+ (Boolean) delete(id)

Deletes an event

Parameters:

  • event (Integer)

    id

Returns:

  • (Boolean)

    with the result of the operation



69
70
71
72
73
74
# File 'lib/amiando/event.rb', line 69

def self.delete(id)
  object = Boolean.new('deleted')
  do_request object, :delete, "/api/event/#{id}"

  object
end

+ (Boolean) exists?(identifier)

See if an event id exists

Returns:



56
57
58
59
60
61
# File 'lib/amiando/event.rb', line 56

def self.exists?(identifier)
  object = Boolean.new('exists')
  get object, "api/event/exists", :params => { :identifier => identifier }

  object
end

+ (Object) find(id)

Fetch an event



47
48
49
50
51
52
# File 'lib/amiando/event.rb', line 47

def self.find(id)
  object = new
  get object, "/api/event/#{id}"

  object
end

+ (Result) find_all_by_user_id(user_id)

With a list of the event ids by this user

Parameters:

  • user

    id

Returns:

  • (Result)

    with a list of the event ids by this user



110
111
112
113
114
115
116
# File 'lib/amiando/event.rb', line 110

def self.find_all_by_user_id(user_id)
  object = Result.new do |response_body|
    response_body['events']
  end
  get object, "/api/user/#{user_id}/events"
  object
end

+ (Result) search(by)

Search by identifier or title.

Parameters:

  • a (Hash)

    hash with 1 entry, either :identifier or :title

Returns:

  • (Result)

    with an array of ids



95
96
97
98
99
100
101
102
103
104
# File 'lib/amiando/event.rb', line 95

def self.search(by)
  unless by[:identifier].nil? ^ by[:title].nil? # XOR
    raise ArgumentError.new('Events can be searched either by identifier or by title, include only one.')
  end

  object = Result.new { |response_body| response_body['ids'] }
  get object, '/api/event/find', :params => by

  object
end

+ (Boolean) update(id, attributes)

Updates an event.

Returns:

  • (Boolean)

    if it was successful or not.



38
39
40
41
42
43
# File 'lib/amiando/event.rb', line 38

def self.update(id, attributes)
  object = Result.new
  post object, "/api/event/#{id}", :params => map_params(attributes)

  object
end