Permalink
Browse files

move challonge init to remote model

I'm not sure it will stay there, but it makes better sense.
  • Loading branch information...
1 parent b6f521f commit aaf7249cefc0dce15f680d59a872b0133961fd4e @colindean committed Nov 1, 2011
Showing with 21 additions and 0 deletions.
  1. +18 −0 app/models/remote_tournament.rb
  2. +3 −0 lib/exceptions.rb
@@ -26,6 +26,10 @@ def resolve_class
end
def get
+ #I'm not sure I want this here...
+ if remote_type == 'Challonge::Tournament'
+ challonge_init
+ end
resolve_class.find(remote_id)
end
@@ -34,4 +38,18 @@ def set(remote_instance)
self.remote_id = remote_instance.id
get
end
+
+ private
+
+ def challonge_init
+ u = Pcfg.get('challonge.api.username')
+ k = Pcfg.get('challonge.api.key')
+
+ msg = _("The Challonge API credentials are not set.")
+ raise PLAS::Exceptions::RemoteTournamentError, msg if !(u and k)
+
+ Challonge::API.username = u
+ Challonge::API.key = k
+
+ end
end
View
@@ -0,0 +1,3 @@
+module PLAS::Exceptions
+ class RemoteTournamentError < StandardError; end
+end

0 comments on commit aaf7249

Please sign in to comment.