Skip to content

Commit

Permalink
feat: v4.0 API client (#96)
Browse files Browse the repository at this point in the history
* fix: Define path when filename is given to send_file (#92)

* fix: Check roles method instead of role_ids

* refactor: Move View to webhooks (#103)

* refactor: Move View to webhooks
* fix: Use Webhooks::View::COMPONENT_TYPES
* fix: Correct use of positional argument in Webhook#execute
* fix: Add alias with deprecation notice

* feat!: Remove restricted channels check (#101)

* refactor: Use chunk_index and chunk_count to determine chunk status. (#102)

* refactor: Use chunk_index and chunk_count to determine chunk status.

* refactor: additional chunking changes

* fix: apply requested changes

* fix: force guild recache from GUILD_CREATE (#104)

* fix: rescue from internal errors instead of rest-client (#106)

* feat: v4.0 API client WIP

* feat: Add guild endpoints

* feat: webhook endpoints

* feat: Migrate to new API client internally

* refactor: Use faraday in discordrb/webhooks. Switch gateway JSON to use symbols

* refactor: Use faraday in discordrb/webhooks. Switch gateway JSON to use symbols

* refactor!: Remove unsupported API methods

* refactor!: Remove old API methods

* fix: Remove further references to rest-client
  • Loading branch information
swarley authored Nov 28, 2021
1 parent 68ecd84 commit bd4feba
Show file tree
Hide file tree
Showing 80 changed files with 3,495 additions and 2,644 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ Style/SingleLineBlockParams:
Methods:
- reduce: [m, e]
- inject: [m, e]

Layout/EndOfLine:
EnforcedStyle: lf
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in discordrb.gemspec
gemspec name: 'discordrb'
gemspec name: 'discordrb-webhooks', development_group: 'webhooks'

3 changes: 2 additions & 1 deletion discordrb-webhooks.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'rest-client', '>= 2.0.0'
spec.add_dependency 'faraday', '~> 1.8'
spec.add_dependency 'faraday_middleware', '~> 1.1.0'

spec.required_ruby_version = '>= 2.6'
end
3 changes: 2 additions & 1 deletion discordrb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Gem::Specification.new do |spec|

spec.add_dependency 'ffi', '>= 1.9.24'
spec.add_dependency 'opus-ruby'
spec.add_dependency 'rest-client', '>= 2.0.0'
spec.add_dependency 'faraday', '~> 1.8'
spec.add_dependency 'faraday_middleware', '~> 1.1.0'
spec.add_dependency 'websocket-client-simple', '>= 0.3.0'

spec.add_dependency 'discordrb-webhooks', '~> 3.4.2'
Expand Down
23 changes: 23 additions & 0 deletions lib/discordrb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ def self.timestamp(time, style = nil)
"<t:#{time.to_i}:#{TIMESTAMP_STYLES[style] || style}>"
end
end

# TODO: This might belong somewhere else.
# Returns one of the "default" discord avatars from the CDN given a discriminator
def self.default_avatar(discrim = 0)
index = discrim.to_i % 5
"#{Discordrb::API.cdn_url}/embed/avatars/#{index}.png"
end

# TODO: This might belong somewhere else.
# Make an avatar URL from the user and avatar IDs
def self.avatar_url(user_id, avatar_id, format = nil)
format ||= if avatar_id.start_with?('a_')
'gif'
else
'webp'
end
"#{Discordrb::API.cdn_url}/avatars/#{user_id}/#{avatar_id}.#{format}"
end

# Make a banner URL from server and banner IDs
def self.banner_url(server_id, banner_id, format = 'webp')
"#{cdn_url}/banners/#{server_id}/#{banner_id}.#{format}"
end
end

# In discordrb, Integer and {String} are monkey-patched to allow for easy resolution of IDs
Expand Down
1 change: 0 additions & 1 deletion lib/discordrb/api.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'rest-client'
require 'json'
require 'time'

Expand Down
202 changes: 0 additions & 202 deletions lib/discordrb/api/application.rb

This file was deleted.

Loading

0 comments on commit bd4feba

Please sign in to comment.