Class: Hoot::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/hoot/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



17
18
19
# File 'lib/hoot/client.rb', line 17

def initialize
	@hedwig = ENV['HEDWING_ENDPOINT'] || HEDWING_ENDPOINT
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



15
16
17
# File 'lib/hoot/client.rb', line 15

def credentials
  @credentials
end

#hedwigObject

Returns the value of attribute hedwig.



14
15
16
# File 'lib/hoot/client.rb', line 14

def hedwig
  @hedwig
end

Instance Method Details

#authenticate(credentials) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/hoot/client.rb', line 46

def authenticate(credentials)
	data = {
		:credentials => {
			:email => credentials[0],
			:password => credentials[1]
		}
	}

	response = request('authenticate', data)

	if response['result']
		Hoot::Keychain.save(credentials)
		abort('Authentication successful.')
	end

	puts 'Authentication failed.'

	Hoot::User::
end

#push(message = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hoot/client.rb', line 21

def push(message = nil)
	@credentials = Hoot::Keychain::credentials

	if message.nil?
		message = 'Hoot! Your command has completed! Come back!'
	end

	data = {
		:credentials => {
			:email => @credentials[0],
			:password => @credentials[1]
		},
		:message => message,
		:metadata => Hoot::Metadata.get
	}

	response = request('send', data)

	if response['result']
		abort('A Hoot was sent to your device.')
	end

	abort('A server error occurred.')
end