bw_status_board_api 1.0.2 → 1.1.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/bw_status_board_api.gemspec +2 -2
- data/lib/bw_status_board_api/client.rb +4 -0
- data/lib/bw_status_board_api/client/boards.rb +77 -0
- data/lib/bw_status_board_api/client/environments.rb +92 -2
- data/lib/bw_status_board_api/client/environments/services.rb +97 -2
- data/lib/bw_status_board_api/client/helpers/filter.rb +14 -0
- data/lib/bw_status_board_api/client/metrics.rb +86 -0
- data/lib/bw_status_board_api/error.rb +3 -61
- data/lib/bw_status_board_api/version.rb +1 -1
- metadata +27 -24
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d5e487fe194eb83bdcfb1a9bdc308caecf9003e3
         | 
| 4 | 
            +
              data.tar.gz: 5165623308736693ee65b76e37eade4fc1c4534f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 68ba44ea521c74c9d9e4b11d85eac3bc93aeb19d7da9abc84b9b9049b9bbaeea5b3584ff83a738127cc571098c23deeadc3b51b2f3e21dfd841b5c433f259c7d
         | 
| 7 | 
            +
              data.tar.gz: ec3a688534b51212564567ed012f1b57c76d7811af5ff086909b129c769fe73a92199872aa3329f7cae4dbf846dfa81fdfa1ce39b1afed1636de2ce04afdaea9
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,6 +1,11 @@ | |
| 1 1 | 
             
            # Changelog
         | 
| 2 2 | 
             
            All notable changes to this project will be documented in this file.
         | 
| 3 3 |  | 
| 4 | 
            +
            ## 1.0.2
         | 
| 5 | 
            +
            ### Added
         | 
| 6 | 
            +
            * NoTask - added cops configuration to .rubocop.yml
         | 
| 7 | 
            +
            * NoTask - added Gemfile.lock to .gitignore
         | 
| 8 | 
            +
             | 
| 4 9 | 
             
            ## 1.0.1
         | 
| 5 10 | 
             
            ### Fixed
         | 
| 6 11 | 
             
            * NoTask - fixed conflict with bwapi gem middleware
         | 
    
        data/bw_status_board_api.gemspec
    CHANGED
    
    | @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/lib/bw_status_board_api/version' | |
| 3 3 | 
             
            Gem::Specification.new do |s|
         | 
| 4 4 | 
             
              s.name        = 'bw_status_board_api'
         | 
| 5 5 | 
             
              s.version     = BWStatusBoardAPI::VERSION
         | 
| 6 | 
            -
              s.date        = '2014- | 
| 6 | 
            +
              s.date        = '2014-10-05'
         | 
| 7 7 | 
             
              s.summary     = 'Brandwatch Status Board API Wrapper'
         | 
| 8 8 | 
             
              s.description = 'A Ruby wrapper for the Brandwatch Status Board'
         | 
| 9 9 | 
             
              s.author      = 'Jonathan Chrisp'
         | 
| @@ -19,7 +19,7 @@ Gem::Specification.new do |s| | |
| 19 19 | 
             
              s.add_runtime_dependency 'faraday', '~> 0.9.0'
         | 
| 20 20 | 
             
              s.add_runtime_dependency 'faraday_middleware', '~> 0.9.1'
         | 
| 21 21 | 
             
              s.add_runtime_dependency 'faraday_middleware-parse_oj', '~> 0.3.0'
         | 
| 22 | 
            -
              s.add_runtime_dependency 'oj', '~> 2.10. | 
| 22 | 
            +
              s.add_runtime_dependency 'oj', '~> 2.10.3'
         | 
| 23 23 |  | 
| 24 24 | 
             
              s.files         = `git ls-files`.split("\n")
         | 
| 25 25 | 
             
              s.executables   = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
         | 
| @@ -3,7 +3,9 @@ require 'bw_status_board_api/connection' | |
| 3 3 | 
             
            require 'bw_status_board_api/request'
         | 
| 4 4 | 
             
            require 'bw_status_board_api/performance'
         | 
| 5 5 |  | 
| 6 | 
            +
            require 'bw_status_board_api/client/boards'
         | 
| 6 7 | 
             
            require 'bw_status_board_api/client/environments'
         | 
| 8 | 
            +
            require 'bw_status_board_api/client/metrics'
         | 
| 7 9 |  | 
| 8 10 | 
             
            require 'faraday'
         | 
| 9 11 |  | 
| @@ -15,7 +17,9 @@ module BWStatusBoardAPI | |
| 15 17 | 
             
                include BWStatusBoardAPI::Request
         | 
| 16 18 | 
             
                include BWStatusBoardAPI::Performance
         | 
