sirportly 1.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.
- data/lib/sirportly.rb +41 -0
- data/lib/sirportly/knowledge_base.rb +54 -0
- data/lib/sirportly/objects.rb +47 -0
- data/lib/sirportly/request.rb +72 -0
- data/lib/sirportly/ticket.rb +27 -0
- metadata +49 -0
    
        data/lib/sirportly.rb
    ADDED
    
    | @@ -0,0 +1,41 @@ | |
| 1 | 
            +
            require 'uri'
         | 
| 2 | 
            +
            require 'net/https'
         | 
| 3 | 
            +
            require 'json'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            require 'sirportly/request'
         | 
| 6 | 
            +
            require 'sirportly/ticket'
         | 
| 7 | 
            +
            require 'sirportly/knowledge_base'
         | 
| 8 | 
            +
            require 'sirportly/objects'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            module Sirportly
         | 
| 11 | 
            +
              class << self
         | 
| 12 | 
            +
                
         | 
| 13 | 
            +
                ## Returns the current version number for the Sirportly API client.
         | 
| 14 | 
            +
                def version
         | 
| 15 | 
            +
                  "1.0.0-beta"
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
                
         | 
| 18 | 
            +
                ## Stores authentication details
         | 
| 19 | 
            +
                attr_accessor :token
         | 
| 20 | 
            +
                attr_accessor :secret
         | 
| 21 | 
            +
                
         | 
| 22 | 
            +
                ## Allow the domain to be changed
         | 
| 23 | 
            +
                attr_writer :domain
         | 
| 24 | 
            +
                
         | 
| 25 | 
            +
                ## Returns the domain which should be used to query the API
         | 
| 26 | 
            +
                def domain
         | 
| 27 | 
            +
                  @domain ||= 'https://app.sirportly.com'
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
                
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
              
         | 
| 32 | 
            +
              ## Various error classes to raise
         | 
| 33 | 
            +
              class Error < StandardError; end
         | 
| 34 | 
            +
              module Errors
         | 
| 35 | 
            +
                class ServiceUnavailable < Error; end
         | 
| 36 | 
            +
                class AccessDenied < Error; end
         | 
| 37 | 
            +
                class NotFound < Error; end
         | 
| 38 | 
            +
                class CommunicationError < Error; end
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
              
         | 
| 41 | 
            +
            end
         | 
| @@ -0,0 +1,54 @@ | |
| 1 | 
            +
            module Sirportly
         | 
| 2 | 
            +
              class KnowledgeBase
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                attr_accessor :id
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                class << self
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def list
         | 
| 9 | 
            +
                    Request.request('knowledge/list')
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def find_by_id(id)
         | 
| 13 | 
            +
                    Request.request('knowledge/tree', :kb => id)
         | 
| 14 | 
            +
                    self.new(id)
         | 
| 15 | 
            +
                  rescue Errors::NotFound
         | 
| 16 | 
            +
                    false
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def initialize(id)
         | 
| 22 | 
            +
                  self.id = id
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def page(path)
         | 
| 26 | 
            +
                  request('page', :path => path)
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def tree
         | 
| 30 | 
            +
                  request('tree')
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def add_page(options = {})
         | 
| 34 | 
            +
                  request('add_page', options)
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def edit_page(path, options = {})
         | 
| 38 | 
            +
                  options[:path] = path
         | 
| 39 | 
            +
                  request('edit_page', options)
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                def delete_page(path)
         | 
| 43 | 
            +
                  request('delete_page', :path => path)
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
                
         | 
| 46 | 
            +
                private
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                def request(path, options = {})
         | 
| 49 | 
            +
                  options[:kb] = self.id
         | 
| 50 | 
            +
                  Request.request('knowledge/'+path, options)
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
            end
         | 
| @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            module Sirportly
         | 
| 2 | 
            +
              class Objects
         | 
| 3 | 
            +
                class << self
         | 
| 4 | 
            +
                  
         | 
| 5 | 
            +
                  def statuses
         | 
| 6 | 
            +
                    Request.request('objects/statuses')
         | 
| 7 | 
            +
                  end
         | 
| 8 | 
            +
                  
         | 
| 9 | 
            +
                  def priorities
         | 
| 10 | 
            +
                    Request.request('objects/priorities')
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                  
         | 
