Class: Wes::Data::API::Model::Challenge

Inherits:
Base
  • Object
show all
Defined in:
lib/wes/data/api/model/challenge.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes

Instance Method Summary collapse

Methods inherited from Base

#exist?, #id, #initialize

Constructor Details

This class inherits a constructor from Wes::Data::API::Model::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Wes::Data::API::Model::Base

Instance Method Details

#add_answers(answers) ⇒ Object



19
20
21
# File 'lib/wes/data/api/model/challenge.rb', line 19

def add_answers(answers)
  client.post(answers_route, answers)
end

#answers(fetch: false) ⇒ Object



12
13
14
15
16
17
# File 'lib/wes/data/api/model/challenge.rb', line 12

def answers(fetch: false)
  records = fetch ? client.get(answers_route) : @attributes.answers
  map_objects(
    records, Wes::Data::API::Model::ChallengeAnswer
  )
end

#rewards(fetch: false) ⇒ Object



27
28
29
30
31
32
# File 'lib/wes/data/api/model/challenge.rb', line 27

def rewards(fetch: false)
  records = fetch ? fetch_rewards : @attributes.rewards
  map_objects(
    records, Wes::Data::API::Model::Reward
  )
end

#update(changes) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/wes/data/api/model/challenge.rb', line 42

def update(changes)
  route = [routes.challenge, id].join("/")
  @attributes = client.put(
    route, @attributes.to_h.merge(changes)
  ).first

  self
end

#update_answers(answers) ⇒ Object



23
24
25
# File 'lib/wes/data/api/model/challenge.rb', line 23

def update_answers(answers)
  client.put(answers_route, answers)
end

#update_status(s) ⇒ Object



51
52
53
# File 'lib/wes/data/api/model/challenge.rb', line 51

def update_status(s)
  update(:status => s)
end

#users(state: nil, fetch: false) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/wes/data/api/model/challenge.rb', line 34

def users(state: nil, fetch: false)
  records = fetch || !state.nil? ? fetch_users(state)
                                 : @attributes.users
  map_objects(
    records, Wes::Data::API::Model::CreatorUser
  )
end

#videos(state: nil, fetch: false) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/wes/data/api/model/challenge.rb', line 55

def videos(state: nil, fetch: false)
  records = fetch || !state.nil? ? fetch_videos(state)
                                 : @attributes.videos
  map_objects(
    records, Wes::Data::API::Model::Video
  )
end