challonge-api 0.1.1 → 0.2.0
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.
- data/lib/challonge/api.rb +3 -1
- data/lib/challonge/match.rb +21 -0
- data/lib/challonge/participant.rb +6 -1
- data/lib/challonge/tournament.rb.orig +45 -0
- metadata +33 -55
data/lib/challonge/api.rb
CHANGED
@@ -2,6 +2,8 @@ class Challonge
|
|
2
2
|
class API < ::ActiveResource::Base
|
3
3
|
self.user = 'your_challonge_username'
|
4
4
|
self.password = 'your_challonge_api_key'
|
5
|
+
self.format = :json
|
6
|
+
self.include_root_in_json = true
|
5
7
|
|
6
8
|
@readonly_attributes = []
|
7
9
|
|
@@ -32,7 +34,7 @@ class Challonge
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def encode
|
35
|
-
self.class.
|
37
|
+
{self.class.element_name => writable_attribute_hash}.to_json
|
36
38
|
end
|
37
39
|
|
38
40
|
def readonly_attributes
|
data/lib/challonge/match.rb
CHANGED
@@ -10,6 +10,18 @@ class Challonge::Match < Challonge::API
|
|
10
10
|
def tournament=(tournament)
|
11
11
|
self.prefix_options[:tournament_id] = tournament.id
|
12
12
|
end
|
13
|
+
|
14
|
+
def player1
|
15
|
+
_find_player(:player1_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def player2
|
19
|
+
_find_player(:player2_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def player_winner? (participant)
|
23
|
+
(participant.id != self.winner_id)
|
24
|
+
end
|
13
25
|
|
14
26
|
# not implemented by API
|
15
27
|
def create; end
|
@@ -22,4 +34,13 @@ class Challonge::Match < Challonge::API
|
|
22
34
|
def readonly_attributes
|
23
35
|
%w/prerequisite_match_ids_csv/
|
24
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def _find_player(player)
|
40
|
+
if self.attributes[player] != nil
|
41
|
+
Challonge::Participant.find(self.attributes[player], :params => {:tournament_id => self.prefix_options[:tournament_id]})
|
42
|
+
else
|
43
|
+
Challonge::Participant.new({:name => 'TBD'})
|
44
|
+
end
|
45
|
+
end
|
25
46
|
end
|
@@ -3,9 +3,10 @@
|
|
3
3
|
class Challonge::Participant < Challonge::API
|
4
4
|
self.site = "https://challonge.com/api/tournaments/:tournament_id"
|
5
5
|
|
6
|
-
def initialize(attributes = {})
|
6
|
+
def initialize(attributes = {}, persisted = false)
|
7
7
|
@attributes = {}
|
8
8
|
@prefix_options = {}
|
9
|
+
@persisted = persisted
|
9
10
|
|
10
11
|
# allow new and create to be passed a tournament or tournament_id
|
11
12
|
real_attributes = attributes.slice!(:tournament, :tournament_id, "tournament", "tournament_id")
|
@@ -26,6 +27,10 @@ class Challonge::Participant < Challonge::API
|
|
26
27
|
def randomize!
|
27
28
|
validated_post(:randomize)
|
28
29
|
end
|
30
|
+
|
31
|
+
def name
|
32
|
+
super ? super : @attributes["challonge_username"]
|
33
|
+
end
|
29
34
|
|
30
35
|
protected
|
31
36
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Challonge::Tournament < Challonge::API
|
2
|
+
self.site = "http://challonge.dev/api"
|
3
|
+
|
4
|
+
def description
|
5
|
+
if self.attributes.include?('description_source')
|
6
|
+
self.description_source
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def description=(val)
|
11
|
+
self.description_source = val
|
12
|
+
end
|
13
|
+
|
14
|
+
def publish!
|
15
|
+
validated_post(:publish)
|
16
|
+
end
|
17
|
+
|
18
|
+
def start!
|
19
|
+
validated_post(:start)
|
20
|
+
end
|
21
|
+
|
22
|
+
def reset!
|
23
|
+
validated_post(:reset)
|
24
|
+
end
|
25
|
+
|
26
|
+
def participants(scope = :all)
|
27
|
+
Challonge::Participant.find(scope, :params => {:tournament_id => self.id})
|
28
|
+
end
|
29
|
+
|
30
|
+
def matches(scope = :all)
|
31
|
+
Challonge::Match.find(scope, :params => {:tournament_id => self.id})
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def readonly_attributes
|
37
|
+
%w/description_source subdomain full_challonge_url live_image_url sign_up_url/
|
38
|
+
end
|
39
|
+
|
40
|
+
def writable_attribute_hash
|
41
|
+
attr_h = super
|
42
|
+
attr_h['description'] = description
|
43
|
+
attr_h
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,84 +1,62 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: challonge-api
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 0.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- CHALLONGE!
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-11-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: activeresource
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &13785960 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *13785960
|
35
25
|
description:
|
36
26
|
email: bitbucket@challonge.com
|
37
27
|
executables: []
|
38
|
-
|
39
28
|
extensions: []
|
40
|
-
|
41
29
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
|
30
|
+
files:
|
31
|
+
- lib/challonge-api.rb
|
44
32
|
- lib/challonge/participant.rb
|
45
|
-
- lib/challonge/api.rb
|
46
33
|
- lib/challonge/match.rb
|
47
34
|
- lib/challonge/tournament.rb
|
48
|
-
- lib/challonge
|
49
|
-
|
35
|
+
- lib/challonge/api.rb
|
36
|
+
- lib/challonge/tournament.rb.orig
|
50
37
|
homepage: http://bitbucket.org/corneldm/challonge-api
|
51
38
|
licenses: []
|
52
|
-
|
53
39
|
post_install_message:
|
54
40
|
rdoc_options: []
|
55
|
-
|
56
|
-
require_paths:
|
41
|
+
require_paths:
|
57
42
|
- lib
|
58
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
44
|
none: false
|
60
|
-
requirements:
|
61
|
-
- -
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
|
64
|
-
|
65
|
-
- 0
|
66
|
-
version: "0"
|
67
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
50
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
segments:
|
74
|
-
- 0
|
75
|
-
version: "0"
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
76
55
|
requirements: []
|
77
|
-
|
78
56
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.
|
57
|
+
rubygems_version: 1.8.11
|
80
58
|
signing_key:
|
81
59
|
specification_version: 3
|
82
|
-
summary: Preconfigured ActiveResource classes for integrating with CHALLONGE!'s API
|
60
|
+
summary: Preconfigured ActiveResource classes for integrating with CHALLONGE!'s API
|
61
|
+
- http://challonge.com/api
|
83
62
|
test_files: []
|
84
|
-
|