| 17 19 |  | 
| 20 | 
            +
                include BWStatusBoardAPI::Client::Boards
         | 
| 18 21 | 
             
                include BWStatusBoardAPI::Client::Environments
         | 
| 22 | 
            +
                include BWStatusBoardAPI::Client::Metrics
         | 
| 19 23 |  | 
| 20 24 | 
             
                # Initializes Client
         | 
| 21 25 | 
             
                #
         | 
| @@ -0,0 +1,77 @@ | |
| 1 | 
            +
            require 'bw_status_board_api/client/environments/services'
         | 
| 2 | 
            +
            require 'bw_status_board_api/client/helpers/filter'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module BWStatusBoardAPI
         | 
| 5 | 
            +
              class Client
         | 
| 6 | 
            +
                # Boards module for boards endpoints
         | 
| 7 | 
            +
                module Boards
         | 
| 8 | 
            +
                  include BWStatusBoardAPI::Client::Helpers
         | 
| 9 | 
            +
                  include BWStatusBoardAPI::Client::Environments::Services
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  # Get boards
         | 
| 12 | 
            +
                  #
         | 
| 13 | 
            +
                  # @return [Hash] boards
         | 
| 14 | 
            +
                  def boards
         | 
| 15 | 
            +
                    get 'boards'
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  # Returns boards name list
         | 
| 19 | 
            +
                  #
         | 
| 20 | 
            +
                  # @return [Array] environments
         | 
| 21 | 
            +
                  def boards_summary
         | 
| 22 | 
            +
                    filter(boards, true)
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  # Get board
         | 
| 26 | 
            +
                  #
         | 
| 27 | 
            +
                  # @param board_id [Integer] board id
         | 
| 28 | 
            +
                  # @return [Hash] board
         | 
| 29 | 
            +
                  def board(board_id)
         | 
| 30 | 
            +
                    get "boards/#{board_id}"
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  # Create board
         | 
| 34 | 
            +
                  #
         | 
| 35 | 
            +
                  # @param opts [Hash] options hash of parameters
         | 
| 36 | 
            +
                  # @option opts [String] name name of the board
         | 
| 37 | 
            +
                  # @option opts [Array] environments environments within the board
         | 
| 38 | 
            +
                  # @option opts [Boolean] enabled board enabled flag
         | 
| 39 | 
            +
                  # @return [Hash] board
         | 
| 40 | 
            +
                  def create_board(opts = {})
         | 
| 41 | 
            +
                    post 'boards', opts
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  # Update board
         | 
| 45 | 
            +
                  #
         | 
| 46 | 
            +
                  # @param board_id [Integer] board id
         | 
| 47 | 
            +
                  # @param opts [Hash] options hash of parameters
         | 
| 48 | 
            +
                  # @option opts [String] name name of the board
         | 
| 49 | 
            +
                  # @option opts [Array] environments environments within the board
         | 
| 50 | 
            +
                  # @option opts [Boolean] enabled board enabled flag
         | 
| 51 | 
            +
                  # @return [Hash] board
         | 
| 52 | 
            +
                  def update_board(board_id, opts = {})
         | 
| 53 | 
            +
                    put "boards/#{board_id}", opts
         | 
| 54 | 
            +
                  end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  # Patch board
         | 
| 57 | 
            +
                  #
         | 
| 58 | 
            +
                  # @param board_id [Integer] board id
         | 
| 59 | 
            +
                  # @param opts [Hash] options hash of parameters
         | 
| 60 | 
            +
                  # @option opts [String] name name of the board
         | 
| 61 | 
            +
                  # @option opts [Array] environments environments within the board
         | 
| 62 | 
            +
                  # @option opts [Boolean] enabled board enabled flag
         | 
| 63 | 
            +
                  # @return [Hash] board
         | 
| 64 | 
            +
                  def patch_board(board_id, opts = {})
         | 
| 65 | 
            +
                    patch "boards/#{board_id}", opts
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                  # Delete board
         | 
| 69 | 
            +
                  #
         | 
| 70 | 
            +
                  # @param board_id [Integer] board id
         | 
| 71 | 
            +
                  # @return [Hash] board
         | 
| 72 | 
            +
                  def delete_board(board_id)
         | 
| 73 | 
            +
                    delete "boards/#{board_id}"
         | 
| 74 | 
            +
                  end
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
              end
         | 
| 77 | 
            +
            end
         | 
| @@ -1,17 +1,107 @@ | |
| 1 1 | 
             
            require 'bw_status_board_api/client/environments/services'
         | 
| 2 | 
            +
            require 'bw_status_board_api/client/helpers/filter'
         | 
| 2 3 |  | 
| 3 4 | 
             
            module BWStatusBoardAPI
         | 
