vkponchik 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5d9121e737cf5462f86b09401971c5ce866f7b00d4676ca335d486a230089eb6
4
+ data.tar.gz: 61e95e6a190805710fe86737ba8f466a89b3ec5b2591d124d445a585d9115124
5
+ SHA512:
6
+ metadata.gz: 3cc15cfc9615f63d76d368d7599ffa42cd1ed9498fd2b842225f90d2329b637d1cd4f56bcea0cc1cb4dc95c5b6e232aee2058cdd099c3f8a74a8cbac3ab68aca
7
+ data.tar.gz: 7ecb79a72fd4449b41c86fac87c25d337c3e41efa43aff7a6cff111419372f08b3e1e4fdda133fc146dd8e50b596e46e377b184406996ba1d5eb2dc6d7c4ddb5
@@ -0,0 +1,42 @@
1
+ name: Main
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ rspec:
13
+ runs-on: ubuntu-latest
14
+ environment: test
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: 2.7.2
21
+ - name: Run the rspec task
22
+ env:
23
+ VKPONCHIK_GROUP: ${{ secrets.VKPONCHIK_GROUP }}
24
+ VKPONCHIK_TOKEN: ${{ secrets.VKPONCHIK_TOKEN }}
25
+ run: |
26
+ gem install bundler -v 2.2.4
27
+ bundle install
28
+ bundle exec rake spec
29
+ rubocop:
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - uses: actions/checkout@v2
33
+ - name: Set up Ruby
34
+ uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: 2.7.2
37
+ - name: Run the rubocop task
38
+ run: |
39
+ gem install bundler -v 2.2.4
40
+ bundle install
41
+ bundle exec rake rubocop
42
+
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # Dotenv for testing
14
+ .env
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,11 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+ TargetRubyVersion: 2.7
8
+
9
+ Metrics/BlockLength:
10
+ Exclude:
11
+ - spec/**/*
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in vkponchik.gemspec
6
+ gemspec
7
+
8
+ gem 'rake'
9
+
10
+ gem 'rspec'
11
+
12
+ gem 'rubocop'
13
+
14
+ gem 'rubocop-rake', require: false
15
+
16
+ gem 'rubocop-rspec', require: false
17
+
18
+ gem 'dotenv'
19
+
20
+ gem 'simplecov', require: false
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vkponchik (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ diff-lcs (1.4.4)
11
+ docile (1.3.4)
12
+ dotenv (2.7.6)
13
+ parallel (1.20.1)
14
+ parser (3.0.0.0)
15
+ ast (~> 2.4.1)
16
+ rainbow (3.0.0)
17
+ rake (13.0.3)
18
+ regexp_parser (2.0.3)
19
+ rexml (3.2.4)
20
+ rspec (3.10.0)
21
+ rspec-core (~> 3.10.0)
22
+ rspec-expectations (~> 3.10.0)
23
+ rspec-mocks (~> 3.10.0)
24
+ rspec-core (3.10.1)
25
+ rspec-support (~> 3.10.0)
26
+ rspec-expectations (3.10.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-mocks (3.10.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-support (3.10.1)
33
+ rubocop (1.8.0)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.0.0.0)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml
39
+ rubocop-ast (>= 1.2.0, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 3.0)
42
+ rubocop-ast (1.4.0)
43
+ parser (>= 2.7.1.5)
44
+ rubocop-rake (0.5.1)
45
+ rubocop
46
+ rubocop-rspec (2.1.0)
47
+ rubocop (~> 1.0)
48
+ rubocop-ast (>= 1.1.0)
49
+ ruby-progressbar (1.11.0)
50
+ simplecov (0.21.1)
51
+ docile (~> 1.1)
52
+ simplecov-html (~> 0.11)
53
+ simplecov_json_formatter (~> 0.1)
54
+ simplecov-html (0.12.3)
55
+ simplecov_json_formatter (0.1.2)
56
+ unicode-display_width (2.0.0)
57
+
58
+ PLATFORMS
59
+ x86_64-linux
60
+
61
+ DEPENDENCIES
62
+ dotenv
63
+ rake
64
+ rspec
65
+ rubocop
66
+ rubocop-rake
67
+ rubocop-rspec
68
+ simplecov
69
+ vkponchik!
70
+
71
+ BUNDLED WITH
72
+ 2.2.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Vladislav Kuznecov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Vkponchik
2
+
3
+ Really small and simple gem for interacting with vkdonuts.ru API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'vkponchik'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install vkponchik
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fizvlad/vkponchik-rb.
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'vkponchik'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'vkponchik/version'
4
+ require_relative 'vkponchik/client'
5
+ require_relative 'vkponchik/response'
6
+
7
+ # Vkponhik library namespace
8
+ module Vkponchik
9
+ class Error < StandardError; end
10
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ module Vkponchik
7
+ # API client class
8
+ class Client
9
+ API_VERSION = 1
10
+ API_BASE = 'https://api.vkdonuts.ru'
11
+ API_HEADERS = { 'Content-Type' => 'application/json' }.freeze
12
+ API_METHODS = [
13
+ 'donates/get', 'donates/change-status', 'donates/answer', 'donates/change-reward-status',
14
+ 'campaigns/get', 'campaigns/get-active', 'campaigns/get-rewards', 'campaigns/change',
15
+ 'campaigns/change-reward', 'payments/get', 'payments/create', 'balance'
16
+ ].freeze
17
+
18
+ # Initialize new client
19
+ # @param group [Integer] group ID
20
+ # @param token [String] group API token
21
+ def initialize(group, token)
22
+ @group = group
23
+ @token = token
24
+ end
25
+
26
+ # Send POST request to API server
27
+ # @param method [String] see {API_METHODS} array
28
+ # @param params [Hash] parameters to pass in POST request
29
+ # @return [Hash]
30
+ def request(method, **params)
31
+ validate_request_options(method, **params)
32
+
33
+ params[:v] = API_VERSION
34
+ params[:group] = @group
35
+ params[:token] = @token
36
+
37
+ uri = URI("#{API_BASE}/#{method}")
38
+ re = Net::HTTP.post(uri, params.to_json, API_HEADERS)
39
+
40
+ Response.new(JSON.parse(re.body))
41
+ rescue StandardError
42
+ raise Vkponchik::Error, 'Request failure'
43
+ end
44
+
45
+ private
46
+
47
+ def validate_request_options(method, **_params)
48
+ raise Vkponchik::Error, 'Invalid request method' unless API_METHODS.include?(method)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vkponchik
4
+ # API response
5
+ class Response
6
+ # @param hash [Hash]
7
+ def initialize(hash)
8
+ @hash = hash
9
+ end
10
+
11
+ # @return [Boolean]
12
+ def error?
13
+ !@hash['success']
14
+ end
15
+
16
+ # @return [Boolean]
17
+ def success?
18
+ !error?
19
+ end
20
+
21
+ # @return [String?]
22
+ def error_full_message
23
+ return unless error?
24
+
25
+ "#{@hash['error']}: #{@hash['msg']}"
26
+ end
27
+
28
+ # @return [Object?]
29
+ def [](arg)
30
+ @hash[arg.to_s]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vkponchik
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/vkponchik/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'vkponchik'
7
+ spec.version = Vkponchik::VERSION
8
+ spec.authors = ['Vladislav Kuznecov']
9
+ spec.email = ['fizvlad@mail.ru']
10
+
11
+ spec.summary = 'API client for VK Ponchik donations service.'
12
+ spec.homepage = 'https://github.com/fizvlad/vkponchik-rb'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/fizvlad/vkponchik-rb'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/fizvlad/vkponchik-rb/releases'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vkponchik
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vladislav Kuznecov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - fizvlad@mail.ru
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/main.yml"
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/console
30
+ - bin/setup
31
+ - lib/vkponchik.rb
32
+ - lib/vkponchik/client.rb
33
+ - lib/vkponchik/response.rb
34
+ - lib/vkponchik/version.rb
35
+ - vkponchik.gemspec
36
+ homepage: https://github.com/fizvlad/vkponchik-rb
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://github.com/fizvlad/vkponchik-rb
41
+ source_code_uri: https://github.com/fizvlad/vkponchik-rb
42
+ changelog_uri: https://github.com/fizvlad/vkponchik-rb/releases
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.7.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.2.4
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: API client for VK Ponchik donations service.
62
+ test_files: []