slack-notifier 0.3.1 → 0.3.2
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/lib/slack-notifier/http_post.rb +42 -0
- data/lib/slack-notifier/version.rb +1 -1
- data/lib/slack-notifier.rb +2 -1
- data/spec/integration/ping_integration_test.rb +5 -0
- data/spec/lib/slack-notifier/http_post_spec.rb +21 -0
- data/spec/lib/slack-notifier_spec.rb +5 -5
- metadata +10 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 62117fcfa420e6b62d6c4982c33b27b7ada1174a
         | 
| 4 | 
            +
              data.tar.gz: d475b9280f822a8f0eb67005b209a324b178891e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 49d78c4b6cc439d904c41024958fb46aa529b654ce1ff7f4aba4351cfacbb82137a722817e989bd1228c75ad6143c9556347c61e9ef82947f56c51138728a1ba
         | 
| 7 | 
            +
              data.tar.gz: 0654d3a34c0223693109bed7badd4a99c4c162e140abe18995b8caa02c43b35ffe6789c2fb6ac538839dacae91531bfda298fbf4f596326450c373600a7ae2ec
         | 
| @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            module Slack
         | 
| 2 | 
            +
              class Notifier
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                class HTTPPost
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  class << self
         | 
| 7 | 
            +
                    def to uri, params
         | 
| 8 | 
            +
                      HTTPPost.new( uri, params ).call
         | 
| 9 | 
            +
                    end
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  attr_reader :uri, :params
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def initialize uri, params
         | 
| 15 | 
            +
                    @uri    = uri
         | 
| 16 | 
            +
                    @params = params
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  def call
         | 
| 20 | 
            +
                    http_obj.request request_obj
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  private
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    def request_obj
         | 
| 26 | 
            +
                      req = Net::HTTP::Post.new uri.request_uri
         | 
| 27 | 
            +
                      req.set_form_data params
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                      return req
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                    def http_obj
         | 
| 33 | 
            +
                      http = Net::HTTP.new uri.host, uri.port
         | 
| 34 | 
            +
                      http.use_ssl = (uri.scheme == "https")
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                      return http
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
            end
         | 
    
        data/lib/slack-notifier.rb
    CHANGED
    
    | @@ -2,6 +2,7 @@ require 'net/http' | |
| 2 2 | 
             
            require 'uri'
         | 
| 3 3 | 
             
            require 'json'
         | 
| 4 4 |  | 
| 5 | 
            +
            require_relative 'slack-notifier/http_post'
         | 
| 5 6 | 
             
            require_relative 'slack-notifier/link_formatter'
         | 
| 6 7 |  | 
| 7 8 | 
             
            module Slack
         | 
| @@ -23,7 +24,7 @@ module Slack | |
| 23 24 | 
             
                  message = LinkFormatter.format(message)
         | 
| 24 25 | 
             
                  payload = { text: message }.merge(default_payload).merge(options)
         | 
| 25 26 |  | 
| 26 | 
            -
                   | 
| 27 | 
            +
                  HTTPPost.to endpoint, payload: payload.to_json
         | 
| 27 28 | 
             
                end
         | 
| 28 29 |  | 
| 29 30 | 
             
                private
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Slack::Notifier::HTTPPost do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              describe "::to" do
         | 
| 6 | 
            +
                it "initializes HTTPPost with the given uri and params then calls" do
         | 
| 7 | 
            +
                  http_post_double = instance_double("Slack::Notifier::HTTPPost")
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  expect( described_class ).to receive(:new)
         | 
| 10 | 
            +
                                           .with( 'uri', 'params' )
         | 
| 11 | 
            +
                                           .and_return( http_post_double )
         | 
| 12 | 
            +
                  expect( http_post_double ).to receive(:call)
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  described_class.to 'uri', 'params'
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                # http_post is really tested in the integration spec,
         | 
| 18 | 
            +
                # where the internals are run through
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            end
         | 
| @@ -21,7 +21,7 @@ describe Slack::Notifier do | |
| 21 21 |  | 
| 22 22 | 
             
              describe "#ping" do
         | 
| 23 23 | 
             
                before :each do
         | 
