pushover 2.0.0 → 3.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.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- data/.rubocop.yml +3 -1
- data/.travis.yml +8 -0
- data/Gemfile +28 -1
- data/Guardfile +5 -0
- data/README.md +43 -28
- data/Rakefile +60 -3
- data/bin/add +25 -0
- data/exe/pushover +37 -0
- data/lib/pushover.rb +6 -4
- data/lib/pushover/message.rb +32 -32
- data/lib/pushover/receipt.rb +13 -2
- data/lib/pushover/response.rb +35 -29
- data/lib/pushover/version.rb +1 -2
- data/pushover.gemspec +1 -21
- data/spec/lib/pushover_spec.rb +3 -0
- data/spec/pushover/message_spec.rb +36 -0
- data/spec/pushover/receipt_spec.rb +24 -0
- data/spec/pushover/response_spec.rb +26 -0
- data/spec/spec_helper.rb +5 -10
- data/spec/vscode_formatter.rb +31 -0
- metadata +21 -227
- data/bin/pushover +0 -0
- data/lib/pushover/api.rb +0 -35
- data/lib/pushover/request.rb +0 -12
- data/spec/lib/pushover/api_spec.rb +0 -41
- data/spec/lib/pushover/message_spec.rb +0 -81
- data/spec/lib/pushover/receipt_spec.rb +0 -6
- data/spec/lib/pushover/request_spec.rb +0 -60
- data/spec/lib/pushover/response_spec.rb +0 -98
    
        data/bin/pushover
    DELETED
    
    | 
            File without changes
         | 
    
        data/lib/pushover/api.rb
    DELETED
    
    | @@ -1,35 +0,0 @@ | |
| 1 | 
            -
            require 'creatable'
         | 
| 2 | 
            -
            require 'excon'
         | 
| 3 | 
            -
            require 'oj'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            require 'pushover/response'
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            module Pushover
         | 
| 8 | 
            -
              # Api module
         | 
| 9 | 
            -
              module Api
         | 
| 10 | 
            -
                module_function
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                def endpoints
         | 
| 13 | 
            -
                  %i[messages sounds limits receipts validate]
         | 
| 14 | 
            -
                end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                def sounds
         | 
| 17 | 
            -
                  %i[ pushover bike bugle cashregister classical cosmic falling gamelan incoming
         | 
| 18 | 
            -
                      intermission magic mechanical pianobar siren spacealarm tugboat alien
         | 
| 19 | 
            -
                      climb persistent echo updown none]
         | 
| 20 | 
            -
                end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                def connection
         | 
| 23 | 
            -
                  Excon.new url
         | 
| 24 | 
            -
                end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                def initialize
         | 
| 27 | 
            -
                  Excon.defaults[:headers]['Content-Type'] = 'application/json'
         | 
| 28 | 
            -
                  Excon.defaults[:headers]['User-Agent'] = "pushover (ruby gem) v#{Pushover::VERSION}"
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                def url
         | 
| 32 | 
            -
                  "https://api.pushover.net"
         | 
| 33 | 
            -
                end
         | 
| 34 | 
            -
              end
         | 
| 35 | 
            -
            end
         | 
    
        data/lib/pushover/request.rb
    DELETED
    
    | @@ -1,12 +0,0 @@ | |
| 1 | 
            -
            module Pushover
         | 
| 2 | 
            -
              class Request
         | 
| 3 | 
            -
                include Creatable
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                def push(endpoint, config = {})
         | 
| 6 | 
            -
                  excon_response = Api.connection.post path: "1/#{endpoint}.json", query: config
         | 
| 7 | 
            -
                  response = Response.create original: excon_response
         | 
| 8 | 
            -
                  response.process
         | 
| 9 | 
            -
                  @response = response
         | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
              end
         | 
| 12 | 
            -
            end
         | 
| @@ -1,41 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Pushover
         | 
| 4 | 
            -
              describe Api do
         | 
| 5 | 
            -
                it { expect(described_class).to respond_to(:endpoints).with(0).argument }
         | 
| 6 | 
            -
                it { expect(described_class).to respond_to(:connection).with(0).argument }
         | 
| 7 | 
            -
                it { expect(described_class).to respond_to(:url).with(0).argument }
         | 
