challonge-api 0.1.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.
@@ -0,0 +1,5 @@
1
+ require 'active_resource'
2
+ require 'challonge/api'
3
+ require 'challonge/tournament'
4
+ require 'challonge/participant'
5
+ require 'challonge/match'
@@ -0,0 +1,50 @@
1
+ class Challonge
2
+ class API < ::ActiveResource::Base
3
+ self.user = 'your_challonge_username'
4
+ self.password = 'your_challonge_api_key'
5
+
6
+ @readonly_attributes = []
7
+
8
+ def self.username=(uname)
9
+ self.user = uname
10
+ end
11
+
12
+ def self.username
13
+ self.user
14
+ end
15
+
16
+ def self.key=(key)
17
+ self.password = key
18
+ end
19
+
20
+ def self.key
21
+ self.password
22
+ end
23
+
24
+ protected
25
+
26
+ def validated_post(action)
27
+ post(action)
28
+ true
29
+ rescue ::ActiveResource::ResourceInvalid => error
30
+ errors.from_xml(error.response.body)
31
+ false
32
+ end
33
+
34
+ def encode
35
+ self.class.format.encode(writable_attribute_hash, {:root => self.class.element_name})
36
+ end
37
+
38
+ def readonly_attributes
39
+ []
40
+ end
41
+
42
+ def writable_attribute_hash
43
+ attr_h = {}
44
+ (attributes.keys - readonly_attributes).each do |key|
45
+ attr_h[key] = attributes[key]
46
+ end
47
+ attr_h
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,23 @@
1
+ class Challonge::Match < Challonge::API
2
+ self.site = "https://challonge.com/api/tournaments/:tournament_id"
3
+
4
+ # the only attributes that will save are: scores_csv, winner_id
5
+
6
+ def tournament
7
+ Challonge::Tournament.find(self.prefix_options[:tournament_id])
8
+ end
9
+
10
+ def tournament=(tournament)
11
+ self.prefix_options[:tournament_id] = tournament.id
12
+ end
13
+
14
+ # methods unsupported by API
15
+ def create; end
16
+ def destroy; end
17
+
18
+ protected
19
+
20
+ def readonly_attributes
21
+ %w/prerequisite_match_ids_csv/
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ class Challonge::Participant < Challonge::API
2
+ self.site = "https://challonge.com/api/tournaments/:tournament_id"
3
+
4
+ # the only attributes that will save are: name, seed, challonge_username, email, misc
5
+
6
+ def tournament
7
+ Challonge::Tournament.find(self.prefix_options[:tournament_id])
8
+ end
9
+
10
+ def tournament=(tournament)
11
+ self.prefix_options[:tournament_id] = tournament.id
12
+ end
13
+
14
+ def randomize!
15
+ validated_post(:randomize)
16
+ end
17
+
18
+ protected
19
+
20
+ def readonly_attributes
21
+ %w/challonge_email_address_verified/
22
+ end
23
+ end
@@ -0,0 +1,46 @@
1
+ class Challonge::Tournament < Challonge::API
2
+ self.site = "https://challonge.com/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
+ # associations
27
+ def participants(scope = :all)
28
+ Challonge::Participant.find(scope, :params => {:tournament_id => self.id})
29
+ end
30
+
31
+ def matches(scope = :all)
32
+ Challonge::Match.find(scope, :params => {:tournament_id => self.id})
33
+ end
34
+
35
+ protected
36
+
37
+ def readonly_attributes
38
+ %w/description_source subdomain full_challonge_url live_image_url sign_up_url/
39
+ end
40
+
41
+ def writable_attribute_hash
42
+ attr_h = super
43
+ attr_h['description'] = description
44
+ attr_h
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: challonge-api
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - CHALLONGE!
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-14 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: bitbucket@challonge.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/challonge/participant.rb
32
+ - lib/challonge/api.rb
33
+ - lib/challonge/match.rb
34
+ - lib/challonge/tournament.rb
35
+ - lib/challonge-api.rb
36
+ has_rdoc: true
37
+ homepage: http://challonge.com
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 3
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Preconfigured ActiveResource classes for integrating with CHALLONGE!'s API - http://challonge.com/api
70
+ test_files: []
71
+