| 24 | 
            -
                  allow(  | 
| 24 | 
            +
                  allow( Slack::Notifier::HTTPPost ).to receive(:to)
         | 
| 25 25 | 
             
                end
         | 
| 26 26 |  | 
| 27 27 | 
             
                it "passes the message through LinkFormatter" do
         | 
| @@ -48,7 +48,7 @@ describe Slack::Notifier do | |
| 48 48 | 
             
                  end
         | 
| 49 49 |  | 
| 50 50 | 
             
                  it "uses default channel" do
         | 
| 51 | 
            -
                    expect(  | 
| 51 | 
            +
                    expect( Slack::Notifier::HTTPPost ).to receive(:to)
         | 
| 52 52 | 
             
                                      .with @endpoint_double,
         | 
| 53 53 | 
             
                                            payload: '{"text":"the message","channel":"default"}'
         | 
| 54 54 |  | 
| @@ -56,7 +56,7 @@ describe Slack::Notifier do | |
| 56 56 | 
             
                  end
         | 
| 57 57 |  | 
| 58 58 | 
             
                  it "allows override channel to be set" do
         | 
| 59 | 
            -
                    expect(  | 
| 59 | 
            +
                    expect( Slack::Notifier::HTTPPost ).to receive(:to)
         | 
| 60 60 | 
             
                                      .with @endpoint_double,
         | 
| 61 61 | 
             
                                            payload: '{"text":"the message","channel":"new"}'
         | 
| 62 62 |  | 
| @@ -72,7 +72,7 @@ describe Slack::Notifier do | |
| 72 72 | 
             
                                  .with("https://team.slack.com/services/hooks/incoming-webhook?token=token")
         | 
| 73 73 | 
             
                                  .and_return(@endpoint_double)
         | 
| 74 74 |  | 
| 75 | 
            -
                      expect(  | 
| 75 | 
            +
                      expect( Slack::Notifier::HTTPPost ).to receive(:to)
         | 
| 76 76 | 
             
                                        .with @endpoint_double,
         | 
| 77 77 | 
             
                                              payload: '{"text":"the message","channel":"channel"}'
         | 
| 78 78 |  | 
| @@ -87,7 +87,7 @@ describe Slack::Notifier do | |
| 87 87 | 
             
                                .with("https://team.slack.com/services/hooks/custom_hook_name?token=token")
         | 
| 88 88 | 
             
                                .and_return(@endpoint_double)
         | 
| 89 89 |  | 
| 90 | 
            -
                    expect(  | 
| 90 | 
            +
                    expect( Slack::Notifier::HTTPPost ).to receive(:to)
         | 
| 91 91 | 
             
                                      .with @endpoint_double,
         | 
| 92 92 | 
             
                                            payload: '{"text":"the message","channel":"channel"}'
         | 
| 93 93 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,16 +1,16 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: slack-notifier
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Steven Sloan
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014-03- | 
| 11 | 
            +
            date: 2014-03-27 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 | 
            -
            description:  | 
| 13 | 
            +
            description: ' A slim ruby wrapper for posting to slack webhooks '
         | 
| 14 14 | 
             
            email:
         | 
| 15 15 | 
             
            - stevenosloan@gmail.com
         | 
| 16 16 | 
             
            executables: []
         | 
| @@ -18,8 +18,11 @@ extensions: [] | |
| 18 18 | 
             
            extra_rdoc_files: []
         | 
| 19 19 | 
             
            files:
         | 
| 20 20 | 
             
            - lib/slack-notifier.rb
         | 
| 21 | 
            +
            - lib/slack-notifier/http_post.rb
         | 
| 21 22 | 
             
            - lib/slack-notifier/link_formatter.rb
         | 
| 22 23 | 
             
            - lib/slack-notifier/version.rb
         | 
| 24 | 
            +
            - spec/integration/ping_integration_test.rb
         | 
| 25 | 
            +
            - spec/lib/slack-notifier/http_post_spec.rb
         | 
| 23 26 | 
             
            - spec/lib/slack-notifier/link_formatter_spec.rb
         | 
| 24 27 | 
             
            - spec/lib/slack-notifier_spec.rb
         | 
| 25 28 | 
             
            - spec/spec_helper.rb
         | 
| @@ -33,12 +36,12 @@ require_paths: | |
| 33 36 | 
             
            - lib
         | 
| 34 37 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 35 38 | 
             
              requirements:
         | 
| 36 | 
            -
              - -  | 
| 39 | 
            +
              - - '>='
         | 
| 37 40 | 
             
                - !ruby/object:Gem::Version
         | 
| 38 41 | 
             
                  version: '0'
         | 
| 39 42 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 40 43 | 
             
              requirements:
         | 
| 41 | 
            -
              - -  | 
| 44 | 
            +
              - - '>='
         | 
| 42 45 | 
             
                - !ruby/object:Gem::Version
         | 
| 43 46 | 
             
                  version: '0'
         | 
| 44 47 | 
             
            requirements: []
         | 
| @@ -48,7 +51,8 @@ signing_key: | |
| 48 51 | 
             
            specification_version: 4
         | 
| 49 52 | 
             
            summary: A slim ruby wrapper for posting to slack webhooks
         | 
| 50 53 | 
             
            test_files:
         | 
| 54 | 
            +
            - spec/integration/ping_integration_test.rb
         | 
| 55 | 
            +
            - spec/lib/slack-notifier/http_post_spec.rb
         | 
| 51 56 | 
             
            - spec/lib/slack-notifier/link_formatter_spec.rb
         | 
| 52 57 | 
             
            - spec/lib/slack-notifier_spec.rb
         | 
| 53 58 | 
             
            - spec/spec_helper.rb
         | 
| 54 | 
            -
            has_rdoc: 
         |