| 8 | 
            -
                it { expect(described_class).to respond_to(:sounds).with(0).argument }
         | 
| 9 | 
            -
                it { expect(described_class).to respond_to(:initialize).with(0).argument }
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                describe '::initialize' do
         | 
| 12 | 
            -
                  before { described_class.initialize }
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                  it "is expected to set excon default Headers Content-Type to 'application/json'" do
         | 
| 15 | 
            -
                    expect(Excon.defaults[:headers]).to include('Content-Type' => 'application/json')
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  it "is expected to set excon default Headers User-Agent to 'pushover (ruby gem) v#{Pushover::VERSION}'" do
         | 
| 19 | 
            -
                    expect(Excon.defaults[:headers]).to include('User-Agent' => "pushover (ruby gem) v#{Pushover::VERSION}")
         | 
| 20 | 
            -
                  end
         | 
| 21 | 
            -
                end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                describe '::endpoints' do
         | 
| 24 | 
            -
                  it { expect(described_class.endpoints).to be_a_kind_of(Array) & include(a_kind_of(Symbol)) }
         | 
| 25 | 
            -
                end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                describe '::connection' do
         | 
| 28 | 
            -
                  it "is expected to return an excon connection" do
         | 
| 29 | 
            -
                    expect(described_class.connection).to be_a_kind_of Excon::Connection
         | 
| 30 | 
            -
                  end
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                describe '::sounds' do
         | 
| 34 | 
            -
                  it { expect(described_class.sounds).to be_a_kind_of(Array) & include(a_kind_of(Symbol)) }
         | 
| 35 | 
            -
                end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                describe '::url' do
         | 
| 38 | 
            -
                  it { expect(described_class.url).to eq 'https://api.pushover.net' }
         | 
| 39 | 
            -
                end
         | 
| 40 | 
            -
              end
         | 
| 41 | 
            -
            end
         | 
| @@ -1,81 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Pushover
         | 
| 4 | 
            -
              describe Message do
         | 
| 5 | 
            -
                describe "Attributes" do
         | 
| 6 | 
            -
                  it { is_expected.to have_attributes(attachment: nil) }
         | 
| 7 | 
            -
                  it { is_expected.to have_attributes(device: nil) }
         | 
| 8 | 
            -
                  it { is_expected.to have_attributes(html: nil) }
         | 
| 9 | 
            -
                  it { is_expected.to have_attributes(message: nil) }
         | 
| 10 | 
            -
                  it { is_expected.to have_attributes(priority: nil) }
         | 
| 11 | 
            -
                  it { is_expected.to have_attributes(response: nil) }
         | 
| 12 | 
            -
                  it { is_expected.to have_attributes(sound: nil) }
         | 
| 13 | 
            -
                  it { is_expected.to have_attributes(timestamp: a_kind_of(Numeric)) }
         | 
| 14 | 
            -
                  it { is_expected.to have_attributes(title: nil) }
         | 
| 15 | 
            -
                  it { is_expected.to have_attributes(token: nil) }
         | 
| 16 | 
            -
                  it { is_expected.to have_attributes(url_title: nil) }
         | 
| 17 | 
            -
                  it { is_expected.to have_attributes(url: nil) }
         | 
| 18 | 
            -
                  it { is_expected.to have_attributes(user: nil) }
         | 
| 19 | 
            -
                end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                it { expect(described_class).to be_a_kind_of(Class) }
         | 
| 22 | 
            -
                it { is_expected.to be_a_kind_of Creatable }
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                describe "Instance Signatures" do
         | 
| 25 | 
            -
                  it { is_expected.to respond_to(:push).with(0).argument }
         | 
| 26 | 
            -
                end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                describe "::push" do
         | 
| 29 | 
            -
                  let(:body) { { "status": 1, "request": "647d2300-702c-4b38-8b2f-d56326ae460b" } }
         | 
| 30 | 
            -
                  let(:excon_connection) { Excon.new Api.url }
         | 
| 31 | 
            -
                  let(:excon_response) { Excon::Response.new(body: Oj.dump(body), status: 200) }
         | 
| 32 | 
            -
                  let(:params) { { user: '1234', token: '1234', message: 'abcd' } }
         | 
