Class: Forward::API::User

Inherits:
Resource show all
Defined in:
lib/forward/api/user.rb

Constant Summary

Constants inherited from Resource

Resource::DEFAULT_ERROR_MESSAGE

Constants included from Common

Common::EMAIL_REGEX

Instance Attribute Summary

Attributes inherited from Resource

#http, #uri

Class Method Summary collapse

Methods inherited from Resource

#add_body!, #add_head!, #delete, #get, #initialize, #post, #request

Methods included from Common

#config, #exit_with_error, #exit_with_message, #logged_in?, #logger, #os, #stop_reactor_and_exit, #windows?

Constructor Details

This class inherits a constructor from Forward::API::Resource

Class Method Details

.authenticate(email, password, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/forward/api/user.rb', line 5

def self.authenticate(email, password, &block)
  resource = new
  options  = {
    path: "#{API.base_path}/user/token",
    params: { email: email, password: password }
  }

  resource.post(options) do |response, status|
    if status != 200
      exit_with_error "Unable to authenticate `#{email}' on forwardhq.com"
    else
      block.call(response[:subdomain], response[:token])
    end
  end
end