vkdonate 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +9 -0
- data/Rakefile +10 -0
- data/bin/console +7 -0
- data/lib/vkdonate/version.rb +7 -0
- data/lib/vkdonate.rb +216 -0
- data/vkdonate.gemspec +29 -0
- metadata +11 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7d590e413133110ae7c498dbcb5babc8787e9e02714faece8749fe656b6b9a6
|
4
|
+
data.tar.gz: 37d6cba556d5b89adf9c3350a6d9ed1fe60913adb43e3a548348268be6241055
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5cbdf8761845b8f913a1cfdad612984c25a807f4c7963ed518b061b299e714ffea0d8c580d70042b213bcc581d70d0b1a729ce55c60bce3498bd9b7ffc3121f
|
7
|
+
data.tar.gz: b93c736343ce86fecb6062ddc1c631f061f396c9937cbcd4c5d148258c56bfaa2ad5599d4bcd52259ee6a1da026fc9d0709add3a4bfa48d6c5c160ea12347f37
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
vkdonate (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
json (2.2.0)
|
10
|
+
minitest (5.11.3)
|
11
|
+
rake (12.3.3)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
x64-mingw32
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
bundler (~> 2.0)
|
18
|
+
json (~> 2.2)
|
19
|
+
minitest (~> 5.0)
|
20
|
+
rake (~> 12.0)
|
21
|
+
vkdonate!
|
22
|
+
|
23
|
+
BUNDLED WITH
|
24
|
+
2.0.2
|
data/LICENSE
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Kuznecov Vladislav
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/lib/vkdonate.rb
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
require "vkdonate/version"
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
5
|
+
require "date"
|
6
|
+
|
7
|
+
##
|
8
|
+
# Main module.
|
9
|
+
module Vkdonate
|
10
|
+
|
11
|
+
##
|
12
|
+
# URI for requests.
|
13
|
+
REQUEST_URI = URI("https://api.vkdonate.ru")
|
14
|
+
|
15
|
+
##
|
16
|
+
# Array of available actions.
|
17
|
+
ACTIONS = [:donates]
|
18
|
+
|
19
|
+
##
|
20
|
+
# Array of available sort-by.
|
21
|
+
SORT = [:date, :sum]
|
22
|
+
|
23
|
+
##
|
24
|
+
# Array of available order-by.
|
25
|
+
ORDER = [:asc, :desc]
|
26
|
+
|
27
|
+
##
|
28
|
+
# Time offset of API server.
|
29
|
+
TIME_OFFSET = "UTC+3"
|
30
|
+
|
31
|
+
##
|
32
|
+
# @!macro [new] request_option
|
33
|
+
# @option options [Integer] count (10) amount of donates (up to 50).
|
34
|
+
# @option options [Integer] offset (0) donates offset.
|
35
|
+
# @option options [Symbol] sort (:date) sort by.
|
36
|
+
# @option options [Symbol] order (:desc) order by.
|
37
|
+
# @see Vkdonate::SORT
|
38
|
+
# @see Vkdonate::ORDER
|
39
|
+
#
|
40
|
+
# @!macro [new] request_return
|
41
|
+
# @return [Array]
|
42
|
+
#
|
43
|
+
# @!macro [new] request
|
44
|
+
# Simple POST request to API.
|
45
|
+
# @param action [Symbol]
|
46
|
+
# @param options [Hash]
|
47
|
+
# @!macro request_option
|
48
|
+
# @see Vkdonate::ACTIONS
|
49
|
+
# @!macro request_return
|
50
|
+
#
|
51
|
+
# @!macro [new] donates
|
52
|
+
# POST request for +donates+ action.
|
53
|
+
# @param options [Hash]
|
54
|
+
# @!macro request_option
|
55
|
+
# @see Vkdonate::ACTIONS
|
56
|
+
# @!macro request_return
|
57
|
+
|
58
|
+
##
|
59
|
+
# @param api_key [String]
|
60
|
+
# @!macro request
|
61
|
+
def self.request(api_key, action, options = {})
|
62
|
+
raise "Unknown action" unless ACTIONS.include? action
|
63
|
+
|
64
|
+
count = options[:count] || 10
|
65
|
+
offset = options[:offset] || 0
|
66
|
+
sort = options[:sort] || :date
|
67
|
+
order = options[:order] || :desc
|
68
|
+
|
69
|
+
raise "Count is out of range" unless count >= 1 && count <= 50
|
70
|
+
raise "Offset is out of range" unless offset >= 0
|
71
|
+
raise "Unknown sorting" unless SORT.include? sort
|
72
|
+
raise "Unknown ordering" unless ORDER.include? order
|
73
|
+
|
74
|
+
res = Net::HTTP.post_form(REQUEST_URI,
|
75
|
+
key: api_key.to_s,
|
76
|
+
action: action.to_s,
|
77
|
+
count: count.to_i,
|
78
|
+
offset: offset.to_i,
|
79
|
+
sort: sort.to_s,
|
80
|
+
order: order.to_s
|
81
|
+
)
|
82
|
+
|
83
|
+
json = JSON.parse res.body
|
84
|
+
|
85
|
+
if json["success"]
|
86
|
+
json["donates"].map { |e| Donate.from_json(e) }
|
87
|
+
else
|
88
|
+
raise json["text"]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# @param api_key [String]
|
94
|
+
# @!macro donates
|
95
|
+
def self.donates(api_key, options = {})
|
96
|
+
request(api_key, :donates, options)
|
97
|
+
end
|
98
|
+
|
99
|
+
##
|
100
|
+
# Single donation
|
101
|
+
class Donate
|
102
|
+
|
103
|
+
##
|
104
|
+
# @return [Integer] Unique payment ID.
|
105
|
+
attr_reader :id
|
106
|
+
|
107
|
+
##
|
108
|
+
# @return [Integer] Donator VK ID.
|
109
|
+
attr_reader :uid
|
110
|
+
|
111
|
+
##
|
112
|
+
# @return [DateTime] Date and time of donation.
|
113
|
+
attr_reader :date
|
114
|
+
|
115
|
+
##
|
116
|
+
# @return [Integer] Size of donation.
|
117
|
+
attr_reader :sum
|
118
|
+
|
119
|
+
##
|
120
|
+
# @return [String, nil] User message or +nil+ if empty.
|
121
|
+
attr_reader :msg
|
122
|
+
alias_method :message, :msg
|
123
|
+
|
124
|
+
##
|
125
|
+
# @return [Boolean] Whether donation is anonymous.
|
126
|
+
attr_reader :anon
|
127
|
+
alias_method :anon?, :anon
|
128
|
+
|
129
|
+
##
|
130
|
+
# @return [Boolean] Whether donate is visible in group.
|
131
|
+
attr_reader :visible
|
132
|
+
alias_method :visible?, :visible
|
133
|
+
|
134
|
+
##
|
135
|
+
# @return [String] Human readable information.
|
136
|
+
def to_s
|
137
|
+
"Donation ##{id} by @#{uid} for #{sum}RUR (at #{date})"
|
138
|
+
end
|
139
|
+
|
140
|
+
##
|
141
|
+
# Save data about donation.
|
142
|
+
#
|
143
|
+
# @param options [Hash]
|
144
|
+
#
|
145
|
+
# @option options [Integer] id
|
146
|
+
# @option options [Integer] uid
|
147
|
+
# @option options [DateTime] date
|
148
|
+
# @option options [Integer] sum
|
149
|
+
# @option options [String, nil] msg
|
150
|
+
# @option options [Boolean] anon
|
151
|
+
# @option options [Boolean] visible
|
152
|
+
def initialize(options)
|
153
|
+
@id = options[:id].to_i
|
154
|
+
|
155
|
+
@uid = options[:uid].to_i
|
156
|
+
|
157
|
+
@date = options[:date]
|
158
|
+
raise unless DateTime === @date
|
159
|
+
|
160
|
+
@sum = options[:sum].to_i
|
161
|
+
|
162
|
+
@msg = options[:msg].to_s
|
163
|
+
@msg = nil if @msg.empty?
|
164
|
+
|
165
|
+
@anon = !!options[:anon]
|
166
|
+
|
167
|
+
@visible = !!options[:visible]
|
168
|
+
end
|
169
|
+
|
170
|
+
##
|
171
|
+
# Parse from JSON hash.
|
172
|
+
#
|
173
|
+
# @param hash [Hash] parsed JSON hash.
|
174
|
+
#
|
175
|
+
# @return [Donate]
|
176
|
+
def self.from_json(hash)
|
177
|
+
self.new(
|
178
|
+
id: hash["id"].to_i,
|
179
|
+
uid: hash["uid"].to_i,
|
180
|
+
date: DateTime.parse(hash["date"] + " #{TIME_OFFSET}"),
|
181
|
+
sum: hash["sum"].to_i,
|
182
|
+
msg: hash["msg"].empty? ? nil : hash["msg"],
|
183
|
+
anon: !hash["anon"].to_i.zero?,
|
184
|
+
visible: !hash["visible"].to_i.zero?
|
185
|
+
)
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
##
|
191
|
+
# Client which saves API key.
|
192
|
+
class Client
|
193
|
+
|
194
|
+
##
|
195
|
+
# New client to work with API.
|
196
|
+
#
|
197
|
+
# @param api_key [String]
|
198
|
+
def initialize(api_key)
|
199
|
+
@api_key = api_key
|
200
|
+
end
|
201
|
+
|
202
|
+
##
|
203
|
+
# @!macro request
|
204
|
+
def request(action, options = {})
|
205
|
+
Vkdonate.request(@api_key, action, options)
|
206
|
+
end
|
207
|
+
|
208
|
+
##
|
209
|
+
# @!macro donates
|
210
|
+
def donates(options = {})
|
211
|
+
Vkdonate.donates(@api_key, options)
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
data/vkdonate.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "vkdonate/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "vkdonate"
|
7
|
+
spec.version = Vkdonate::VERSION
|
8
|
+
spec.authors = ["Fizvlad"]
|
9
|
+
spec.email = ["fizvlad@mail.ru"]
|
10
|
+
|
11
|
+
spec.summary = "This is small non-official gem which provides interface to interact with vkdonate.ru API"
|
12
|
+
spec.homepage = "https://github.com/fizvlad/vkdonate-rb"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/fizvlad/vkdonate-rb"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/fizvlad/vkdonate-rb/releases"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
27
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
28
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vkdonate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fizvlad
|
@@ -59,7 +59,17 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE
|
62
67
|
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- lib/vkdonate.rb
|
71
|
+
- lib/vkdonate/version.rb
|
72
|
+
- vkdonate.gemspec
|
63
73
|
homepage: https://github.com/fizvlad/vkdonate-rb
|
64
74
|
licenses:
|
65
75
|
- MIT
|