Class: Chillout::Registration
- Inherits:
-
Object
- Object
- Chillout::Registration
- Defined in:
- lib/chillout/registration.rb
Defined Under Namespace
Classes: NotRegisteredByAccident, NotRegisteredByCommunicationError, NotRegisteredByInvalidData, NotRegisteredByLimit
Instance Method Summary collapse
-
#initialize(http_client = PlainHttpClient.new) ⇒ Registration
constructor
A new instance of Registration.
- #register(name, emails) ⇒ Object
Constructor Details
#initialize(http_client = PlainHttpClient.new) ⇒ Registration
Returns a new instance of Registration.
10 11 12 |
# File 'lib/chillout/registration.rb', line 10 def initialize(http_client=PlainHttpClient.new) @http_client = http_client end |
Instance Method Details
#register(name, emails) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/chillout/registration.rb', line 14 def register(name, emails) data = { :name => name, :emails => emails } response_body = @http_client.post("/projects", data) response_body["api_key"].strip rescue PlainHttpClient::NotCreated => e if e.code == "403" raise NotRegisteredByLimit.new elsif e.code == "400" raise NotRegisteredByInvalidData.new else raise NotRegisteredByAccident.new end rescue PlainHttpClient::CommunicationError => e raise NotRegisteredByCommunicationError.new end |