| 4 5 | 
             
              class Client
         | 
| 5 6 | 
             
                # Environments module for environments endpoints
         | 
| 6 7 | 
             
                module Environments
         | 
| 8 | 
            +
                  include BWStatusBoardAPI::Client::Helpers
         | 
| 7 9 | 
             
                  include BWStatusBoardAPI::Client::Environments::Services
         | 
| 8 10 |  | 
| 9 | 
            -
                  # Get environments | 
| 11 | 
            +
                  # Get environments
         | 
| 10 12 | 
             
                  #
         | 
| 11 | 
            -
                  # @return [Hash]  | 
| 13 | 
            +
                  # @return [Hash] environments
         | 
| 12 14 | 
             
                  def environments
         | 
| 13 15 | 
             
                    get 'environments'
         | 
| 14 16 | 
             
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  # Returns environments name list
         | 
| 19 | 
            +
                  #
         | 
| 20 | 
            +
                  # @return [Array] environments
         | 
| 21 | 
            +
                  def environments_summary
         | 
| 22 | 
            +
                    filter(environments, true)
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  # Get environment
         | 
| 26 | 
            +
                  #
         | 
| 27 | 
            +
                  # @param environment_id [Integer] environment id
         | 
| 28 | 
            +
                  # @return [Hash] environment
         | 
| 29 | 
            +
                  def environment(environment_id)
         | 
| 30 | 
            +
                    get "environments/#{environment_id}"
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  # Create environment
         | 
| 34 | 
            +
                  #
         | 
| 35 | 
            +
                  # @param opts [Hash] options hash of parameters
         | 
| 36 | 
            +
                  # @option opts [String] name name of the environment
         | 
| 37 | 
            +
                  # @option opts [String] shortName short name of the environment
         | 
| 38 | 
            +
                  # @option opts [Array] services services within the board
         | 
| 39 | 
            +
                  # @option opts [String] status status of the environment
         | 
| 40 | 
            +
                  # @option opts [Boolean] enabled environment enabled flag
         | 
| 41 | 
            +
                  # @return [Hash] environment
         | 
| 42 | 
            +
                  def create_environment(opts = {})
         | 
| 43 | 
            +
                    post 'environments', opts
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  # Update environment
         | 
| 47 | 
            +
                  #
         | 
| 48 | 
            +
                  # @param environment_id [Integer] environment id
         | 
| 49 | 
            +
                  # @param opts [Hash] options hash of parameters
         | 
| 50 | 
            +
                  # @option opts [String] name name of the environment
         | 
| 51 | 
            +
                  # @option opts [String] shortName short name of the environment
         | 
| 52 | 
            +
                  # @option opts [Array] services services within the board
         | 
| 53 | 
            +
                  # @option opts [String] status status of the environment
         | 
| 54 | 
            +
                  # @option opts [Boolean] enabled environment enabled flag
         | 
| 55 | 
            +
                  # @return [Hash] environment
         | 
| 56 | 
            +
                  def update_environment(environment_id, opts = {})
         | 
| 57 | 
            +
                    put "environments/#{environment_id}", opts
         | 
| 58 | 
            +
                  end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  # Patch environment
         | 
| 61 | 
            +
                  #
         | 
| 62 | 
            +
                  # @param environment_id [Integer] environment id
         | 
| 63 | 
            +
                  # @param opts [Hash] options hash of parameters
         | 
| 64 | 
            +
                  # @option opts [String] name name of the environment
         | 
| 65 | 
            +
                  # @option opts [String] shortName short name of the environment
         | 
| 66 | 
            +
                  # @option opts [Array] services services within the board
         | 
| 67 | 
            +
                  # @option opts [String] status status of the environment
         | 
| 68 | 
            +
                  # @option opts [Boolean] enabled environment enabled flag
         | 
| 69 | 
            +
                  # @return [Hash] environment
         | 
| 70 | 
            +
                  def patch_environment(environment_id, opts = {})
         | 
| 71 | 
            +
                    patch "environments/#{environment_id}", opts
         | 
| 72 | 
            +
                  end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                  # Delete environment
         | 
| 75 | 
            +
                  #
         | 
| 76 | 
            +
                  # @param environment_id [Integer] environment id
         | 
| 77 | 
            +
                  # @return [Hash] environment
         | 
| 78 | 
            +
                  def delete_environment(environment_id)
         | 
| 79 | 
            +
                    delete "environments/#{environment_id}"
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                  # Returns failing environments
         | 
| 83 | 
            +
                  #
         | 
| 84 | 
            +
                  # @param summary [Boolean] summary flag
         | 
| 85 | 
            +
                  # @return [Array] environments
         | 
