vox 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4525b927b8d1067a91aa3062e4d72674958b11c4aa216a290824262a359c21eb
4
+ data.tar.gz: 7dac51047015695c88c46113cdd78424c483bada9456f068f96169645001381a
5
+ SHA512:
6
+ metadata.gz: 99abfab082caef047c4e244ef345353f5b98db418b1f1477abaa07c8bceab883e256045e039dd5d9850c2ebe2b8089b7bd9d57386db51c2df9daba1d2b5062f8
7
+ data.tar.gz: d760f0c0e5df2edc43ea4b17e0e3fabeccfa557cbd69def6963733177a5ab9b68a889a25ff857caaa978ac96cabd649fe00e6ac8428dd9728e593b8c1da1a0c5
@@ -0,0 +1,39 @@
1
+ name: Deploy Docs
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ tags:
8
+ - v*
9
+ paths-ignore:
10
+ - "vox.gemspec"
11
+ - "CHANGELOG.md"
12
+ - ".rubocop.yml"
13
+ - ".rspec"
14
+ - "Rakefile"
15
+
16
+ jobs:
17
+ deploy:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: 2.7.0
25
+ bundler-cache: true
26
+ - name: Install dependencies
27
+ run: bundle install
28
+ - name: Run YARD
29
+ run: bundle exec yard --output-dir docs
30
+ - name: Extract branch name
31
+ shell: bash
32
+ run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
33
+ id: extract_branch
34
+ - name: Deploy to gh-pages
35
+ uses: peaceiris/actions-gh-pages@v3.7.0-8
36
+ with:
37
+ personal_token: ${{ secrets.GITHUB_TOKEN }}
38
+ publish_dir: docs
39
+ destination_dir: ${{ steps.extract_branch.outputs.branch }}
@@ -0,0 +1,29 @@
1
+ name: RSpec
2
+
3
+ on:
4
+ push:
5
+ paths-ignore:
6
+ - "**.md"
7
+ pull_request:
8
+ paths-ignore:
9
+ - "**.md"
10
+
11
+ jobs:
12
+ rspec:
13
+ strategy:
14
+ matrix:
15
+ os: [ ubuntu-20.04, macos-10.15, windows-2019 ]
16
+ ruby: [ 2.5, 2.6.6, 2.7 ]
17
+ runs-on: ${{ matrix.os }}
18
+
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Install dependencies
27
+ run: bundle install
28
+ - name: Run RSpec
29
+ run: bundle exec rake
@@ -0,0 +1,24 @@
1
+ name: Rubocop
2
+
3
+ on:
4
+ push:
5
+ paths-ignore:
6
+ - "**.md"
7
+ pull_request:
8
+ paths-ignore:
9
+ - "**.md"
10
+
11
+ jobs:
12
+ rubocop:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.7.0
20
+ bundler-cache: true
21
+ - name: Install dependencies
22
+ run: bundle install
23
+ - name: Run Rubocop
24
+ run: bundle exec rubocop -c .rubocop.yml -P
@@ -0,0 +1,32 @@
1
+ name: YARD
2
+
3
+ on:
4
+ push:
5
+ paths-ignore:
6
+ - "vox.gemspec"
7
+ - "CHANGELOG.md"
8
+ - ".rubocop.yml"
9
+ - ".rspec"
10
+ - "Rakefile"
11
+ pull_request:
12
+ paths-ignore:
13
+ - "vox.gemspec"
14
+ - "CHANGELOG.md"
15
+ - ".rubocop.yml"
16
+ - ".rspec"
17
+ - "Rakefile"
18
+
19
+ jobs:
20
+ yard:
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - name: Set up Ruby
25
+ uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: 2.7.0
28
+ bundler-cache: true
29
+ - name: Install dependencies
30
+ run: bundle install
31
+ - name: Run YARD
32
+ run: bundle exec yard doc
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /bin/
10
+
11
+ Gemfile.lock
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,22 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.5
7
+ Exclude:
8
+ - bin/*
9
+ - vendor/**/*
10
+ NewCops: enable
11
+
12
+ Style/FormatStringToken:
13
+ Enabled: false
14
+
15
+ Style/RaiseArgs:
16
+ Enabled: false
17
+
18
+ RSpec/FilePath:
19
+ SpecSuffixOnly: true
20
+
21
+ Metrics:
22
+ Enabled: false
@@ -0,0 +1,4 @@
1
+ --tag vox.permissions:"Required Permissions"
2
+ --tag vox.api_docs:"View On Discord's Docs"
3
+ --tag vox.oauth_scope:"Required OAuth2 Scope"
4
+ --main README.md
File without changes
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at matthew.b.carey@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in vox.gemspec
6
+ gemspec
@@ -0,0 +1,25 @@
1
+ The MIT License (MIT)
2
+ =====================
3
+
4
+ Copyright © `2020` `Matthew Carey`
5
+
6
+ Permission is hereby granted, free of charge, to any person
7
+ obtaining a copy of this software and associated documentation
8
+ files (the “Software”), to deal in the Software without
9
+ restriction, including without limitation the rights to use,
10
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the
12
+ Software is furnished to do so, subject to the following
13
+ conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # Vox
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vox`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vox'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vox
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/swarley/vox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/swarley/vox/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Vox project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/swarley/vox/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.rspec_opts = '--format progress'
9
+ t.verbose = false
10
+ end
11
+
12
+ RuboCop::RakeTask.new(:rubocop)
13
+
14
+ task default: :spec
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'vox/version'
4
+
5
+ # Parent module containing all component pieces
6
+ module Vox
7
+ # Catch all error for all Vox error subclasses
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'logging'
5
+ require 'securerandom'
6
+ # require 'vox/http/routes/audit_log'
7
+ # require 'vox/http/routes/channel'
8
+ # require 'vox/http/routes/emoji'
9
+ # require 'vox/http/routes/guild'
10
+ # require 'vox/http/routes/invite'
11
+ # require 'vox/http/routes/user'
12
+ # require 'vox/http/routes/voice'
13
+ # require 'vox/http/routes/webhook'
14
+ require 'vox/http/route'
15
+ require 'vox/http/routes'
16
+ require 'vox/http/error'
17
+ require 'vox/http/middleware'
18
+
19
+ module Vox
20
+ # The HTTP component used to interact with the REST portion of the API.
21
+ # Contains a client, as well as modular paths if you wish to provide your own client
22
+ # with support for the same `request` method signature.
23
+ module HTTP
24
+ # HTTP Client for interacting with the REST portion of the Discord API
25
+ class Client
26
+ # include AuditLog
27
+ # include Channel
28
+ # include Emoji
29
+ # include Guild
30
+ # include Invite
31
+ # include User
32
+ # include Voice
33
+ # include Webhook
34
+ include Routes
35
+
36
+ # @!visibility private
37
+ attr_reader :conn
38
+
39
+ # TODO: Maybe fallback to extrapolating the key from URLs so we
40
+ # can expose the connection for use outside of our request function?
41
+
42
+ # Discord REST API version.
43
+ API_VERSION = '8'
44
+
45
+ # Base URL to base endpoints off of.
46
+ API_BASE = "https://discord.com/api/v#{API_VERSION}/"
47
+
48
+ # Headers that form the base for every request.
49
+ DEFAULT_HEADERS = {
50
+ 'User-Agent': "DiscordBot (https://github.com/swarley/vox, #{Vox::VERSION})"
51
+ }.freeze
52
+
53
+ def initialize(token)
54
+ @conn = default_connection
55
+ @conn.authorization('Bot', token.delete_prefix('Bot '))
56
+ yield(@conn) if block_given?
57
+ end
58
+
59
+ # Run a request
60
+ # @param query [Hash<String, String>, nil] Query string parameters.
61
+ # @param data [Hash<(String, Integer), (String, #content_type)>, String, nil] HTTP body for non-JSON payloads.
62
+ # @param json [Hash, nil] Object that will be serialized to JSON for requests.
63
+ # @param raw [true, false] Whether or not the response body should be parsed from
64
+ # JSON.
65
+ # @param reason [String, nil] Reason for use in paths that support audit log reasons.
66
+ # @return [Hash, nil] The response body serialized to a Hash, or nil when a route returns 204.
67
+ def request(route, query: nil, data: nil, json: nil, raw: nil, reason: nil)
68
+ req = @conn.build_request(route.verb) do |r|
69
+ setup_basic_request(r, route, query: query, reason: reason)
70
+
71
+ if json
72
+ r.body = MultiJson.dump(json)
73
+ r.headers['Content-Type'] = 'application/json'
74
+ elsif data
75
+ r.body = data
76
+ end
77
+ end
78
+
79
+ begin
80
+ resp = @conn.builder.build_response(@conn, req)
81
+ handle_response(resp, raw, req.options.context[:trace])
82
+ rescue Error::TooManyRequests
83
+ retry
84
+ end
85
+ end
86
+
87
+ # @!visibility private
88
+ # Hide the big instance variables
89
+ def inspect
90
+ "#<Vox::HTTP::Client:0x#{object_id.to_s(16).rjust(16, '0')}>"
91
+ end
92
+
93
+ private
94
+
95
+ # @param req [Faraday::Request] Request to be executed
96
+ # @param route [Vox::HTTP::Route]
97
+ # @param query [Hash<String, String>, nil]
98
+ # @param reason [String, nil]
99
+ def setup_basic_request(req, route, query: nil, reason: nil)
100
+ req.path = route.format.delete_prefix('/')
101
+ req.params = query unless query.nil? || query.empty?
102
+ req.headers['X-Audit-Log-Reason'] = reason if reason
103
+ req.options.context = { rl_key: route.rl_key, trace: SecureRandom.alphanumeric(6) }
104
+ end
105
+
106
+ # @param resp [Faraday::Response] The response to be processed.
107
+ def handle_response(resp, raw, req_id)
108
+ raise Error::ServerError.new(req_id) if (500..600).cover? resp.status
109
+
110
+ data = raw ? resp.body : MultiJson.load(resp.body, symbolize_keys: true)
111
+ case resp.status
112
+ when 200
113
+ data
114
+ when 204, 304
115
+ nil
116
+ when 400
117
+ raise Error::BadRequest.new(data, req_id)
118
+ when 401
119
+ raise Error::Unauthorized.new(data, req_id)
120
+ when 403
121
+ raise Error::Forbidden.new(data, req_id)
122
+ when 404
123
+ raise Error::NotFound.new(data, req_id)
124
+ when 405
125
+ raise Error::MethodNotAllowed.new(data, req_id)
126
+ when 429
127
+ raise Error::TooManyRequests.new(data, req_id)
128
+ end
129
+ end
130
+
131
+ # A default connection used when you're not passing your own
132
+ # @return [Faraday::Connection]
133
+ def default_connection
134
+ Faraday.new(url: API_BASE, headers: DEFAULT_HEADERS) do |faraday|
135
+ faraday.use :vox_ratelimiter
136
+ faraday.request :multipart
137
+ faraday.response(
138
+ :logger,
139
+ Logging.logger['Vox::HTTP'],
140
+ { formatter: Vox::HTTP::Middleware::LogFormatter }
141
+ )
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end