Class: Amiando::Event

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

Overview

Instance Attribute Summary

Attributes inherited from Resource

#request, #response, #success

Class Method Summary collapse

Methods inherited from Resource

#==, #extract_attributes_from, #initialize, method_missing, #populate_create

Methods included from Attributes

#[], #id, included, #method_missing, #respond_to?, #type

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::Attributes

Class Method Details

.activate(id) ⇒ Result

Activate an event

Parameters:

  • id (Integer)

    event id

Returns:

  • (Result)

    if it was activated or not.


86
87
88
89
90
91
# File 'lib/amiando/event.rb', line 86

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

  object
end

.create(attributes) ⇒ Event

Creates an event.

Parameters:

  • attributes (Hash)

Returns:

  • (Event)

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


18
19
20
21
22
23
24
25
# File 'lib/amiando/event.rb', line 18

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

  object
end

.delete(id) ⇒ Boolean

Deletes an event

Parameters:

  • id (Integer)

    event id

Returns:

  • (Boolean)

    with the result of the operation


73
74
75
76
77
78
# File 'lib/amiando/event.rb', line 73

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

  object
end

.exists?(identifier) ⇒ Boolean

See if an event id exists

Parameters:

  • identifier

Returns:

  • (Boolean)

    if it exists or not


60
61
62
63
64
65
# File 'lib/amiando/event.rb', line 60

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

  object
end

.find(id) ⇒ Event

Fetch an event

Parameters:

  • id

Returns:


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

.find_all_by_user_id(user_id) ⇒ Result

Find all events from a user

Parameters:

  • user_id

Returns:

  • (Result)

    with a list of the event ids by this user


117
118
119
120
121
122
123
# File 'lib/amiando/event.rb', line 117

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

.search(by) ⇒ Result

Search by identifier or title.

Parameters:

  • a (Hash)

    hash with 1 entry, either :identifier or :title

Returns:

  • (Result)

    with an array of ids

Raises:

  • (ArgumentError)

    if no identifier or title supplied, or if both present


100
101
102
103
104
105
106
107
108
109
# File 'lib/amiando/event.rb', line 100

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

.update(id, attributes) ⇒ Result

Updates an event.

Parameters:

  • id
  • attributes (Hash)

Returns:

  • (Result)

    if it was successful or not.


34
35
36
37
38
39
# File 'lib/amiando/event.rb', line 34

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

  object
end