| 13 | 
            +
                  def users
         | 
| 14 | 
            +
                    Request.request('objects/users')
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                  
         | 
| 17 | 
            +
                  def teams
         | 
| 18 | 
            +
                    Request.request('objects/teams')
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                  
         | 
| 21 | 
            +
                  def brands
         | 
| 22 | 
            +
                    Request.request('objects/brands')
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                  
         | 
| 25 | 
            +
                  def departments(brand_id = nil)
         | 
| 26 | 
            +
                    if brand_id
         | 
| 27 | 
            +
                      begin
         | 
| 28 | 
            +
                        Request.request('objects/departments', :brand_id => brand_id.to_i)
         | 
| 29 | 
            +
                      rescue Errors::NotFound
         | 
| 30 | 
            +
                        false
         | 
| 31 | 
            +
                      end
         | 
| 32 | 
            +
                    else
         | 
| 33 | 
            +
                      Request.request('objects/departments')
         | 
| 34 | 
            +
                    end
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                  
         | 
| 37 | 
            +
                  def escalation_paths
         | 
| 38 | 
            +
                    Request.request('objects/escalation_paths')
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
                  
         | 
| 41 | 
            +
                  def slas
         | 
| 42 | 
            +
                    Request.request('objects/slas')
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
                  
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
| @@ -0,0 +1,72 @@ | |
| 1 | 
            +
            module Sirportly
         | 
| 2 | 
            +
              class Request
         | 
| 3 | 
            +
                
         | 
| 4 | 
            +
                def self.request(path, data = {})
         | 
| 5 | 
            +
                  req = self.new(path, :post)
         | 
| 6 | 
            +
                  req.data = data
         | 
| 7 | 
            +
                  req.make && req.success? ? req.output : false
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
                
         | 
| 10 | 
            +
                attr_reader :path, :method
         | 
| 11 | 
            +
                attr_accessor :data
         | 
| 12 | 
            +
                
         | 
| 13 | 
            +
                def initialize(path, method = :get)
         | 
| 14 | 
            +
                  @path = path
         | 
| 15 | 
            +
                  @method = method
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
                
         | 
| 18 | 
            +
                def success?
         | 
| 19 | 
            +
                  @success || false
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
                
         | 
| 22 | 
            +
                def output
         | 
| 23 | 
            +
                  @output || nil
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
                
         | 
| 26 | 
            +
                def make
         | 
| 27 | 
            +
                  uri = URI.parse([Sirportly.domain, "api/v1", @path].join('/'))
         | 
| 28 | 
            +
                  http_request = http_class.new(uri.request_uri)
         | 
| 29 | 
            +
                  http_request.add_field("X-Auth-Token", Sirportly.token)
         | 
| 30 | 
            +
                  http_request.add_field("X-Auth-Secret", Sirportly.secret)
         | 
| 31 | 
            +
                  http_request.set_form_data(@data)
         | 
| 32 | 
            +
                  
         | 
| 33 | 
            +
                  http = Net::HTTP.new(uri.host, uri.port)
         | 
| 34 | 
            +
                  
         | 
| 35 | 
            +
                  if uri.scheme == 'https'
         | 
| 36 | 
            +
                    http.use_ssl = true
         | 
| 37 | 
            +
                    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
                  
         | 
| 40 | 
            +
                  http_result = http.request(http_request)
         | 
| 41 | 
            +
                  @output = JSON.parse(http_result.body)
         | 
| 42 | 
            +
                  @success = case http_result
         | 
| 43 | 
            +
                  when Net::HTTPSuccess
         | 
| 44 | 
            +
                    true
         | 
| 45 | 
            +
                  when Net::HTTPServiceUnavailable
         | 
| 46 | 
            +
                    raise Sirportly::Errors::ServiceUnavailable
         | 
| 47 | 
            +
                  when Net::HTTPForbidden, Net::HTTPUnauthorized
         | 
| 48 | 
            +
                    raise Sirportly::Errors::AccessDenied, "Access Denied for '#{Sirportly.token}'"
         | 
| 49 | 
            +
                  when Net::HTTPNotFound
         | 
| 50 | 
            +
                    raise Sirportly::Errors::NotFound, "Not Found at #{uri.to_s}"
         | 
| 51 | 
            +
                  when Net::HTTPClientError
         | 