| 33 | 
            -
                  let(:request) { Request.create }
         | 
| 34 | 
            -
                  let(:response) { Response.create original: excon_response }
         | 
| 35 | 
            -
                  let(:working_message) { described_class.create params }
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                  before do
         | 
| 38 | 
            -
                    allow(Api).to receive(:connection).and_return excon_connection
         | 
| 39 | 
            -
                    allow(excon_connection).to receive(:post).and_return excon_response
         | 
| 40 | 
            -
                    allow(Response).to receive(:create).and_return response
         | 
| 41 | 
            -
                  end
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                  shared_examples 'required_param' do |param|
         | 
| 44 | 
            -
                    context "when #{param} is not set" do
         | 
| 45 | 
            -
                      before { working_message.instance_variable_set "@#{param}".to_sym, nil }
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                      it { expect { working_message.push }.to raise_error ArgumentError, /#{param} is a required parameter/ }
         | 
| 48 | 
            -
                    end
         | 
| 49 | 
            -
                  end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                  shared_examples 'extra_param' do |param|
         | 
| 52 | 
            -
                    context "when a #{param} is provided" do
         | 
| 53 | 
            -
                      before { working_message.instance_variable_set "@#{param}".to_sym, 'not_nil' }
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                      it "is expected to add the #{param} to the query" do
         | 
| 56 | 
            -
                        working_message.push
         | 
| 57 | 
            -
                        expect(excon_connection).to have_received(:post).with(query: a_hash_including(param.to_s => 'not_nil'), path: '1/messages.json')
         | 
| 58 | 
            -
                      end
         | 
| 59 | 
            -
                    end
         | 
| 60 | 
            -
                  end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                  %i[message token user].each do |param|
         | 
| 63 | 
            -
                    include_examples 'required_param', param
         | 
| 64 | 
            -
                  end
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                  %i[attachment device html priority sound title url_title url].each do |param|
         | 
| 67 | 
            -
                    include_examples 'extra_param', param
         | 
| 68 | 
            -
                  end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
                  it "is expected to call Request.create with ..." do
         | 
| 71 | 
            -
                    allow(Request).to receive(:create).and_return(request)
         | 
| 72 | 
            -
                    working_message.push
         | 
| 73 | 
            -
                    expect(Request).to have_received(:create).with(no_args)
         | 
| 74 | 
            -
                  end
         | 
| 75 | 
            -
             | 
| 76 | 
            -
                  it "is expected to return response" do
         | 
| 77 | 
            -
                    expect(working_message.push).to eq response
         | 
| 78 | 
            -
                  end
         | 
| 79 | 
            -
                end
         | 
| 80 | 
            -
              end
         | 
| 81 | 
            -
            end
         | 
| @@ -1,60 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Pushover
         | 
| 4 | 
            -
              describe Request do
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                let(:endpoint) { :messages }
         | 
| 7 | 
            -
                let(:excon_connection) { Excon.new Api.url }
         | 
| 8 | 
            -
                let(:params) { { user: '1234', token: '1234', message: 'abcd' } }
         | 
| 9 | 
            -
                let(:request) { described_class.create }
         | 
| 10 | 
            -
                let(:excon_response) { Excon::Response.new(body: Oj.dump(body), status: 200, headers: headers) }
         | 
| 11 | 
            -
                let(:body) { { "status" => 1, "request" => "647d2300-702c-4b38-8b2f-d56326ae460b" } }
         | 
| 12 | 
            -
                let(:request) { Request.new }
         | 
| 13 | 
            -
                let(:response) { Response.create original: excon_response }
         | 
| 14 | 
            -
                let(:headers) do
         | 
| 15 | 
            -
                  {
         | 
| 16 | 
            -
                    "X-Limit-App-Limit":     7500,
         | 
| 17 | 
            -
                    "X-Limit-App-Remaining": 7496,
         | 
| 18 | 
            -
                    "X-Limit-App-Reset":     1_393_653_600
         | 
| 19 | 
            -
                  }
         | 
| 20 | 
            -
                end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                it { expect(described_class).to be_a_kind_of(Class) }
         | 
| 23 | 
            -
                it { is_expected.to be_a_kind_of Creatable }
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                describe "Instance Signatures" do
         | 
| 26 | 
            -
                  it { is_expected.to respond_to(:push).with(2).argument }
         | 
| 27 | 
            -
                end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                describe "::push" do
         | 
| 30 | 
            -
                  before do
         | 
| 31 | 
            -
                    allow(Api).to receive(:connection).and_return excon_connection
         | 
| 32 | 
            -
                    allow(excon_connection).to receive(:post).and_return excon_response
         | 
| 33 | 
            -
                    allow(Response).to receive(:create).and_return response
         | 
| 34 | 
            -
                    allow(response).to receive(:process).and_call_original
         | 
| 35 | 
            -
                  end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
                  let(:request) { described_class.new }
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                  it 'is expected to call Api.connection.get with query set to the second argument' do
         | 
| 41 | 
            -
                    request.push endpoint, params
         | 
| 42 | 
            -
                    expect(excon_connection).to have_received(:post).with(query: a_kind_of(Hash), path: '1/messages.json')
         | 
| 43 | 
            -
                  end
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                  it "is expected to call Response.create with the response set to original" do
         | 
| 46 | 
            -
                    request.push endpoint, params
         | 
| 47 | 
            -
                    expect(Response).to have_received(:create).with(original: a_kind_of(Excon::Response))
         | 
| 48 | 
            -
                  end
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                  it "is expected to call response.process to populate the object" do
         | 
| 51 | 
            -
                    request.push endpoint, params
         | 
| 52 | 
            -
                    expect(response).to have_received(:process)
         | 
| 53 | 
            -
                  end
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                  it "is expected to return request" do
         | 
| 56 | 
            -
                    expect(request.push endpoint, params).to eq response
         | 
| 57 | 
            -
                  end
         | 
| 58 | 
            -
                end
         | 
| 59 | 
            -
              end
         | 
| 60 | 
            -
            end
         | 
| @@ -1,98 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Pushover
         | 
| 4 | 
            -
              describe Response do
         | 
| 5 | 
            -
                let(:body) { { "status" => 1, "request" => "647d2300-702c-4b38-8b2f-d56326ae460b" } }
         | 
| 6 | 
            -
                let(:receipt_body) { { "status" => 1, "request" => "647d2300-702c-4b38-8b2f-d56326ae460b", "receipt" => 'abcdefg' } }
         | 
| 7 | 
            -
                let(:error_body) { { "user" => "invalid", "errors" => ["user identifier is invalid"], "status" => 0, "request" => "5042853c-402d-4a18-abcb-168734a801de" } }
         | 
| 8 | 
            -
                let(:headers) do
         | 
| 9 | 
            -
                  {
         | 
| 10 | 
            -
                    "X-Limit-App-Limit":     7500,
         | 
| 11 | 
            -
                    "X-Limit-App-Remaining": 7496,
         | 
| 12 | 
            -
                    "X-Limit-App-Reset":     1_393_653_600
         | 
| 13 | 
            -
                  }
         | 
| 14 | 
            -
                end
         | 
| 15 | 
            -
                let(:excon_response) { Excon::Response.new(body: Oj.dump(body), status: 200, headers: headers) }
         | 
| 16 | 
            -
                let(:response) { described_class.create original: excon_response }
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                it { is_expected.to be_a_kind_of Creatable }
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                it { expect(described_class).to be_a_kind_of(Class) }
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                describe "Attributes" do
         | 
| 23 | 
            -
                  it { is_expected.to have_attributes(errors: []) }
         | 
| 24 | 
            -
                  it { is_expected.to have_attributes(limit: nil) }
         | 
| 25 | 
            -
                  it { is_expected.to have_attributes(original: nil) }
         | 
| 26 | 
            -
                  it { is_expected.to have_attributes(receipt: nil) }
         | 
| 27 | 
            -
                  it { is_expected.to have_attributes(remaining: nil) }
         | 
| 28 | 
            -
                  it { is_expected.to have_attributes(request: nil) }
         | 
| 29 | 
            -
                  it { is_expected.to have_attributes(reset: nil) }
         | 
| 30 | 
            -
                  it { is_expected.to have_attributes(status: a_kind_of(Numeric)) }
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                describe "Instance Signatures" do
         | 
| 34 | 
            -
                  it { is_expected.to respond_to(:process).with(0).argument }
         | 
| 35 | 
            -
                  it { is_expected.to respond_to(:process_body).with(0).argument }
         | 
| 36 | 
            -
                  it { is_expected.to respond_to(:process_headers).with(0).argument }
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                describe '::process' do
         | 
| 40 | 
            -
                  shared_examples 'process_verb' do |verb|
         | 
| 41 | 
            -
                    it "is expected to call process_#{verb}" do
         | 
| 42 | 
            -
                      allow(response).to receive("process_#{verb}".to_sym)
         | 
| 43 | 
            -
                      response.process
         | 
| 44 | 
            -
                      expect(response).to have_received("process_#{verb}".to_sym)
         | 
| 45 | 
            -
                    end
         | 
| 46 | 
            -
                  end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
                  include_examples 'process_verb', 'body'
         | 
| 49 | 
            -
                  include_examples 'process_verb', 'headers'
         | 
| 50 | 
            -
                end
         | 
| 51 | 
            -
             | 
| 52 | 
            -
                describe '::process_body' do
         | 
| 53 | 
            -
                  context "when a receipt is provided" do
         | 
| 54 | 
            -
                    let(:body) { receipt_body }
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                    it "is expected to set receipt" do
         | 
| 57 | 
            -
                      expect { response.process_body }.to change(response, :receipt).to body["receipt"]
         | 
| 58 | 
            -
                    end
         | 
| 59 | 
            -
                  end
         | 
| 60 | 
            -
             | 
| 61 | 
            -
                  context "when a errors is provided" do
         | 
| 62 | 
            -
                    let(:body) { error_body }
         | 
| 63 | 
            -
             | 
| 64 | 
            -
                    it "is expected to set errors" do
         | 
| 65 | 
            -
                      expect { response.process_body }.to change(response, :errors).to body["errors"]
         | 
| 66 | 
            -
                    end
         | 
| 67 | 
            -
                  end
         | 
| 68 | 
            -
             | 
| 69 | 
            -
                  it "is expected to call Oj.load" do
         | 
| 70 | 
            -
                    allow(Oj).to receive(:load).and_call_original
         | 
| 71 | 
            -
                    response.process_body
         | 
| 72 | 
            -
                    expect(Oj).to have_received(:load)
         | 
| 73 | 
            -
                  end
         | 
| 74 | 
            -
             | 
| 75 | 
            -
                  it "is expected to set status" do
         | 
| 76 | 
            -
                    expect { response.process_body }.to change(response, :status).to body["status"]
         | 
| 77 | 
            -
                  end
         | 
| 78 | 
            -
             | 
| 79 | 
            -
                  it "is expected to set request" do
         | 
| 80 | 
            -
                    expect { response.process_body }.to change(response, :request).to body["request"]
         | 
| 81 | 
            -
                  end
         | 
| 82 | 
            -
                end
         | 
| 83 | 
            -
             | 
| 84 | 
            -
                describe '::process_headers' do
         | 
| 85 | 
            -
                  it "is expected to set limit to X-Limit-App-Limit" do
         | 
| 86 | 
            -
                    expect { response.process_headers }.to change(response, :limit).to headers[:'X-Limit-App-Limit']
         | 
| 87 | 
            -
                  end
         | 
| 88 | 
            -
             | 
| 89 | 
            -
                  it "is expected to set remaing to X-Limit-App-Remaining" do
         | 
| 90 | 
            -
                    expect { response.process_headers }.to change(response, :remaining).to headers[:'X-Limit-App-Remaining']
         | 
| 91 | 
            -
                  end
         | 
| 92 | 
            -
             | 
| 93 | 
            -
                  it "is expected to set reset to X-Limit-App-Reset" do
         | 
| 94 | 
            -
                    expect { response.process_headers }.to change(response, :reset).to headers[:'X-Limit-App-Reset']
         | 
| 95 | 
            -
                  end
         | 
| 96 | 
            -
                end
         | 
| 97 | 
            -
              end
         | 
| 98 | 
            -
            end
         |