Class: EyePea::Client

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

Constant Summary collapse

@@DEBUG =
false
@@API =
'http://eyepea.heroku.com/api/1'

Class Method Summary collapse

Class Method Details

.error_msgObject

Error when can't find ip



35
36
37
38
39
40
# File 'lib/eyepea/client.rb', line 35

def self.error_msg
  msgs = [
    'Uh oh! Some unknown error occurred'
  ]
  msgs[rand(msgs.size)]
end

.get_ipObject

Make api request to get IP



23
24
25
26
27
28
29
30
31
32
# File 'lib/eyepea/client.rb', line 23

def self.get_ip
  result = Net::HTTP.get(URI.parse(@@API+'/ip.json'))
  json_result = JSON.parse(result)

  if json_result.has_key? 'Error'
    raise 'JSON error'
  end

  json_result['ip'].to_s
end

.loading_msgObject

Text loading



47
48
49
50
51
52
53
54
55
# File 'lib/eyepea/client.rb', line 47

def self.loading_msg
  msgs = [
    'Body massage machine go',
    'Searching the intertubes',
    'Dialing up',
    'Here we go'
  ]
  msgs[rand(msgs.size)] + '..'
end

.run!Object

Run her baby



11
12
13
14
15
16
17
18
19
20
# File 'lib/eyepea/client.rb', line 11

def self.run!
  puts self.loading_msg
  begin
    ip = self.get_ip
    puts self.success_msg(ip)
  rescue Exception => e
    puts e if @@DEBUG
    puts self.error_msg
  end
end

.success_msg(ip) ⇒ Object



42
43
44
# File 'lib/eyepea/client.rb', line 42

def self.success_msg(ip)
  "IP: "+ip.to_s
end