pushover 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,16 @@
1
1
  module Pushover
2
- # Receipt class
3
- class Receipt
2
+ # Receipt is a struct to interface with the receipt endpoint.
3
+ # @!attribute [rw] receipt
4
+ # @return [String] id of the receipt to request
5
+ # @!attribute [rw] token
6
+ # @return [String] application token to check for a receipt
7
+ Receipt = Struct.new(:receipt, :token, keyword_init: true) do
8
+ # Call pushover and return a response.
9
+ # @return [Response] response for the receipt request
10
+ def get
11
+ %i[receipt token].each { |param| raise "#{param} must be supplied" unless send param }
12
+
13
+ Response.create_from_excon_response Excon.get(path: "1/receipts/#{receipt}.json", query: { token: token })
14
+ end
4
15
  end
5
16
  end
@@ -1,40 +1,46 @@
1
1
  module Pushover
2
- class Response
3
- include Creatable
2
+ # Response encapsulates the response back from pushover.
3
+ # Class to wrap the user and basic functions related to it.
4
+ # @attribute status
5
+ # @return [Numeric] status of the response
6
+ # @attribute request
7
+ # @return [String] request is a UUID representing the specific call
8
+ # @attribute errors
9
+ # @return [Array] errors includes any errors made
10
+ # @attribute receipt
11
+ # @return [String] receipt returns a receipt if requested
12
+ # @attribute headers
13
+ # @return [Hash] headers is the headers returned from the call.
14
+ # @attribute attributes
15
+ # @return [String] any extra k/v pairs from the server.
16
+ Response = Struct.new(:status, :request, :errors, :receipt, :headers, :attributes, keyword_init: true) do
17
+ # New response object, from an excon_response
18
+ # @return [Response] populated response object
19
+ def self.create_from_excon_response(excon_response)
20
+ json = Oj.load excon_response[:body]
21
+ values = {}
22
+ attributes = {}
23
+ json.each { |k, v| members.include?(k.to_sym) ? values.store(k, v) : attributes.store(k, v) }
4
24
 
5
- attribute name: 'user', kind_of: String
6
- attribute name: 'errors', kind_of: Array
7
- attribute name: 'status', kind_of: Numeric
8
- attribute name: 'receipt', kind_of: String
9
- attribute name: 'request', kind_of: String
10
- attribute name: 'original', kind_of: String
11
- attribute name: 'limit', kind_of: String
12
- attribute name: 'remaining', kind_of: String
13
- attribute name: 'reset', kind_of: String
14
-
15
- def initialize
16
- @status = 0
17
- @errors = []
25
+ Response.new values.merge(headers: excon_response.headers, attributes: attributes)
18
26
  end
19
27
 
20
- def process
21
- process_body
22
- process_headers
28
+ # purty.
29
+ def to_s
30
+ "#{errors ? 'errors: ' + errors.join("\n") : 'status: ok'}, #{limits}"
23
31
  end
24
32
 
25
- def process_body
26
- body = Oj.load original[:body]
33
+ private
27
34
 
28
- @status = body["status"]
29
- @request = body["request"]
30
- @receipt = body["receipt"] if body["receipt"]
31
- @errors = body["errors"] if body["errors"]
32
- end
35
+ # :nocov:
36
+ # Application limits
37
+ # @return [Array] 0: Remaining Calls, 1: Total Limit, 2: Limit Reset
38
+ def limits
39
+ return '' unless headers.include? 'X-Limit-App-Limit'
33
40
 
34
- def process_headers
35
- @limit = original.headers['X-Limit-App-Limit']
36
- @remaining = original.headers['X-Limit-App-Remaining']
37
- @reset = original.headers['X-Limit-App-Reset']
41
+ output = [headers['X-Limit-App-Remaining'], headers['X-Limit-App-Limit'], headers['X-Limit-App-Reset']]
42
+ output.define_singleton_method(:to_s) { "requests #{self[0]} of #{self[1]}, reset on #{Time.at(self[2].to_f)}" }
43
+ output
38
44
  end
39
45
  end
40
46
  end
@@ -1,4 +1,3 @@
1
1
  module Pushover
