Class: EmojiDiffer::SlackApi

Inherits:
Struct
  • Object
show all
Defined in:
lib/emoji_differ/slack_api.rb

Constant Summary collapse

API_ENDPOINT =
'https://slack.com/api/emoji.list'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tokenObject

Returns the value of attribute token

Returns:

  • (Object)

    the current value of token



5
6
7
# File 'lib/emoji_differ/slack_api.rb', line 5

def token
  @token
end

Instance Method Details

#emojiObject



24
25
26
# File 'lib/emoji_differ/slack_api.rb', line 24

def emoji
  EmojiDiffer::List.from_json(raw_response.body)
end

#raw_responseObject



8
9
10
11
12
13
14
# File 'lib/emoji_differ/slack_api.rb', line 8

def raw_response
  @raw_response ||= Net::HTTP.get_response(uri).tap do |handle|
    if !handle.is_a?(Net::HTTPSuccess)
      raise "Slack API is out of business today, #{handle.inspect}"
    end
  end
end

#uriObject



16
17
18
19
20
21
22
# File 'lib/emoji_differ/slack_api.rb', line 16

def uri
  URI(API_ENDPOINT).tap do |uri|
    uri.query = URI.encode_www_form({
      token: token,
    })
  end
end