Class: MShard::MShard

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mshard/mshard.rb

Instance Method Summary collapse

Instance Method Details

#detour?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/mshard/mshard.rb', line 39

def detour?
  ENV['http_proxy']
end

#get(id) ⇒ Object



12
13
14
# File 'lib/mshard/mshard.rb', line 12

def get(id)
  self.class.get("/v2/shards/#{id}").body
end

#get_safe(*args) ⇒ Object



31
32
33
# File 'lib/mshard/mshard.rb', line 31

def get_safe(*args)
  try { get(*args) }
end

#notify(**args) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/mshard/mshard.rb', line 43

def notify(**args)
  return set(args) if detour?
  args[:slack] ||= true
  args[:webhook_url] ||= ENV['SLACK_WEBHOOK_URI']
  args[:channel] ||= ENV['SLACK_CHANNEL']
  Slack::Notifier.new(args[:webhook_url], **args).ping(args[:text])
end

#set(params) ⇒ Object



16
17
18
# File 'lib/mshard/mshard.rb', line 16

def set(params)
  self.class.post('/v2/shards', body: params)['id']
end

#set_safe(*args) ⇒ Object

rubocop:disable Naming/AccessorMethodName



35
36
37
# File 'lib/mshard/mshard.rb', line 35

def set_safe(*args) # rubocop:disable Naming/AccessorMethodName
  try { set(*args) }
end

#try(times: 3, delay: 2) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/mshard/mshard.rb', line 20

def try(times: 3, delay: 2)
  times.times do
    begin
      return yield
    rescue StandardError
      sleep delay
    end
  end
  nil
end