| 52 | 
            +
                    @output
         | 
| 53 | 
            +
                  else
         | 
| 54 | 
            +
                    raise Sirportly::Errors::CommunicationError, http_result.body
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
                  self
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
                
         | 
| 59 | 
            +
                private
         | 
| 60 | 
            +
                
         | 
| 61 | 
            +
                def http_class  
         | 
| 62 | 
            +
                  case @method
         | 
| 63 | 
            +
                  when :post    then Net::HTTP::Post
         | 
| 64 | 
            +
                  when :put     then Net::HTTP::Put
         | 
| 65 | 
            +
                  when :delete  then Net::HTTP::Delete
         | 
| 66 | 
            +
                  else
         | 
| 67 | 
            +
                    Net::HTTP::Get
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
                
         | 
| 71 | 
            +
              end
         | 
| 72 | 
            +
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            module Sirportly
         | 
| 2 | 
            +
              class Ticket
         | 
| 3 | 
            +
                
         | 
| 4 | 
            +
                class << self
         | 
| 5 | 
            +
                
         | 
| 6 | 
            +
                  def find_by_reference(reference)
         | 
| 7 | 
            +
                    Request.request('tickets/ticket', :reference => reference)
         | 
| 8 | 
            +
                  rescue Errors::NotFound
         | 
| 9 | 
            +
                    false
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
                
         | 
| 12 | 
            +
                  def execute_spql(query)
         | 
| 13 | 
            +
                    Request.request('tickets/spql', :spql => query)
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                  
         | 
| 16 | 
            +
                  def submit(options)
         | 
| 17 | 
            +
                    Request.request('tickets/submit', options)
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                  
         | 
| 20 | 
            +
                  def update(reference, options)
         | 
| 21 | 
            +
                    options.merge!(:ticket => reference)
         | 
| 22 | 
            +
                    Request.request('tickets/post_update', options)
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                  
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: sirportly
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 1.0.0
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
            platform: ruby
         | 
| 7 | 
            +
            authors:
         | 
| 8 | 
            +
            - Adam Cooke
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
            date: 2012-01-26 00:00:00.000000000Z
         | 
| 13 | 
            +
            dependencies: []
         | 
| 14 | 
            +
            description: 
         | 
| 15 | 
            +
            email: adam@atechmedia.com
         | 
| 16 | 
            +
            executables: []
         | 
| 17 | 
            +
            extensions: []
         | 
| 18 | 
            +
            extra_rdoc_files: []
         | 
| 19 | 
            +
            files:
         | 
| 20 | 
            +
            - lib/sirportly.rb
         | 
| 21 | 
            +
            - lib/sirportly/knowledge_base.rb
         | 
| 22 | 
            +
            - lib/sirportly/objects.rb
         | 
| 23 | 
            +
            - lib/sirportly/request.rb
         | 
| 24 | 
            +
            - lib/sirportly/ticket.rb
         | 
| 25 | 
            +
            homepage: http://www.sirportly.com
         | 
| 26 | 
            +
            licenses: []
         | 
| 27 | 
            +
            post_install_message: 
         | 
| 28 | 
            +
            rdoc_options: []
         | 
| 29 | 
            +
            require_paths:
         | 
| 30 | 
            +
            - lib
         | 
| 31 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 32 | 
            +
              none: false
         | 
| 33 | 
            +
              requirements:
         | 
| 34 | 
            +
              - - ! '>='
         | 
| 35 | 
            +
                - !ruby/object:Gem::Version
         | 
| 36 | 
            +
                  version: '0'
         | 
| 37 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 38 | 
            +
              none: false
         | 
| 39 | 
            +
              requirements:
         | 
| 40 | 
            +
              - - ! '>='
         | 
| 41 | 
            +
                - !ruby/object:Gem::Version
         | 
| 42 | 
            +
                  version: '0'
         | 
| 43 | 
            +
            requirements: []
         | 
| 44 | 
            +
            rubyforge_project: 
         | 
| 45 | 
            +
            rubygems_version: 1.8.10
         | 
| 46 | 
            +
            signing_key: 
         | 
| 47 | 
            +
            specification_version: 3
         | 
| 48 | 
            +
            summary: Easy to use client library for Sirportly
         | 
| 49 | 
            +
            test_files: []
         |