cloud_spokes_api_model 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,127 @@
|
|
1
|
+
class CloudSpokes::Model::Challenge < CloudSpokes::Model::BaseApi
|
2
|
+
|
3
|
+
attr_accessor :id, :challenge_id, :challenge_type, :attributes,
|
4
|
+
:prize_type, :total_prize_money, :top_prize,
|
5
|
+
:start_date, :end_date, :usage_details, :requirements, :post_reg_info,
|
6
|
+
:name, :description, :status, :release_to_open_source, :additional_info,
|
7
|
+
:categories, :is_open, :discussion_board, :registered_members,
|
8
|
+
:submission_details, :winner_announced, :community,
|
9
|
+
|
10
|
+
# these are only available if you call /admin on the model
|
11
|
+
# e.g. http://cs-api-sandbox.herokuapp.com/v1/challenges/2/admin
|
12
|
+
:challenge_reviewers, :challenge_comment_notifiers, :assets
|
13
|
+
|
14
|
+
has_many :comments
|
15
|
+
|
16
|
+
# Note that we're not using the participants data in the json because it
|
17
|
+
# lacks many attributes. We simply just do another api call.
|
18
|
+
has_many :participants
|
19
|
+
|
20
|
+
# Cleanup up the __r convention -- may want to delete this
|
21
|
+
def initialize(params={})
|
22
|
+
# there has GOT to be some better way to clean this up ...
|
23
|
+
params['categories'] = params.delete('challenge_categories__r') if params['challenge_categories__r']
|
24
|
+
params['participants'] = params.delete('challenge_participants__r') if params['challenge_participants__r']
|
25
|
+
params['community'] = params.delete('community__r') if params['community__r']
|
26
|
+
params['terms_of_service'] = params.delete('terms_of_service__r') if params['terms_of_service__r']
|
27
|
+
params['challenge_comments'] = params.delete('challenge_comments__r') if params['challenge_comments__r']
|
28
|
+
params['challenge_reviewers'] = params.delete('challenge_reviewers__r') if params['challenge_reviewers__r']
|
29
|
+
params['challenge_comment_notifiers'] = params.delete('challenge_comment_notifiers__r') if params['challenge_comment_notifiers__r']
|
30
|
+
params['challenge_prizes'] = params.delete('challenge_prizes__r') if params['challenge_prizes__r']
|
31
|
+
params['assets'] = params.delete('assets__r') if params['assets__r']
|
32
|
+
|
33
|
+
# these fields need extra cleaning as they should only output arrays of strings
|
34
|
+
# they also have an awful lot of duplication that can benefit with a bit of refactoring
|
35
|
+
params['challenge_reviewers'] = params['challenge_reviewers'].map do |entry|
|
36
|
+
entry['member__r']['name']
|
37
|
+
end if params['challenge_reviewers']
|
38
|
+
|
39
|
+
params['challenge_comment_notifiers'] = params['challenge_comment_notifiers'].map do |entry|
|
40
|
+
entry['member__r']['name']
|
41
|
+
end if params['challenge_comment_notifiers']
|
42
|
+
|
43
|
+
params['challenge_prizes'] = params['challenge_prizes'].records.map do |entry|
|
44
|
+
{ place: entry['place'].to_s, prize: entry['prize'].to_s, points: entry['points'] || '', value: entry['value'] || '' }
|
45
|
+
end if params['challenge_prizes']
|
46
|
+
|
47
|
+
# params['assets'] = params['assets'].map do |entry|
|
48
|
+
# entry['filename']
|
49
|
+
# end if params['assets']
|
50
|
+
|
51
|
+
super(params)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.api_endpoint
|
55
|
+
CloudSpokes::APP_CONFIG[:cs_api][:challenges]
|
56
|
+
end
|
57
|
+
|
58
|
+
# Used for resourceful routes (instead of id)
|
59
|
+
def to_param
|
60
|
+
challenge_id
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns all the closed challenges
|
64
|
+
def self.closed
|
65
|
+
request(:get, 'closed', {}).map {|challenge| Challenge.new challenge}
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.open
|
69
|
+
request(:get, '', {}).map {|challenge| Challenge.new challenge}
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.all
|
73
|
+
closed + open
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns all the recent challenges
|
77
|
+
def self.recent
|
78
|
+
request(:get, 'recent', {}).map {|challenge| Challenge.new challenge}
|
79
|
+
end
|
80
|
+
|
81
|
+
# Return an object instead of a string
|
82
|
+
def start_date
|
83
|
+
Date.parse(@start_date) if @start_date
|
84
|
+
end
|
85
|
+
|
86
|
+
# Return an object instead of a string
|
87
|
+
def end_date
|
88
|
+
Date.parse(@end_date) if @end_date
|
89
|
+
end
|
90
|
+
|
91
|
+
# TODO: blow up the categories into something useful
|
92
|
+
def categories
|
93
|
+
@categories.records.map {|c| c.display_name}
|
94
|
+
end
|
95
|
+
|
96
|
+
def category_names
|
97
|
+
categories.records.map(&:display_name)
|
98
|
+
end
|
99
|
+
|
100
|
+
def assets
|
101
|
+
assets.records.map(&:filename)
|
102
|
+
end
|
103
|
+
|
104
|
+
def community_name
|
105
|
+
community.try(:name)
|
106
|
+
end
|
107
|
+
|
108
|
+
def open?
|
109
|
+
@is_open == "true"
|
110
|
+
end
|
111
|
+
|
112
|
+
def release_to_open_source?
|
113
|
+
!!@release_to_open_source
|
114
|
+
end
|
115
|
+
|
116
|
+
def winner_announced
|
117
|
+
Date.parse(@winner_announced) if @winner_announced
|
118
|
+
end
|
119
|
+
|
120
|
+
# has_one :status
|
121
|
+
# TODO (this requires authentication)
|
122
|
+
# edit Nov 22: apparently not? O_O
|
123
|
+
# def status
|
124
|
+
# 'nil'
|
125
|
+
# end
|
126
|
+
end
|
127
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_spokes_api_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- app/models/active_model/model.rb
|
103
103
|
- app/models/cloud_spokes/model/base_api.rb
|
104
104
|
- app/models/cloud_spokes/model/category.rb
|
105
|
+
- app/models/cloud_spokes/model/challenge.rb
|
105
106
|
- app/models/cloud_spokes/model/member.rb
|
106
107
|
- lib/cloud_spokes_api_model/engine.rb
|
107
108
|
- lib/cloud_spokes_api_model/railtie.rb
|
@@ -155,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
156
|
version: '0'
|
156
157
|
segments:
|
157
158
|
- 0
|
158
|
-
hash:
|
159
|
+
hash: 81249341863946088
|
159
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
161
|
none: false
|
161
162
|
requirements:
|
@@ -164,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
165
|
version: '0'
|
165
166
|
segments:
|
166
167
|
- 0
|
167
|
-
hash:
|
168
|
+
hash: 81249341863946088
|
168
169
|
requirements: []
|
169
170
|
rubyforge_project:
|
170
171
|
rubygems_version: 1.8.24
|