vkdonate 1.0.2 → 1.1.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.
- checksums.yaml +4 -4
- data/.env.example +1 -0
- data/.github/workflows/ruby.yml +35 -0
- data/.gitignore +11 -8
- data/.rspec +1 -0
- data/.rubocop.yml +60 -0
- data/Gemfile +35 -3
- data/Gemfile.lock +88 -24
- data/LICENSE +0 -0
- data/README.md +1 -1
- data/Rakefile +15 -7
- data/bin/console +7 -4
- data/lib/vkdonate.rb +62 -106
- data/lib/vkdonate/client.rb +23 -0
- data/lib/vkdonate/donate.rb +69 -94
- data/vkdonate.gemspec +18 -16
- metadata +13 -38
- data/.travis.yml +0 -7
- data/lib/vkdonate/version.rb +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a8f1e20f5c7f0e039827614913ccf8873921cf94cb382563d8bfc993670e0abb
|
|
4
|
+
data.tar.gz: cd466099a4d030217258d97a70d860733ebd81fee2fa91f2342dab04b7074ba9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d1b22d1284a68423122b8e05462f8467ef07741988e5b74b72d91ed2630449453e495ab9e6f5cf65847f13e0f33c223b313a7e34a0f2a2fc538902104bfaf48
|
|
7
|
+
data.tar.gz: 2c1b3f63ab414c0efe8f95e57f533cca7f4a6419a3513683779a5f28b7c4c0da9b7bb8c6b8020e63f53ce4ff1c64b7623c82e0ecc55b72e29c9d4aad13c92069
|
data/.env.example
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
API_KEY=0123456789abcdefg
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: Ruby
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [ master ]
|
|
13
|
+
pull_request:
|
|
14
|
+
branches: [ master ]
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
test:
|
|
18
|
+
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v2
|
|
23
|
+
- name: Set up Ruby
|
|
24
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
|
25
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
|
26
|
+
# uses: ruby/setup-ruby@v1
|
|
27
|
+
uses: ruby/setup-ruby@v1.52.0
|
|
28
|
+
with:
|
|
29
|
+
ruby-version: 2.7.2
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: bundle install
|
|
32
|
+
- name: Run rubocop
|
|
33
|
+
run: bundle exec rake rubocop
|
|
34
|
+
- name: Run yarddoc
|
|
35
|
+
run: bundle exec rake yard
|
data/.gitignore
CHANGED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# The behavior of RuboCop can be controlled via the .rubocop.yml
|
|
2
|
+
# configuration file. It makes it possible to enable/disable
|
|
3
|
+
# certain cops (checks) and to alter their behavior if they accept
|
|
4
|
+
# any parameters. The file can be placed either in your home
|
|
5
|
+
# directory or in some project directory.
|
|
6
|
+
#
|
|
7
|
+
# RuboCop will start looking for the configuration file in the directory
|
|
8
|
+
# where the inspected file is and continue its way up to the root directory.
|
|
9
|
+
#
|
|
10
|
+
# See https://docs.rubocop.org/rubocop/configuration
|
|
11
|
+
|
|
12
|
+
AllCops:
|
|
13
|
+
TargetRubyVersion: 2.7
|
|
14
|
+
EnabledByDefault: true
|
|
15
|
+
|
|
16
|
+
Layout/FirstMethodParameterLineBreak:
|
|
17
|
+
Enabled: false
|
|
18
|
+
Layout/FirstMethodArgumentLineBreak:
|
|
19
|
+
Enabled: false
|
|
20
|
+
Layout/MultilineMethodArgumentLineBreaks:
|
|
21
|
+
Enabled: false
|
|
22
|
+
Layout/EndOfLine:
|
|
23
|
+
Enabled: false
|
|
24
|
+
Layout/EndAlignment:
|
|
25
|
+
EnforcedStyleAlignWith: variable
|
|
26
|
+
Layout/FirstHashElementIndentation:
|
|
27
|
+
Enabled: false
|
|
28
|
+
Layout/MultilineAssignmentLayout:
|
|
29
|
+
EnforcedStyle: same_line
|
|
30
|
+
Layout/CaseIndentation:
|
|
31
|
+
EnforcedStyle: end
|
|
32
|
+
Lint/ConstantResolution:
|
|
33
|
+
Enabled: false
|
|
34
|
+
Metrics/ParameterLists:
|
|
35
|
+
Enabled: false
|
|
36
|
+
Metrics/BlockLength:
|
|
37
|
+
Exclude:
|
|
38
|
+
- 'spec/**/*_spec.rb'
|
|
39
|
+
Style/MethodCallWithArgsParentheses:
|
|
40
|
+
Enabled: false
|
|
41
|
+
Style/Copyright:
|
|
42
|
+
Enabled: false
|
|
43
|
+
Style/ClassVars:
|
|
44
|
+
Enabled: false
|
|
45
|
+
Style/MissingElse:
|
|
46
|
+
Enabled: false
|
|
47
|
+
Style/StringHashKeys:
|
|
48
|
+
Enabled: false
|
|
49
|
+
Style/ImplicitRuntimeError:
|
|
50
|
+
Enabled: false
|
|
51
|
+
Style/NumericLiterals:
|
|
52
|
+
Enabled: false
|
|
53
|
+
Style/DisableCopsWithinSourceCodeDirective:
|
|
54
|
+
Enabled: false
|
|
55
|
+
Style/DoubleNegation:
|
|
56
|
+
Enabled: false
|
|
57
|
+
Style/DateTime:
|
|
58
|
+
Enabled: false
|
|
59
|
+
Layout/MultilineHashKeyLineBreaks:
|
|
60
|
+
Enabled: false
|
data/Gemfile
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
2
4
|
|
|
3
5
|
# Specify your gem's dependencies in vkdonate.gemspec
|
|
4
6
|
gemspec
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
|
|
8
|
+
group :test, :development do
|
|
9
|
+
# Debugging console
|
|
10
|
+
gem 'pry'
|
|
11
|
+
|
|
12
|
+
# Another debugging console
|
|
13
|
+
gem 'byebug'
|
|
14
|
+
|
|
15
|
+
# The thing, forcing you to write good code
|
|
16
|
+
gem 'rubocop', require: false
|
|
17
|
+
|
|
18
|
+
# Rake tasks
|
|
19
|
+
gem 'rake', require: false
|
|
20
|
+
|
|
21
|
+
# Testing
|
|
22
|
+
gem 'rspec', require: false
|
|
23
|
+
|
|
24
|
+
# Docs
|
|
25
|
+
gem 'yard', require: false
|
|
26
|
+
|
|
27
|
+
# .env support
|
|
28
|
+
gem 'dotenv'
|
|
29
|
+
|
|
30
|
+
# Save web requests for fast and reliable testing
|
|
31
|
+
gem 'vcr'
|
|
32
|
+
|
|
33
|
+
# Stub web requests
|
|
34
|
+
gem 'webmock'
|
|
35
|
+
|
|
36
|
+
# Test coverage
|
|
37
|
+
gem 'simplecov', require: false, group: :test
|
|
38
|
+
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,24 +1,88 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
vkdonate (1.0.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
vkdonate (1.0.2)
|
|
5
|
+
json (~> 2.3)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
addressable (2.7.0)
|
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
12
|
+
ast (2.4.1)
|
|
13
|
+
byebug (11.1.3)
|
|
14
|
+
coderay (1.1.3)
|
|
15
|
+
crack (0.4.4)
|
|
16
|
+
diff-lcs (1.4.4)
|
|
17
|
+
docile (1.3.2)
|
|
18
|
+
dotenv (2.7.6)
|
|
19
|
+
hashdiff (1.0.1)
|
|
20
|
+
json (2.3.1)
|
|
21
|
+
method_source (1.0.0)
|
|
22
|
+
parallel (1.20.1)
|
|
23
|
+
parser (2.7.2.0)
|
|
24
|
+
ast (~> 2.4.1)
|
|
25
|
+
pry (0.13.1)
|
|
26
|
+
coderay (~> 1.1)
|
|
27
|
+
method_source (~> 1.0)
|
|
28
|
+
public_suffix (4.0.6)
|
|
29
|
+
rainbow (3.0.0)
|
|
30
|
+
rake (13.0.1)
|
|
31
|
+
regexp_parser (2.0.0)
|
|
32
|
+
rexml (3.2.4)
|
|
33
|
+
rspec (3.10.0)
|
|
34
|
+
rspec-core (~> 3.10.0)
|
|
35
|
+
rspec-expectations (~> 3.10.0)
|
|
36
|
+
rspec-mocks (~> 3.10.0)
|
|
37
|
+
rspec-core (3.10.0)
|
|
38
|
+
rspec-support (~> 3.10.0)
|
|
39
|
+
rspec-expectations (3.10.0)
|
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
41
|
+
rspec-support (~> 3.10.0)
|
|
42
|
+
rspec-mocks (3.10.0)
|
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
44
|
+
rspec-support (~> 3.10.0)
|
|
45
|
+
rspec-support (3.10.0)
|
|
46
|
+
rubocop (1.4.2)
|
|
47
|
+
parallel (~> 1.10)
|
|
48
|
+
parser (>= 2.7.1.5)
|
|
49
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
50
|
+
regexp_parser (>= 1.8)
|
|
51
|
+
rexml
|
|
52
|
+
rubocop-ast (>= 1.1.1)
|
|
53
|
+
ruby-progressbar (~> 1.7)
|
|
54
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
|
55
|
+
rubocop-ast (1.2.0)
|
|
56
|
+
parser (>= 2.7.1.5)
|
|
57
|
+
ruby-progressbar (1.10.1)
|
|
58
|
+
simplecov (0.19.1)
|
|
59
|
+
docile (~> 1.1)
|
|
60
|
+
simplecov-html (~> 0.11)
|
|
61
|
+
simplecov-html (0.12.3)
|
|
62
|
+
unicode-display_width (1.7.0)
|
|
63
|
+
vcr (6.0.0)
|
|
64
|
+
webmock (3.10.0)
|
|
65
|
+
addressable (>= 2.3.6)
|
|
66
|
+
crack (>= 0.3.2)
|
|
67
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
68
|
+
yard (0.9.25)
|
|
69
|
+
|
|
70
|
+
PLATFORMS
|
|
71
|
+
ruby
|
|
72
|
+
x64-mingw32
|
|
73
|
+
|
|
74
|
+
DEPENDENCIES
|
|
75
|
+
byebug
|
|
76
|
+
dotenv
|
|
77
|
+
pry
|
|
78
|
+
rake
|
|
79
|
+
rspec
|
|
80
|
+
rubocop
|
|
81
|
+
simplecov
|
|
82
|
+
vcr
|
|
83
|
+
vkdonate!
|
|
84
|
+
webmock
|
|
85
|
+
yard
|
|
86
|
+
|
|
87
|
+
BUNDLED WITH
|
|
88
|
+
2.1.4
|
data/LICENSE
CHANGED
|
File without changes
|
data/README.md
CHANGED
data/Rakefile
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
require "rake/testtask"
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
require 'rubocop/rake_task'
|
|
6
|
+
require 'yard'
|
|
7
|
+
|
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
9
|
+
|
|
10
|
+
RuboCop::RakeTask.new
|
|
11
|
+
|
|
12
|
+
YARD::Rake::YardocTask.new do |t|
|
|
13
|
+
t.files = ['lib/**/*.rb']
|
|
14
|
+
t.options = ['--any', '--extra', '--opts']
|
|
15
|
+
t.stats_options = ['--list-undoc']
|
|
8
16
|
end
|
|
9
17
|
|
|
10
|
-
task :
|
|
18
|
+
task default: %i[rubocop spec yard]
|
data/bin/console
CHANGED
data/lib/vkdonate.rb
CHANGED
|
@@ -1,131 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
require "vkdonate/donate"
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'date'
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
require 'vkdonate/client'
|
|
8
|
+
require 'vkdonate/donate'
|
|
9
|
+
|
|
10
|
+
# Main module
|
|
10
11
|
module Vkdonate
|
|
12
|
+
# Gem version
|
|
13
|
+
VERSION = '1.1.0'
|
|
14
|
+
public_constant :VERSION
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
REQUEST_URI
|
|
16
|
+
# URI for requests
|
|
17
|
+
REQUEST_URI = URI('https://api.vkdonate.ru')
|
|
18
|
+
private_constant :REQUEST_URI
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
# Array of available actions
|
|
21
|
+
ACTIONS = %i[donates].freeze
|
|
22
|
+
private_constant :ACTIONS
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
# Array of available sort-by
|
|
25
|
+
SORT = %i[date sum].freeze
|
|
26
|
+
private_constant :SORT
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
# Array of available order-by
|
|
29
|
+
ORDER = %i[asc desc].freeze
|
|
30
|
+
private_constant :ORDER
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
TIME_OFFSET
|
|
32
|
+
# Time offset of API server
|
|
33
|
+
TIME_OFFSET = 'UTC+3'
|
|
34
|
+
private_constant :TIME_OFFSET
|
|
31
35
|
|
|
32
|
-
##
|
|
33
36
|
# Requests timeout in seconds
|
|
34
37
|
REQUEST_TIMEOUT = 10
|
|
38
|
+
private_constant :REQUEST_TIMEOUT
|
|
35
39
|
|
|
36
|
-
##
|
|
37
40
|
# @!macro [new] request_option
|
|
38
|
-
# @
|
|
39
|
-
# @
|
|
40
|
-
# @
|
|
41
|
-
# @
|
|
41
|
+
# @param count [Integer] amount of donates (up to 50)
|
|
42
|
+
# @param offset [Integer] donates offset
|
|
43
|
+
# @param sort [Symbol] sort by
|
|
44
|
+
# @param order [Symbol] order by
|
|
42
45
|
# @see Vkdonate::SORT
|
|
43
46
|
# @see Vkdonate::ORDER
|
|
44
|
-
#
|
|
45
|
-
# @!macro [new] request_return
|
|
46
|
-
# @return [Array]
|
|
47
|
-
#
|
|
48
|
-
# @!macro [new] request
|
|
49
|
-
# Simple POST request to API.
|
|
50
|
-
# @param action [Symbol]
|
|
51
|
-
# @param options [Hash]
|
|
52
|
-
# @!macro request_option
|
|
53
|
-
# @see Vkdonate::ACTIONS
|
|
54
|
-
# @!macro request_return
|
|
55
|
-
#
|
|
56
|
-
# @!macro [new] donates
|
|
57
|
-
# POST request for +donates+ action.
|
|
58
|
-
# @param options [Hash]
|
|
59
|
-
# @!macro request_option
|
|
60
|
-
# @see Vkdonate::ACTIONS
|
|
61
|
-
# @!macro request_return
|
|
62
|
-
|
|
63
|
-
##
|
|
64
|
-
# @param api_key [String]
|
|
65
|
-
# @!macro request
|
|
66
|
-
def self.request(api_key, action, options = {})
|
|
67
|
-
raise "Unknown action" unless ACTIONS.include? action
|
|
68
|
-
|
|
69
|
-
count = options[:count] || 10
|
|
70
|
-
offset = options[:offset] || 0
|
|
71
|
-
sort = options[:sort] || :date
|
|
72
|
-
order = options[:order] || :desc
|
|
73
|
-
|
|
74
|
-
raise "Count is out of range" unless count >= 1 && count <= 50
|
|
75
|
-
raise "Offset is out of range" unless offset >= 0
|
|
76
|
-
raise "Unknown sorting" unless SORT.include? sort
|
|
77
|
-
raise "Unknown ordering" unless ORDER.include? order
|
|
78
|
-
|
|
79
|
-
res = Net::HTTP.post_form(REQUEST_URI,
|
|
80
|
-
key: api_key.to_s,
|
|
81
|
-
action: action.to_s,
|
|
82
|
-
count: count.to_i,
|
|
83
|
-
offset: offset.to_i,
|
|
84
|
-
sort: sort.to_s,
|
|
85
|
-
order: order.to_s
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
json = JSON.parse res.body
|
|
89
|
-
|
|
90
|
-
if json["success"]
|
|
91
|
-
json["donates"].map { |e| Donate.from_json(e) }
|
|
92
|
-
else
|
|
93
|
-
raise json["text"]
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
47
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
48
|
+
class << self
|
|
49
|
+
# Simple POST request to API
|
|
50
|
+
# @param api_key [String]
|
|
51
|
+
# @param action [Symbol]
|
|
52
|
+
# @!macro request_option
|
|
53
|
+
# @see Vkdonate::ACTIONS
|
|
54
|
+
# @return [Array]
|
|
55
|
+
def request(api_key, action, count: 10, offset: 0, sort: :date, order: :desc)
|
|
56
|
+
validate_request_options(action, count, offset, sort, order)
|
|
103
57
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
class Client
|
|
58
|
+
res = Net::HTTP.post_form(REQUEST_URI, key: api_key, action: action.to_s, count: count,
|
|
59
|
+
offset: offset, sort: sort.to_s, order: order.to_s)
|
|
107
60
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
# @param api_key [String]
|
|
112
|
-
def initialize(api_key)
|
|
113
|
-
@api_key = api_key.to_s
|
|
114
|
-
raise "API key can not be empty" if @api_key.empty?
|
|
115
|
-
end
|
|
61
|
+
json = JSON.parse res.body
|
|
62
|
+
|
|
63
|
+
raise json['text'] unless json['success']
|
|
116
64
|
|
|
117
|
-
|
|
118
|
-
# @!macro request
|
|
119
|
-
def request(action, options = {})
|
|
120
|
-
Vkdonate.request(@api_key, action, options)
|
|
65
|
+
json['donates'].map { |e| Donate.from_json(e) }
|
|
121
66
|
end
|
|
122
67
|
|
|
123
|
-
|
|
124
|
-
#
|
|
125
|
-
|
|
126
|
-
|
|
68
|
+
# POST request for +donates+ action
|
|
69
|
+
# @param api_key [String]
|
|
70
|
+
# @!macro request_option
|
|
71
|
+
# @see Vkdonate.request
|
|
72
|
+
# @return [Array]
|
|
73
|
+
def donates(api_key, **options)
|
|
74
|
+
request(api_key, :donates, **options)
|
|
127
75
|
end
|
|
128
76
|
|
|
129
|
-
|
|
77
|
+
private
|
|
130
78
|
|
|
79
|
+
def validate_request_options(action, count, offset, sort, order)
|
|
80
|
+
raise 'Unknown action' unless ACTIONS.include? action
|
|
81
|
+
raise 'Count is out of range' unless count >= 1 && count <= 50
|
|
82
|
+
raise 'Offset is out of range' unless offset >= 0
|
|
83
|
+
raise 'Unknown sorting' unless SORT.include? sort
|
|
84
|
+
raise 'Unknown ordering' unless ORDER.include? order
|
|
85
|
+
end
|
|
86
|
+
end
|
|
131
87
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Vkdonate
|
|
4
|
+
# Client which saves API key
|
|
5
|
+
class Client
|
|
6
|
+
# New client to work with API
|
|
7
|
+
# @param api_key [String]
|
|
8
|
+
def initialize(api_key)
|
|
9
|
+
@api_key = api_key.to_s
|
|
10
|
+
raise 'API key can not be empty' if @api_key.empty?
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @see VkDonate.request
|
|
14
|
+
def request(action, **options)
|
|
15
|
+
Vkdonate.request(@api_key, action, **options)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @see VkDonate.donates
|
|
19
|
+
def donates(**options)
|
|
20
|
+
Vkdonate.donates(@api_key, **options)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/vkdonate/donate.rb
CHANGED
|
@@ -1,94 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
# Single donation
|
|
5
|
-
class Donate
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# @return [
|
|
13
|
-
attr_reader :
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# @
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#
|
|
50
|
-
# @
|
|
51
|
-
# @
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
@visible = !!options[:visible]
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
##
|
|
75
|
-
# Parse from JSON hash.
|
|
76
|
-
#
|
|
77
|
-
# @param hash [Hash] parsed JSON hash.
|
|
78
|
-
#
|
|
79
|
-
# @return [Donate]
|
|
80
|
-
def self.from_json(hash)
|
|
81
|
-
self.new(
|
|
82
|
-
id: hash["id"].to_i,
|
|
83
|
-
uid: hash["uid"].to_i,
|
|
84
|
-
date: DateTime.parse(hash["date"] + " #{TIME_OFFSET}"),
|
|
85
|
-
sum: hash["sum"].to_i,
|
|
86
|
-
msg: hash["msg"].empty? ? nil : hash["msg"],
|
|
87
|
-
anon: !hash["anon"].to_i.zero?,
|
|
88
|
-
visible: !hash["visible"].to_i.zero?
|
|
89
|
-
)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Vkdonate
|
|
4
|
+
# Single donation
|
|
5
|
+
class Donate
|
|
6
|
+
# @return [Integer] Unique payment ID
|
|
7
|
+
attr_reader :id
|
|
8
|
+
|
|
9
|
+
# @return [Integer] Donator VK ID
|
|
10
|
+
attr_reader :uid
|
|
11
|
+
|
|
12
|
+
# @return [DateTime] Date and time of donation
|
|
13
|
+
attr_reader :date
|
|
14
|
+
|
|
15
|
+
# @return [Integer] Size of donation
|
|
16
|
+
attr_reader :sum
|
|
17
|
+
|
|
18
|
+
# @return [String] User message or +nil+ if empty
|
|
19
|
+
attr_reader :msg
|
|
20
|
+
alias message msg
|
|
21
|
+
|
|
22
|
+
# @return [Boolean] Whether donation is anonymous
|
|
23
|
+
attr_reader :anon
|
|
24
|
+
alias anon? anon
|
|
25
|
+
|
|
26
|
+
# @return [Boolean] Whether donate is visible in group
|
|
27
|
+
attr_reader :visible
|
|
28
|
+
alias visible? visible
|
|
29
|
+
|
|
30
|
+
# Save data about donation.
|
|
31
|
+
# @param options [Hash]
|
|
32
|
+
# @option options [Integer] id
|
|
33
|
+
# @option options [Integer] uid
|
|
34
|
+
# @option options [DateTime] date
|
|
35
|
+
# @option options [Integer] sum
|
|
36
|
+
# @option options [String] msg
|
|
37
|
+
# @option options [Boolean] anon
|
|
38
|
+
# @option options [Boolean] visible
|
|
39
|
+
def initialize(id:, uid:, date:, sum:, msg:, anon:, visible:)
|
|
40
|
+
@id = id
|
|
41
|
+
@uid = uid
|
|
42
|
+
@date = date
|
|
43
|
+
@sum = sum
|
|
44
|
+
@msg = msg
|
|
45
|
+
@anon = anon
|
|
46
|
+
@visible = visible
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Parse from JSON hash.
|
|
50
|
+
# @param hash [Hash] parsed JSON hash.
|
|
51
|
+
# @return [Donate]
|
|
52
|
+
def self.from_json(hash)
|
|
53
|
+
new(
|
|
54
|
+
id: hash['id'],
|
|
55
|
+
uid: hash['uid'],
|
|
56
|
+
date: DateTime.parse(hash['date'] + " #{TIME_OFFSET}"),
|
|
57
|
+
sum: hash['sum'],
|
|
58
|
+
msg: hash['msg'].to_s,
|
|
59
|
+
anon: Integer(hash['anon'].to_s, 10) != 0,
|
|
60
|
+
visible: Integer(hash['visible'].to_s, 10) != 0
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# @return [String] Human readable information
|
|
65
|
+
def to_s
|
|
66
|
+
"Donation ##{id} by @#{uid} for #{sum}RUR (at #{date})"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
data/vkdonate.gemspec
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
-
require
|
|
5
|
+
require 'vkdonate'
|
|
4
6
|
|
|
5
7
|
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name =
|
|
8
|
+
spec.name = 'vkdonate'
|
|
7
9
|
spec.version = Vkdonate::VERSION
|
|
8
|
-
spec.authors = [
|
|
9
|
-
spec.email = [
|
|
10
|
+
spec.authors = ['Fizvlad']
|
|
11
|
+
spec.email = ['fizvlad@mail.ru']
|
|
12
|
+
|
|
13
|
+
spec.summary = 'This is small non-official gem which provides interface to interact with vkdonate.ru API'
|
|
14
|
+
spec.homepage = 'https://github.com/fizvlad/vkdonate-rb'
|
|
15
|
+
spec.license = 'MIT'
|
|
10
16
|
|
|
11
|
-
spec.
|
|
12
|
-
spec.homepage = "https://github.com/fizvlad/vkdonate-rb"
|
|
13
|
-
spec.license = "MIT"
|
|
17
|
+
spec.required_ruby_version = '>=2.7.1'
|
|
14
18
|
|
|
15
|
-
spec.metadata[
|
|
16
|
-
spec.metadata[
|
|
17
|
-
spec.metadata[
|
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/fizvlad/vkdonate-rb'
|
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/fizvlad/vkdonate-rb/releases'
|
|
18
22
|
|
|
19
23
|
# Specify which files should be added to the gem when it is released.
|
|
20
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
21
|
-
spec.files
|
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
22
26
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
23
27
|
end
|
|
24
|
-
spec.require_paths = [
|
|
28
|
+
spec.require_paths = ['lib']
|
|
25
29
|
|
|
26
|
-
spec.
|
|
27
|
-
spec.add_development_dependency "rake", "~> 12.0"
|
|
28
|
-
spec.add_development_dependency "minitest", "~> 5.0"
|
|
30
|
+
spec.add_runtime_dependency('json', '~> 2.3')
|
|
29
31
|
end
|
metadata
CHANGED
|
@@ -1,57 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vkdonate
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Fizvlad
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-11-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: json
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '2.
|
|
20
|
-
type: :
|
|
19
|
+
version: '2.3'
|
|
20
|
+
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '2.
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: rake
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '12.0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '12.0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: minitest
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '5.0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '5.0'
|
|
26
|
+
version: '2.3'
|
|
55
27
|
description:
|
|
56
28
|
email:
|
|
57
29
|
- fizvlad@mail.ru
|
|
@@ -59,8 +31,11 @@ executables: []
|
|
|
59
31
|
extensions: []
|
|
60
32
|
extra_rdoc_files: []
|
|
61
33
|
files:
|
|
34
|
+
- ".env.example"
|
|
35
|
+
- ".github/workflows/ruby.yml"
|
|
62
36
|
- ".gitignore"
|
|
63
|
-
- ".
|
|
37
|
+
- ".rspec"
|
|
38
|
+
- ".rubocop.yml"
|
|
64
39
|
- Gemfile
|
|
65
40
|
- Gemfile.lock
|
|
66
41
|
- LICENSE
|
|
@@ -68,8 +43,8 @@ files:
|
|
|
68
43
|
- Rakefile
|
|
69
44
|
- bin/console
|
|
70
45
|
- lib/vkdonate.rb
|
|
46
|
+
- lib/vkdonate/client.rb
|
|
71
47
|
- lib/vkdonate/donate.rb
|
|
72
|
-
- lib/vkdonate/version.rb
|
|
73
48
|
- vkdonate.gemspec
|
|
74
49
|
homepage: https://github.com/fizvlad/vkdonate-rb
|
|
75
50
|
licenses:
|
|
@@ -86,14 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
86
61
|
requirements:
|
|
87
62
|
- - ">="
|
|
88
63
|
- !ruby/object:Gem::Version
|
|
89
|
-
version:
|
|
64
|
+
version: 2.7.1
|
|
90
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
66
|
requirements:
|
|
92
67
|
- - ">="
|
|
93
68
|
- !ruby/object:Gem::Version
|
|
94
69
|
version: '0'
|
|
95
70
|
requirements: []
|
|
96
|
-
rubygems_version: 3.
|
|
71
|
+
rubygems_version: 3.1.2
|
|
97
72
|
signing_key:
|
|
98
73
|
specification_version: 4
|
|
99
74
|
summary: This is small non-official gem which provides interface to interact with
|
data/.travis.yml
DELETED