| 86 | 
            +
                  def failing_environments(summary = true)
         | 
| 87 | 
            +
                    filter(environments, summary, 'status', 'failure')
         | 
| 88 | 
            +
                  end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                  # Returns partially successful environments
         | 
| 91 | 
            +
                  #
         | 
| 92 | 
            +
                  # @param summary [Boolean] summary flag
         | 
| 93 | 
            +
                  # @return [Array] environments
         | 
| 94 | 
            +
                  def partially_successful_environments(summary = true)
         | 
| 95 | 
            +
                    filter(environments, summary, 'status', 'partialSuccess')
         | 
| 96 | 
            +
                  end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                  # Returns successful environments
         | 
| 99 | 
            +
                  #
         | 
| 100 | 
            +
                  # @param summary [Boolean] summary flag
         | 
| 101 | 
            +
                  # @return [Array] environments
         | 
| 102 | 
            +
                  def successful_environments(summary = true)
         | 
| 103 | 
            +
                    filter(environments, summary, 'status', 'success')
         | 
| 104 | 
            +
                  end
         | 
| 15 105 | 
             
                end
         | 
| 16 106 | 
             
              end
         | 
| 17 107 | 
             
            end
         | 
| @@ -1,15 +1,110 @@ | |
| 1 | 
            +
            require 'bw_status_board_api/client/helpers/filter'
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module BWStatusBoardAPI
         | 
| 2 4 | 
             
              class Client
         | 
| 3 5 | 
             
                module Environments
         | 
| 4 6 | 
             
                  # Services module for environment services endpoints
         | 
| 5 7 | 
             
                  module Services
         | 
| 8 | 
            +
                    include BWStatusBoardAPI::Client::Helpers
         | 
| 9 | 
            +
             | 
| 6 10 | 
             
                    # Get environment services
         | 
| 7 11 | 
             
                    #
         | 
| 8 | 
            -
                    # @param environment_id [Integer]  | 
| 9 | 
            -
                    # @return [Hash]  | 
| 12 | 
            +
                    # @param environment_id [Integer] environment id
         | 
| 13 | 
            +
                    # @return [Hash] services
         | 
| 10 14 | 
             
                    def services(environment_id)
         | 
| 11 15 | 
             
                      get "environments/#{environment_id}/services"
         | 
| 12 16 | 
             
                    end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    # Returns services name list
         | 
| 19 | 
            +
                    #
         | 
| 20 | 
            +
                    # @param environment_id [Integer] environment id
         | 
| 21 | 
            +
                    # @return [Array] the environments
         | 
| 22 | 
            +
                    def services_summary(environment_id)
         | 
| 23 | 
            +
                      filter(services(environment_id), true)
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                    # Get environment service
         | 
| 27 | 
            +
                    #
         | 
| 28 | 
            +
                    # @param environment_id [Integer] environment id
         | 
| 29 | 
            +
                    # @param service_id [Integer] service id
         | 
| 30 | 
            +
                    # @return [Hash] service
         | 
| 31 | 
            +
                    def service(environment_id, service_id)
         | 
| 32 | 
            +
                      get "environments/#{environment_id}/services/#{service_id}"
         | 
| 33 | 
            +
                    end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                    # Create service
         | 
| 36 | 
            +
                    #
         | 
| 37 | 
            +
                    # @param environment_id [Integer] environment id
         | 
| 38 | 
            +
                    # @param opts [Hash] options hash of parameters
         | 
| 39 | 
            +
                    # @option opts [String] name name of the service
         | 
| 40 | 
            +
                    # @option opts [String] shortName short name of the service
         | 
| 41 | 
            +
                    # @option opts [String] status status of the service
         | 
| 42 | 
            +
                    # @option opts [String] url url of the service
         | 
| 43 | 
            +
                    # @option opts [Integer] successStatusCode success status code of the service
         | 
| 44 | 
            +
                    # @option opts [Boolean] enabled service enabled flag
         | 
| 45 | 
            +
                    # @return [Hash] service
         | 
| 46 | 
            +
                    def create_service(environment_id, opts = {})
         | 
| 47 | 
            +
                      post "environments/#{environment_id}/services", opts
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                    # Update environment service
         | 
| 51 | 
            +
                    #
         | 
| 52 | 
            +
                    # @param environment_id [Integer] environment id
         | 
| 53 | 
            +
                    # @param service_id [Integer] service id
         | 
| 54 | 
            +
                    # @param opts [Hash] options hash of parameters
         | 
| 55 | 
            +
                    # @option opts [String] name name of the service
         | 
| 56 | 
            +
                    # @option opts [String] shortName short name of the service
         | 
| 57 | 
            +
                    # @option opts [String] status status of the service
         | 
