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

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Challenge

Returns a new instance of Challenge.



10
11
12
# File 'lib/wes/data/api/challenge.rb', line 10

def initialize(attributes)
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym) ⇒ Object



64
65
66
# File 'lib/wes/data/api/challenge.rb', line 64

def method_missing(method_sym)
  attributes.to_h.fetch(method_sym, nil)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



8
9
10
# File 'lib/wes/data/api/challenge.rb', line 8

def attributes
  @attributes
end

Class Method Details

.allObject



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

def all
  client.get routes.challenges
end

.clientObject



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

def client
  Client.new
end

.closedObject



32
33
34
# File 'lib/wes/data/api/challenge.rb', line 32

def closed
  client.get "#{routes.challenges}/closed"
end

.configurationObject



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

def configuration
  Configuration
end

.draftsObject



36
37
38
# File 'lib/wes/data/api/challenge.rb', line 36

def drafts
  client.get "#{routes.challenges}/drafts"
end

.find(id) ⇒ Object



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

def find(id)
  attributes = client.get("#{routes.challenge}/#{id}").first
  new(attributes)
end

.openObject



40
41
42
# File 'lib/wes/data/api/challenge.rb', line 40

def open
  client.get "#{routes.challenges}/open"
end

.routesObject



44
45
46
# File 'lib/wes/data/api/challenge.rb', line 44

def routes
  configuration.routes
end

Instance Method Details

#purchased_videosObject



54
55
56
57
# File 'lib/wes/data/api/challenge.rb', line 54

def purchased_videos
  id_set?
  client.get "#{routes.challenge}/#{id}#{routes.videos}/purchased"
end

#rewardsObject



59
60
61
62
# File 'lib/wes/data/api/challenge.rb', line 59

def rewards
  id_set?
  client.get "#{routes.challenge}/#{id}/rewards"
end

#videosObject



49
50
51
52
# File 'lib/wes/data/api/challenge.rb', line 49

def videos
  id_set?
  client.get "#{routes.challenge}/#{id}#{routes.videos}"
end