2
- # The current version of Pushover.
3
- VERSION = "2.0.0".freeze
2
+ VERSION = "3.0.0".freeze # The current version of Pushover.
4
3
  end
data/pushover.gemspec CHANGED
@@ -19,28 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
21
21
 
22
- # documentation
23
- spec.extra_rdoc_files = Dir.glob('*.md')
24
- spec.rdoc_options = ['--line-numbers', '--inline-source', '--title', 'Pushover', '--main', 'README.md', '--encoding=UTF-8']
25
- spec.has_rdoc = 'yard'
26
-
27
22
  # dependencies.
28
- spec.add_runtime_dependency 'creatable'
29
23
  spec.add_runtime_dependency 'excon'
24
+ spec.add_runtime_dependency 'gli'
30
25
  spec.add_runtime_dependency 'oj'
31
-
32
- spec.add_development_dependency 'bundler'
33
- spec.add_development_dependency 'guard'
34
- spec.add_development_dependency 'guard-bundler'
35
- spec.add_development_dependency 'guard-rspec'
36
- spec.add_development_dependency 'guard-rubocop'
37
- spec.add_development_dependency 'guard-yard'
38
- spec.add_development_dependency 'pry'
39
- spec.add_development_dependency 'rake'
40
- spec.add_development_dependency 'rspec'
41
- spec.add_development_dependency 'rubocop'
42
- spec.add_development_dependency 'rubocop-rspec'
43
- spec.add_development_dependency 'simplecov'
44
- spec.add_development_dependency 'simplecov-console'
45
- spec.add_development_dependency 'yard'
46
26
  end
@@ -1,4 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Pushover do
4
+ it "is expected to have a VERSION" do
5
+ expect(Pushover::VERSION).not_to be_nil
6
+ end
4
7
  end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pushover::Message do