| 58 | 
            +
                    # @option opts [String] url url of the service
         | 
| 59 | 
            +
                    # @option opts [Integer] successStatusCode success status code of the service
         | 
| 60 | 
            +
                    # @option opts [Boolean] enabled service enabled flag
         | 
| 61 | 
            +
                    # @return [Hash] service
         | 
| 62 | 
            +
                    def update_service(environment_id, service_id, opts = {})
         | 
| 63 | 
            +
                      put "environments/#{environment_id}/services/#{service_id}", opts
         | 
| 64 | 
            +
                    end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                    # Patch environment service
         | 
| 67 | 
            +
                    #
         | 
| 68 | 
            +
                    # @param environment_id [Integer] environment id
         | 
| 69 | 
            +
                    # @param service_id [Integer] service id
         | 
| 70 | 
            +
                    # @param opts [Hash] options hash of parameters
         | 
| 71 | 
            +
                    # @option opts [String] name name of the service
         | 
| 72 | 
            +
                    # @option opts [String] shortName short name of the service
         | 
| 73 | 
            +
                    # @option opts [String] status status of the service
         | 
| 74 | 
            +
                    # @option opts [String] url url of the service
         | 
| 75 | 
            +
                    # @option opts [Integer] successStatusCode success status code of the service
         | 
| 76 | 
            +
                    # @option opts [Boolean] enabled service enabled flag
         | 
| 77 | 
            +
                    # @return [Hash] service
         | 
| 78 | 
            +
                    def patch_service(environment_id, service_id, opts = {})
         | 
| 79 | 
            +
                      patch "environments/#{environment_id}/services/#{service_id}", opts
         | 
| 80 | 
            +
                    end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                    # Delete environment service
         | 
| 83 | 
            +
                    #
         | 
| 84 | 
            +
                    # @param environment_id [Integer] environment id
         | 
| 85 | 
            +
                    # @param service_id [Integer] service id
         | 
| 86 | 
            +
                    # @return [Hash] service
         | 
| 87 | 
            +
                    def delete_service(environment_id, service_id)
         | 
| 88 | 
            +
                      delete "environments/#{environment_id}/services/#{service_id}"
         | 
| 89 | 
            +
                    end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                    # Returns failing services for environment
         | 
| 92 | 
            +
                    #
         | 
| 93 | 
            +
                    # @param environment_id [Integer] environment id
         | 
| 94 | 
            +
                    # @param summary [Boolean] summary flag
         | 
| 95 | 
            +
                    # @return [Array] services
         | 
| 96 | 
            +
                    def failing_services(environment_id, summary = true)
         | 
| 97 | 
            +
                      filter(services(environment_id), summary, 'status', 'failure')
         | 
| 98 | 
            +
                    end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                    # Returns successful services for environment
         | 
| 101 | 
            +
                    #
         | 
| 102 | 
            +
                    # @param environment_id [Integer] environment id
         | 
| 103 | 
            +
                    # @param summary [Boolean] summary flag
         | 
| 104 | 
            +
                    # @return [Array] services
         | 
| 105 | 
            +
                    def successful_services(environment_id, summary = true)
         | 
| 106 | 
            +
                      filter(services(environment_id), summary, 'status', 'success')
         | 
| 107 | 
            +
                    end
         | 
| 13 108 | 
             
                  end
         | 
| 14 109 | 
             
                end
         | 
| 15 110 | 
             
              end
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            module BWStatusBoardAPI
         | 
| 2 | 
            +
              class Client
         | 
| 3 | 
            +
                # Helpers module
         | 
| 4 | 
            +
                module Helpers
         | 
| 5 | 
            +
                  def filter(response, summary = false, key = nil, value = nil)
         | 
| 6 | 
            +
                    response.each_with_object([]) do |hash, array|
         | 
| 7 | 
            +
                      if value.nil? || hash[key] == value
         | 
| 8 | 
            +
                        summary ? array << hash['name'] : array << hash
         | 
| 9 | 
            +
                      end
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -0,0 +1,86 @@ | |
| 1 | 
            +
            require 'bw_status_board_api/client/boards'
         | 
| 2 | 
            +
            require 'bw_status_board_api/client/environments'
         | 
| 3 | 
            +
            require 'bw_status_board_api/client/environments/services'
         | 
| 4 | 
            +
            require 'bw_status_board_api/client/helpers/filter'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module BWStatusBoardAPI
         | 
| 7 | 
            +
              class Client
         | 
| 8 | 
            +
                # Metrics module
         | 
| 9 | 
            +
                module Metrics
         | 
| 10 | 
            +
                  include BWStatusBoardAPI::Client::Boards
         | 
