vkdonate 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7d590e413133110ae7c498dbcb5babc8787e9e02714faece8749fe656b6b9a6
4
- data.tar.gz: 37d6cba556d5b89adf9c3350a6d9ed1fe60913adb43e3a548348268be6241055
3
+ metadata.gz: aef0225bab369599e43474b1164d5d0560286e217e36223b28001c497e3a1be6
4
+ data.tar.gz: ed0165051595e9d2b4ef0fd40717410a5bbfc8eb16c864797d55713805596cbc
5
5
  SHA512:
6
- metadata.gz: e5cbdf8761845b8f913a1cfdad612984c25a807f4c7963ed518b061b299e714ffea0d8c580d70042b213bcc581d70d0b1a729ce55c60bce3498bd9b7ffc3121f
7
- data.tar.gz: b93c736343ce86fecb6062ddc1c631f061f396c9937cbcd4c5d148258c56bfaa2ad5599d4bcd52259ee6a1da026fc9d0709add3a4bfa48d6c5c160ea12347f37
6
+ metadata.gz: 7fa8c5c596bf40421b0c4a198cdd66c842bc99b4280c925e9d5b485e8264df1104adea0d513151ef7b0d00a435893e56f808b48b67f0f9bcc4f591db4571991a
7
+ data.tar.gz: f369642650d2bf76fc2ab76add329412e6fbfcc2afd3767c18dd9cccb775ce57db7d5daf94752a1b999ad09d74c84f5fd6d247a36723bee272c8cdb6a9d3d915
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vkdonate (1.0.0)
4
+ vkdonate (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -25,7 +25,7 @@ You can check documentation [here](https://www.rubydoc.info/gems/vkdonate/).
25
25
  To interact with API you are to initialize client firstly:
26
26
 
27
27
  ```ruby
28
- client = Vkdonate::Client("API KEY GOES HERE")
28
+ client = Vkdonate::Client.new("API KEY GOES HERE")
29
29
  ```
30
30
 
31
31
  After that you can call method `Client#donates` which returnes array of `Donate` objects:
@@ -0,0 +1,94 @@
1
+ module Vkdonate
2
+
3
+ ##
4
+ # Single donation
5
+ class Donate
6
+
7
+ ##
8
+ # @return [Integer] Unique payment ID.
9
+ attr_reader :id
10
+
11
+ ##
12
+ # @return [Integer] Donator VK ID.
13
+ attr_reader :uid
14
+
15
+ ##
16
+ # @return [DateTime] Date and time of donation.
17
+ attr_reader :date
18
+
19
+ ##
20
+ # @return [Integer] Size of donation.
21
+ attr_reader :sum
22
+
23
+ ##
24
+ # @return [String, nil] User message or +nil+ if empty.
25
+ attr_reader :msg
26
+ alias_method :message, :msg
27
+
28
+ ##
29
+ # @return [Boolean] Whether donation is anonymous.
30
+ attr_reader :anon
31
+ alias_method :anon?, :anon
32
+
33
+ ##
34
+ # @return [Boolean] Whether donate is visible in group.
35
+ attr_reader :visible
36
+ alias_method :visible?, :visible
37
+
38
+ ##
39
+ # @return [String] Human readable information.
40
+ def to_s
41
+ "Donation ##{id} by @#{uid} for #{sum}RUR (at #{date})"
42
+ end
43
+
44
+ ##
45
+ # Save data about donation.
46
+ #
47
+ # @param options [Hash]
48
+ #
49
+ # @option options [Integer] id
50
+ # @option options [Integer] uid
51
+ # @option options [DateTime] date
52
+ # @option options [Integer] sum
53
+ # @option options [String, nil] msg
54
+ # @option options [Boolean] anon
55
+ # @option options [Boolean] visible
56
+ def initialize(options)
57
+ @id = options[:id].to_i
58
+
59
+ @uid = options[:uid].to_i
60
+
61
+ @date = options[:date]
62
+ raise unless DateTime === @date
63
+
64
+ @sum = options[:sum].to_i
65
+
66
+ @msg = options[:msg].to_s
67
+ @msg = nil if @msg.empty?
68
+
69
+ @anon = !!options[:anon]
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
@@ -2,6 +2,6 @@ module Vkdonate
2
2
 
3
3
  ##
4
4
  # Gem version.
5
- VERSION = "1.0.1"
5
+ VERSION = "1.0.2"
6
6
 
7
7
  end
data/lib/vkdonate.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "vkdonate/version"
2
+ require "vkdonate/donate"
2
3
 
3
4
  require "net/http"
4
5
  require "json"
@@ -28,6 +29,10 @@ module Vkdonate
28
29
  # Time offset of API server.
29
30
  TIME_OFFSET = "UTC+3"
30
31
 
32
+ ##
33
+ # Requests timeout in seconds
34
+ REQUEST_TIMEOUT = 10
35
+
31
36
  ##
32
37
  # @!macro [new] request_option
33
38
  # @option options [Integer] count (10) amount of donates (up to 50).
@@ -96,97 +101,6 @@ module Vkdonate
96
101
  request(api_key, :donates, options)
97
102
  end
98
103
 
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
104
  ##
191
105
  # Client which saves API key.
192
106
  class Client
@@ -196,7 +110,8 @@ module Vkdonate
196
110
  #
197
111
  # @param api_key [String]
198
112
  def initialize(api_key)
199
- @api_key = api_key
113
+ @api_key = api_key.to_s
114
+ raise "API key can not be empty" if @api_key.empty?
200
115
  end
201
116
 
202
117
  ##
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.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fizvlad
@@ -68,6 +68,7 @@ files:
68
68
  - Rakefile
69
69
  - bin/console
70
70
  - lib/vkdonate.rb
71
+ - lib/vkdonate/donate.rb
71
72
  - lib/vkdonate/version.rb
72
73
  - vkdonate.gemspec
73
74
  homepage: https://github.com/fizvlad/vkdonate-rb