4
+ it { is_expected.to have_attributes(token: a_kind_of(String).or(be_nil)) }
5
+ it { is_expected.to have_attributes(user: a_kind_of(String).or(be_nil)) }
6
+ it { is_expected.to have_attributes(message: a_kind_of(String).or(be_nil)) }
7
+ it { is_expected.to have_attributes(attachment: a_kind_of(String).or(be_nil)) }
8
+ it { is_expected.to have_attributes(device: a_kind_of(String).or(be_nil)) }
9
+ it { is_expected.to have_attributes(title: a_kind_of(String).or(be_nil)) }
10
+ it { is_expected.to have_attributes(url: a_kind_of(String).or(be_nil)) }
11
+ it { is_expected.to have_attributes(url_title: a_kind_of(String).or(be_nil)) }
12
+ it { is_expected.to have_attributes(priority: a_kind_of(Numeric).or(be_nil)) }
13
+ it { is_expected.to have_attributes(sound: a_kind_of(String).or(be_nil)) }
14
+ it { is_expected.to have_attributes(timestamp: a_kind_of(DateTime).or(be_nil)) }
15
+ it { is_expected.to have_attributes(expire: a_kind_of(Numeric).or(be_nil)) }
16
+ it { is_expected.to have_attributes(retry: a_kind_of(Numeric).or(be_nil)) }
17
+ it { is_expected.to have_attributes(callback: a_kind_of(String).or(be_nil)) }
18
+
19
+ it { is_expected.to respond_to(:push).with(0).argument }
20
+
21
+ describe "#push" do
22
+ let(:params) { { 'token' => 't', 'user' => 'u', 'message' => 'message' } }
23
+
24
+ it "is expected to send" do
25
+ expect { described_class.new(params).push }.to raise_error Excon::Error::StubNotFound
26
+ end
27
+
28
+ ['token', 'user', 'message'].each do |param|
29
+ context "when #{param} is not supplied" do
30
+ before { params.delete param }
31
+
32
+ it { expect { described_class.new(params).push }.to raise_error RuntimeError, /#{param} must be supplied/ }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pushover::Receipt do
4
+ it { is_expected.to have_attributes(receipt: a_kind_of(String).or(be_nil)) }
5
+ it { is_expected.to have_attributes(token: a_kind_of(String).or(be_nil)) }
6
+
7
+ it { is_expected.to respond_to(:get).with(0).argument }
8
+
9
+ describe "#push" do
10
+ let(:params) { { 'token' => 't', 'receipt' => 'receipt' } }
11
+
12
+ it "is expected to send" do
13
+ expect { described_class.new(params).get }.to raise_error Excon::Error::StubNotFound
14
+ end
15
+
16
+ ['token', 'receipt'].each do |param|
17
+ context "when #{param} is not supplied" do
18
+ before { params.delete param }
19
+
20
+ it { expect { described_class.new(params).get }.to raise_error RuntimeError, /#{param} must be supplied/ }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pushover do
4
+ describe Pushover::Response do
5
+ let(:excon_response) { Excon::Response.new body: '{}', headers: {} }
6
+
7
+ it { is_expected.to have_attributes(status: a_kind_of(String).or(be_nil)) }
8
+ it { is_expected.to have_attributes(request: a_kind_of(String).or(be_nil)) }
9
+ it { is_expected.to have_attributes(errors: a_kind_of(Array).or(be_nil)) }
10
+ it { is_expected.to have_attributes(receipt: a_kind_of(String).or(be_nil)) }
11
+ it { is_expected.to have_attributes(headers: a_kind_of(Hash).or(be_nil)) }
12
+ it { is_expected.to have_attributes(attributes: a_kind_of(Hash).or(be_nil)) }
13
+
14
+ it { expect(described_class).to respond_to(:create_from_excon_response).with(1).argument }
15
+
16
+ describe "#to_s" do
17
+ it "is expected to be purty." do
18
+ expect(Pushover::Response.create_from_excon_response(excon_response).to_s).to include('status')
19
+ end
20
+ end
21
+
22
+ describe "::create_from_excon_response" do
23
+ it { expect(Pushover::Response.create_from_excon_response(excon_response)).to be_a_kind_of described_class }
24
+ end
25
+ end
26
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,22 +1,17 @@
1
1
  require 'excon'
2
- require 'pry'
3
2
  require 'simplecov'
4
- require 'simplecov-console'
5
-
3
+ require 'codecov'
6
4
  Excon.defaults[:mock] = true
7
5
 
8
- SimpleCov.formatters = [
9
- SimpleCov::Formatter::HTMLFormatter
10
- ]
11
-
12
6
  RSpec.configure do |config|
13
7
  config.filter_run :focus
14
8
  config.run_all_when_everything_filtered = true
15
9
  config.example_status_persistence_file_path = "tmp/examples.txt"
16
10
  end
17
11
 
18
- SimpleCov.start do
19
- add_filter "/spec/"
20
- end
12
+ RSpec::Matchers.alias_matcher :return_a_kind_of, :be_a_kind_of
13
+
14
+ SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::Codecov]
15
+ SimpleCov.start { add_filter "/spec/" }
21
16
 
22
17
  require 'pushover'
@@ -0,0 +1,31 @@
1
+ class VsCodeFormatter
2
+ RSpec::Core::Formatters.register self, :message, :dump_summary, :dump_failures, :dump_pending, :seed
3
+
4
+ def initialize(output)
5
+ @output = output
6
+ end
7
+
8
+ def message(notification)
9
+ @output << notification.message
10
+ end
11
+
12
+ def dump_failures(notification)
13
+ return if notification.failure_notifications.empty?
14
+
15
+ notification.failed_examples.each { |e| @output << "error: #{e.full_description} @ #{e.location}" << "\n" }
16
+ end
17
+
18
+ def dump_summary(summary); end
19
+
20
+ def dump_pending(notification)
21
+ return if notification.pending_examples.empty?
22
+
23
+ notification.pending_examples.each { |e| @output << "warning: #{e.full_description} @ #{e.location}" << "\n" }
24
+ end
25
+
26
+ def seed(notification)
27
+ return unless notification.seed_used?
28
+
29
+ @output << notification.fully_formatted
30
+ end
31
+ end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushover
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Brodeur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-08 00:00:00.000000000 Z
11
+ date: 2019-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: creatable
14
+ name: excon
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: excon
28
+ name: gli
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -52,249 +52,45 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: guard-bundler
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: guard-rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: guard-rubocop
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: guard-yard
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: pry
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: rake
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: rspec
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: rubocop
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: rubocop-rspec
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0'
209
- - !ruby/object:Gem::Dependency
210
- name: simplecov
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - ">="
214
- - !ruby/object:Gem::Version
215
- version: '0'
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - ">="
221
- - !ruby/object:Gem::Version
222
- version: '0'
223
- - !ruby/object:Gem::Dependency
224
- name: simplecov-console
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - ">="
228
- - !ruby/object:Gem::Version
229
- version: '0'
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - ">="
235
- - !ruby/object:Gem::Version
236
- version: '0'
237
- - !ruby/object:Gem::Dependency
238
- name: yard
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - ">="
242
- - !ruby/object:Gem::Version
243
- version: '0'
244
- type: :development
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - ">="
249
- - !ruby/object:Gem::Version
250
- version: '0'
251
55
  description: Api (and CLI) to interface with pushover.net
252
56
  email:
253
57
  - ebrodeur@ujami.net
254
58
  executables:
255
- - pushover
59
+ - add
256
60
  extensions: []
257
- extra_rdoc_files:
258
- - CODE_OF_CONDUCT.md
259
- - README.md
61
+ extra_rdoc_files: []
260
62
  files:
63
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
64
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
261
65
  - ".gitignore"
262
66
  - ".rubocop.yml"
67
+ - ".travis.yml"
263
68
  - CODE_OF_CONDUCT.md
264
69
  - Gemfile
265
70
  - Guardfile
266
71
  - LICENSE
267
72
  - README.md
268
73
  - Rakefile
269
- - bin/pushover
74
+ - bin/add
75
+ - exe/pushover
270
76
  - lib/pushover.rb
271
- - lib/pushover/api.rb
272
77
  - lib/pushover/message.rb
273
78
  - lib/pushover/receipt.rb
274
- - lib/pushover/request.rb
275
79
  - lib/pushover/response.rb
276
80
  - lib/pushover/version.rb
277
81
  - pushover.gemspec
278
- - spec/lib/pushover/api_spec.rb
279
- - spec/lib/pushover/message_spec.rb
280
- - spec/lib/pushover/receipt_spec.rb
281
- - spec/lib/pushover/request_spec.rb
282
- - spec/lib/pushover/response_spec.rb
283
82
  - spec/lib/pushover_spec.rb
83
+ - spec/pushover/message_spec.rb
84
+ - spec/pushover/receipt_spec.rb
85
+ - spec/pushover/response_spec.rb
284
86
  - spec/spec_helper.rb
87
+ - spec/vscode_formatter.rb
285
88
  homepage: https://github.com/erniebrodeur/pushover
286
89
  licenses:
287
90
  - MIT
288
91
  metadata: {}
289
92
  post_install_message:
290
- rdoc_options:
291
- - "--line-numbers"
292
- - "--inline-source"
293
- - "--title"
294
- - Pushover
295
- - "--main"
296
- - README.md
297
- - "--encoding=UTF-8"
93
+ rdoc_options: []
298
94
  require_paths:
299
95
  - lib
300
96
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -308,16 +104,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
104
  - !ruby/object:Gem::Version
309
105
  version: '0'
310
106
  requirements: []
311
- rubyforge_project:
312
- rubygems_version: 2.6.11
107
+ rubygems_version: 3.0.3
313
108
  signing_key:
314
109
  specification_version: 4
315
110
  summary: This spec provides both an API and CLI interface to pushover.net.
316
111
  test_files:
317
- - spec/lib/pushover/api_spec.rb
318
- - spec/lib/pushover/message_spec.rb
319
- - spec/lib/pushover/receipt_spec.rb
320
- - spec/lib/pushover/request_spec.rb
321
- - spec/lib/pushover/response_spec.rb
322
112
  - spec/lib/pushover_spec.rb
113
+ - spec/pushover/message_spec.rb
114
+ - spec/pushover/receipt_spec.rb
115
+ - spec/pushover/response_spec.rb
323
116
  - spec/spec_helper.rb
117
+ - spec/vscode_formatter.rb