| 11 | 
            +
                  include BWStatusBoardAPI::Client::Environments
         | 
| 12 | 
            +
                  include BWStatusBoardAPI::Client::Environments::Services
         | 
| 13 | 
            +
                  include BWStatusBoardAPI::Client::Helpers
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  # Returns total boards
         | 
| 16 | 
            +
                  #
         | 
| 17 | 
            +
                  # @return [Integer] total
         | 
| 18 | 
            +
                  def total_boards
         | 
| 19 | 
            +
                    boards.size
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  # Returns total environments
         | 
| 23 | 
            +
                  #
         | 
| 24 | 
            +
                  # @return [Integer] total
         | 
| 25 | 
            +
                  def total_environments
         | 
| 26 | 
            +
                    environments.size
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  # Returns total failing environments
         | 
| 30 | 
            +
                  #
         | 
| 31 | 
            +
                  # @return [Integer] total
         | 
| 32 | 
            +
                  def total_failing_environments
         | 
| 33 | 
            +
                    filter(environments, false, 'status', 'failure').size
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  # Returns total partially successful environments
         | 
| 37 | 
            +
                  #
         | 
| 38 | 
            +
                  # @return [Integer] total
         | 
| 39 | 
            +
                  def total_partially_successful_environments
         | 
| 40 | 
            +
                    filter(environments, false, 'status', 'partialSuccess').size
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  # Returns total successful environments
         | 
| 44 | 
            +
                  #
         | 
| 45 | 
            +
                  # @return [Integer] total
         | 
| 46 | 
            +
                  def total_successful_environments
         | 
| 47 | 
            +
                    filter(environments, false, 'status', 'success').size
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  # Returns total services
         | 
| 51 | 
            +
                  #
         | 
| 52 | 
            +
                  # @return [Integer] total
         | 
| 53 | 
            +
                  def total_services
         | 
| 54 | 
            +
                    environments.map { |environment| environment['services'].size }.inject(:+)
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                  # Returns total services for environment
         | 
| 58 | 
            +
                  #
         | 
| 59 | 
            +
                  # @param environment_id [Integer] environment id
         | 
| 60 | 
            +
                  # @return [Integer] total
         | 
| 61 | 
            +
                  def total_environment_services(environment_id)
         | 
| 62 | 
            +
                    services(environment_id).size
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  # Returns total failing services
         | 
| 66 | 
            +
                  #
         | 
| 67 | 
            +
                  # @return [Integer] total
         | 
| 68 | 
            +
                  def total_failing_services
         | 
| 69 | 
            +
                    filter(all_services, false, 'status', 'failure').size
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  # Returns total successful services
         | 
| 73 | 
            +
                  #
         | 
| 74 | 
            +
                  # @return [Integer] total
         | 
| 75 | 
            +
                  def total_successful_services
         | 
| 76 | 
            +
                    filter(all_services, false, 'status', 'success').size
         | 
| 77 | 
            +
                  end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                  private
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                  def all_services
         | 
| 82 | 
            +
                    environments.map { |environment| environment['services'] }.flatten
         | 
| 83 | 
            +
                  end
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
            end
         | 
| @@ -2,70 +2,12 @@ module BWStatusBoardAPI | |
| 2 2 | 
             
              # BWStatusBoardAPI error class
         | 
| 3 3 | 
             
              class BWStatusBoardAPIError < StandardError
         | 
| 4 4 | 
             
                def initialize(response = nil)
         | 
| 5 | 
            -
                   | 
| 6 | 
            -
             | 
| 7 | 
            -
                  @errors.empty? ? super() : super(@errors.join(', '))
         | 
| 8 | 
            -
                end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                # Check if response is valid
         | 
| 11 | 
            -
                #
         | 
| 12 | 
            -
                # @param object [Object] response object to check for errors
         | 
| 13 | 
            -
                def valid_response?(response)
         | 
| 14 | 
            -
                  return nil if response.nil?
         | 
| 15 | 
            -
                  return nil unless response.body.is_a?(Object) && response.respond_to?(:body)
         | 
| 16 | 
            -
                  return nil unless response.body.is_a?(Hash)
         | 
| 17 | 
            -
                  parse_errors(errors_keys?(response.body)) unless response.body.nil?
         | 
| 18 | 
            -
                end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                # Check if response has known errors keys
         | 
| 21 | 
            -
                #
         | 
| 22 | 
            -
                # @param object [Object] response object to process for errors
         | 
| 23 | 
            -
                def errors_keys?(body)
         | 
| 24 | 
            -
                  if body.key?('error') && body.key?('error_description')
         | 
| 25 | 
            -
                    body
         | 
| 26 | 
            -
                  elsif body.key?('errors')
         | 
