Class: PollEverywhere::Models::Participant

Inherits:
Object
  • Object
show all
Includes:
Serializable
Defined in:
lib/polleverywhere/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

included

Constructor Details

#initialize(http = PollEverywhere.http) ⇒ Participant

Returns a new instance of Participant.


42
43
44
# File 'lib/polleverywhere/models.rb', line 42

def initialize(http=PollEverywhere.http)
  self.http = http
end

Instance Attribute Details

#httpObject

Returns the value of attribute http


40
41
42
# File 'lib/polleverywhere/models.rb', line 40

def http
  @http
end

Class Method Details

.get(email) ⇒ Object


53
54
55
# File 'lib/polleverywhere/models.rb', line 53

def self.get(email)
  from_hash(:email => email).fetch
end

Instance Method Details

#destroyObject


57
58
59
60
# File 'lib/polleverywhere/models.rb', line 57

def destroy
  http.delete.from(path).response do |response|
  end
end

#fetchObject


66
67
68
69
70
# File 'lib/polleverywhere/models.rb', line 66

def fetch
  http.get.from(path).as(:json).response do |response|
    from_json response.body
  end
end

#pathObject


62
63
64
# File 'lib/polleverywhere/models.rb', line 62

def path
  "/participants/#{prop(:email).was || prop(:email).is}"
end

#saveObject


46
47
48
49
50
51
# File 'lib/polleverywhere/models.rb', line 46

def save
  http.put(to_json).as(:json).to(path).response do |response|
    value_set.commit
    from_json response.body
  end
end