| 27 | 
            -
                    body['errors']
         | 
| 5 | 
            +
                  if response.respond_to?(:body) && response.body.is_a?(Hash) && response.body.key?('message')
         | 
| 6 | 
            +
                    super(response.body['message'])
         | 
| 28 7 | 
             
                  else
         | 
| 29 | 
            -
                     | 
| 8 | 
            +
                    super()
         | 
| 30 9 | 
             
                  end
         | 
| 31 10 | 
             
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                # Parses errors based on error body passed
         | 
| 34 | 
            -
                #
         | 
| 35 | 
            -
                # @param body [Hash] errors
         | 
| 36 | 
            -
                def parse_errors(body)
         | 
| 37 | 
            -
                  verify_type body
         | 
| 38 | 
            -
                end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                # Verifies type
         | 
| 41 | 
            -
                #
         | 
| 42 | 
            -
                # @param object [Object] type to determine
         | 
| 43 | 
            -
                def verify_type(type)
         | 
| 44 | 
            -
                  case type
         | 
| 45 | 
            -
                  when Array
         | 
| 46 | 
            -
                    split_array_errors(type)
         | 
| 47 | 
            -
                  when Hash
         | 
| 48 | 
            -
                    split_hash_errors(type)
         | 
| 49 | 
            -
                  when String
         | 
| 50 | 
            -
                    @errors << type
         | 
| 51 | 
            -
                  end
         | 
| 52 | 
            -
                end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                # Iterates through errors in array
         | 
| 55 | 
            -
                #
         | 
| 56 | 
            -
                # @param array [Array] array to iterate
         | 
| 57 | 
            -
                def split_array_errors(array)
         | 
| 58 | 
            -
                  array.each_with_index { |_e, i| verify_type array[i] }
         | 
| 59 | 
            -
                end
         | 
| 60 | 
            -
             | 
| 61 | 
            -
                # Iterates through errors in hash
         | 
| 62 | 
            -
                #
         | 
| 63 | 
            -
                # @param hash [Hash] hash to iterate
         | 
| 64 | 
            -
                def split_hash_errors(hash)
         | 
| 65 | 
            -
                  message = []
         | 
| 66 | 
            -
                  hash.each { |k, v| message << "#{k}: #{v}" }
         | 
| 67 | 
            -
                  @errors << message.flatten.join(' with ')
         | 
| 68 | 
            -
                end
         | 
| 69 11 | 
             
              end
         | 
| 70 12 |  | 
| 71 13 | 
             
              # Raised when Brandwatch returns a 400 HTTP status code
         | 
    
        metadata
    CHANGED
    
    | @@ -1,113 +1,113 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: bw_status_board_api
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0 | 
| 4 | 
            +
              version: 1.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jonathan Chrisp
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-10-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rspec
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - ~>
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: 3.0.0
         | 
| 20 20 | 
             
              type: :development
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - - ~>
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: 3.0.0
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: rubocop
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - - ~>
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 33 | 
             
                    version: 0.24.1
         | 
| 34 34 | 
             
              type: :development
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 | 
            -
                - - ~>
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: 0.24.1
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: allotment
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 | 
            -
                - - ~>
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 47 | 
             
                    version: 1.1.0
         | 
| 48 48 | 
             
              type: :runtime
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 | 
            -
                - - ~>
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 54 | 
             
                    version: 1.1.0
         | 
| 55 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 56 | 
             
              name: faraday
         | 
| 57 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 58 | 
             
                requirements:
         | 
| 59 | 
            -
                - - ~>
         | 
| 59 | 
            +
                - - "~>"
         | 
| 60 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 61 | 
             
                    version: 0.9.0
         | 
| 62 62 | 
             
              type: :runtime
         | 
| 63 63 | 
             
              prerelease: false
         | 
| 64 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 65 | 
             
                requirements:
         | 
| 66 | 
            -
                - - ~>
         | 
| 66 | 
            +
                - - "~>"
         | 
| 67 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 68 | 
             
                    version: 0.9.0
         | 
| 69 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 70 | 
             
              name: faraday_middleware
         | 
| 71 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 72 | 
             
                requirements:
         | 
| 73 | 
            -
                - - ~>
         | 
| 73 | 
            +
                - - "~>"
         | 
| 74 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| 75 75 | 
             
                    version: 0.9.1
         | 
| 76 76 | 
             
              type: :runtime
         | 
| 77 77 | 
             
              prerelease: false
         | 
| 78 78 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 79 | 
             
                requirements:
         | 
| 80 | 
            -
                - - ~>
         | 
| 80 | 
            +
                - - "~>"
         | 
| 81 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 82 | 
             
                    version: 0.9.1
         | 
| 83 83 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 84 84 | 
             
              name: faraday_middleware-parse_oj
         | 
| 85 85 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 86 | 
             
                requirements:
         | 
| 87 | 
            -
                - - ~>
         | 
| 87 | 
            +
                - - "~>"
         | 
| 88 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 89 | 
             
                    version: 0.3.0
         | 
| 90 90 | 
             
              type: :runtime
         | 
| 91 91 | 
             
              prerelease: false
         | 
| 92 92 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 93 | 
             
                requirements:
         | 
| 94 | 
            -
                - - ~>
         | 
| 94 | 
            +
                - - "~>"
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 96 | 
             
                    version: 0.3.0
         | 
| 97 97 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 98 98 | 
             
              name: oj
         | 
| 99 99 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 100 | 
             
                requirements:
         | 
| 101 | 
            -
                - - ~>
         | 
| 101 | 
            +
                - - "~>"
         | 
| 102 102 | 
             
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            -
                    version: 2.10. | 
| 103 | 
            +
                    version: 2.10.3
         | 
| 104 104 | 
             
              type: :runtime
         | 
| 105 105 | 
             
              prerelease: false
         | 
| 106 106 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 107 | 
             
                requirements:
         | 
| 108 | 
            -
                - - ~>
         | 
| 108 | 
            +
                - - "~>"
         | 
| 109 109 | 
             
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            -
                    version: 2.10. | 
| 110 | 
            +
                    version: 2.10.3
         | 
| 111 111 | 
             
            description: A Ruby wrapper for the Brandwatch Status Board
         | 
| 112 112 | 
             
            email: jonathan@brandwatch.com
         | 
| 113 113 | 
             
            executables:
         | 
| @@ -115,9 +115,9 @@ executables: | |
| 115 115 | 
             
            extensions: []
         | 
| 116 116 | 
             
            extra_rdoc_files: []
         | 
| 117 117 | 
             
            files:
         | 
| 118 | 
            -
            - .editorconfig
         | 
| 119 | 
            -
            - .gitignore
         | 
| 120 | 
            -
            - .rubocop.yml
         | 
| 118 | 
            +
            - ".editorconfig"
         | 
| 119 | 
            +
            - ".gitignore"
         | 
| 120 | 
            +
            - ".rubocop.yml"
         | 
| 121 121 | 
             
            - CHANGELOG.md
         | 
| 122 122 | 
             
            - CONTRIBUTING.md
         | 
| 123 123 | 
             
            - Gemfile
         | 
| @@ -126,8 +126,11 @@ files: | |
| 126 126 | 
             
            - bw_status_board_api.gemspec
         | 
| 127 127 | 
             
            - lib/bw_status_board_api.rb
         | 
| 128 128 | 
             
            - lib/bw_status_board_api/client.rb
         | 
| 129 | 
            +
            - lib/bw_status_board_api/client/boards.rb
         | 
| 129 130 | 
             
            - lib/bw_status_board_api/client/environments.rb
         | 
| 130 131 | 
             
            - lib/bw_status_board_api/client/environments/services.rb
         | 
| 132 | 
            +
            - lib/bw_status_board_api/client/helpers/filter.rb
         | 
| 133 | 
            +
            - lib/bw_status_board_api/client/metrics.rb
         | 
| 131 134 | 
             
            - lib/bw_status_board_api/configuration.rb
         | 
| 132 135 | 
             
            - lib/bw_status_board_api/connection.rb
         | 
| 133 136 | 
             
            - lib/bw_status_board_api/default.rb
         | 
| @@ -150,17 +153,17 @@ require_paths: | |
| 150 153 | 
             
            - lib
         | 
| 151 154 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 152 155 | 
             
              requirements:
         | 
| 153 | 
            -
              - -  | 
| 156 | 
            +
              - - ">="
         | 
| 154 157 | 
             
                - !ruby/object:Gem::Version
         | 
| 155 158 | 
             
                  version: 1.9.2
         | 
| 156 159 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 157 160 | 
             
              requirements:
         | 
| 158 | 
            -
              - -  | 
| 161 | 
            +
              - - ">="
         | 
| 159 162 | 
             
                - !ruby/object:Gem::Version
         | 
| 160 163 | 
             
                  version: '0'
         | 
| 161 164 | 
             
            requirements: []
         | 
| 162 165 | 
             
            rubyforge_project: 
         | 
| 163 | 
            -
            rubygems_version: 2. | 
| 166 | 
            +
            rubygems_version: 2.2.2
         | 
| 164 167 | 
             
            signing_key: 
         | 
| 165 168 | 
             
            specification_version: 4
         | 
| 166 169 | 
             
            summary: Brandwatch Status Board API Wrapper
         |