seer-rb 0.1
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 +7 -0
- data/README.md +61 -0
- data/lib/environment.rb +12 -0
- data/lib/seer.rb +22 -0
- data/lib/seer/dns.rb +35 -0
- data/lib/seer/hosts.rb +93 -0
- data/lib/seer/org.rb +37 -0
- data/lib/seer/status.rb +32 -0
- data/lib/seer/version.rb +20 -0
- data/seer-rb.gemspec +14 -0
- metadata +54 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 74e195941b3642297ccac3ca04b9ba165286db6f
         | 
| 4 | 
            +
              data.tar.gz: 5e6db0e02a5e50914c29e78bbfab9e909af0ed27
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 91eba63a80bb0e2b6fcf4654359b356ab085c519be6241bf5a5dd89a787c066752e0a610a8d19ec31f7dea03e8124c97f4232f5c5594518f06ba11c4b3909525
         | 
| 7 | 
            +
              data.tar.gz: 6d8de23a8cd6f69658d9b35e821b25821a22fc3c46ed296671f09c443eb9215ef0bbfbc90a27e756a7d9c71b40ae48204bf5c94da568e3c59c6f27824dfacf22
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,61 @@ | |
| 1 | 
            +
            # seer-rb
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Ruby SDK for SEER API
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Example
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ### Host query
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            #### Register with API token
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ```ruby
         | 
| 12 | 
            +
            seer = Seer::Hosts.new(token: api_token, host: api_host)
         | 
| 13 | 
            +
            ```
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            #### Get host information by IP
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ```ruby
         | 
| 18 | 
            +
            host = seer.ip(ip)
         | 
| 19 | 
            +
            ```
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            #### Get host information by custom search syntax
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ```ruby
         | 
| 24 | 
            +
            host = seer.search(query, return_field)
         | 
| 25 | 
            +
            ```
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            #### Get hosts by port
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            ```ruby
         | 
| 30 | 
            +
            hosts = seer.port(port)
         | 
| 31 | 
            +
            ```
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            ### Domain query
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            #### Register with API token
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            ```ruby
         | 
| 38 | 
            +
            seer = Seer::DNS.new(token: api_token, host: api_host)
         | 
| 39 | 
            +
            ```
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            #### Get type A record by IP
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            ```ruby
         | 
| 44 | 
            +
            seer.ip(ip)
         | 
| 45 | 
            +
            ```
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            #### Get type A record by domain
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            ```ruby
         | 
| 50 | 
            +
            seer.domain(domain)
         | 
| 51 | 
            +
            ```
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            ## Installation
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            ```
         | 
| 56 | 
            +
            gem install seer-rb
         | 
| 57 | 
            +
            ```
         | 
| 58 | 
            +
             | 
| 59 | 
            +
            ```
         | 
| 60 | 
            +
            gem "seer-rb"
         | 
| 61 | 
            +
            ```
         | 
    
        data/lib/environment.rb
    ADDED
    
    
    
        data/lib/seer.rb
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            require 'environment'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # SEER API Wrapper
         | 
| 4 | 
            +
            # @author ztz <ztz@ztz.me>
         | 
| 5 | 
            +
            # @version 0.1
         | 
| 6 | 
            +
            module Seer
         | 
| 7 | 
            +
              # Send request to SEER API
         | 
| 8 | 
            +
              # @param url [String] Request url
         | 
| 9 | 
            +
              # @param body [String] Request body
         | 
| 10 | 
            +
              # @param header [Hash] Request hash
         | 
| 11 | 
            +
              # @return [Hash]
         | 
| 12 | 
            +
              def request(url, body, header)
         | 
| 13 | 
            +
                response = RestClient.post(
         | 
| 14 | 
            +
                  url,
         | 
| 15 | 
            +
                  JSON.dump(body),
         | 
| 16 | 
            +
                  header
         | 
| 17 | 
            +
                )
         | 
| 18 | 
            +
                JSON.load response
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              module_function :request
         | 
| 22 | 
            +
            end
         | 
    
        data/lib/seer/dns.rb
    ADDED
    
    | @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            module Seer
         | 
| 2 | 
            +
              # DNS API controller
         | 
| 3 | 
            +
              class DNS
         | 
| 4 | 
            +
                # Initialize a DNS object
         | 
| 5 | 
            +
                # @param token [string] API token
         | 
| 6 | 
            +
                # @param version [string] API version you want use (defaut 1)
         | 
| 7 | 
            +
                # @param host [string] API host
         | 
| 8 | 
            +
                def initialize(token: '', version: '1', host: '')
         | 
| 9 | 
            +
                  @host = host + '/dns'
         | 
| 10 | 
            +
                  @header = {
         | 
| 11 | 
            +
                    content_type: 'application/json',
         | 
| 12 | 
            +
                    accept: "application/seer+json;version=#{version}",
         | 
| 13 | 
            +
                    x_seer_token: token
         | 
| 14 | 
            +
                  }
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                # Get ip from domain
         | 
| 18 | 
            +
                # @param domain [string]
         | 
| 19 | 
            +
                # @return [Hash] Result
         | 
| 20 | 
            +
                def domain(domain)
         | 
| 21 | 
            +
                  body = { domain: domain }
         | 
| 22 | 
            +
                  url = @host + '/domain'
         | 
| 23 | 
            +
                  Seer.request(url, body, @header)
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                # Get domain by ip
         | 
| 27 | 
            +
                # @param ip [String]
         | 
| 28 | 
            +
                # @return [Hash] Result
         | 
| 29 | 
            +
                def ip(ip)
         | 
| 30 | 
            +
                  body = { ip: ip }
         | 
| 31 | 
            +
                  url = @host + '/ip'
         | 
| 32 | 
            +
                  Seer.request(url, body, @header)
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
    
        data/lib/seer/hosts.rb
    ADDED
    
    | @@ -0,0 +1,93 @@ | |
| 1 | 
            +
            module Seer
         | 
| 2 | 
            +
              # Hosts API controller
         | 
| 3 | 
            +
              class Hosts
         | 
| 4 | 
            +
                # Initialize a Hosts object
         | 
| 5 | 
            +
                # @param token [string] API token
         | 
| 6 | 
            +
                # @param version [string] API version you want use (defaut 1)
         | 
| 7 | 
            +
                # @param host [string] API host
         | 
| 8 | 
            +
                def initialize(token: '', version: '1', host: '')
         | 
| 9 | 
            +
                  @host = host + '/hosts'
         | 
| 10 | 
            +
                  @header = {
         | 
| 11 | 
            +
                    content_type: 'application/json',
         | 
| 12 | 
            +
                    accept: "application/seer+json;version=#{version}",
         | 
| 13 | 
            +
                    x_seer_token: token
         | 
| 14 | 
            +
                  }
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                # Get host by ip
         | 
| 18 | 
            +
                # @param ip [String] IP Address
         | 
| 19 | 
            +
                # @param minify [Boolean] Only return IP address (default false)
         | 
| 20 | 
            +
                # @return [Hash] Result
         | 
| 21 | 
            +
                def ip(ip, minify: false)
         | 
| 22 | 
            +
                  body = {
         | 
| 23 | 
            +
                    ip: ip,
         | 
| 24 | 
            +
                    minify: minify
         | 
| 25 | 
            +
                  }
         | 
| 26 | 
            +
                  url = @host + '/ip'
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  Seer.request(url, body, @header)
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                # Get hosts by port
         | 
| 32 | 
            +
                # @param port [Fixnum] Port you want to search
         | 
| 33 | 
            +
                # @param page [Fixnum] The page of results
         | 
| 34 | 
            +
                # @param minify [Boolean] Only return IP address (default false)
         | 
| 35 | 
            +
                # @return [Hash] Result
         | 
| 36 | 
            +
                def port(port, page: 1, minify: false)
         | 
| 37 | 
            +
                  body = {
         | 
| 38 | 
            +
                    port: port,
         | 
| 39 | 
            +
                    page: page,
         | 
| 40 | 
            +
                    minify: minify
         | 
| 41 | 
            +
                  }
         | 
| 42 | 
            +
                  url = @host + '/port'
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  Seer.request(url, body, @header)
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                # Get hosts by service
         | 
| 48 | 
            +
                # @param service [String] Service you want to search
         | 
| 49 | 
            +
                # @param page [Fixnum] The page of results
         | 
| 50 | 
            +
                # @param minify [Boolean] Only return IP address (default false)
         | 
| 51 | 
            +
                # @return [Hash] Result
         | 
| 52 | 
            +
                def service(service, page: 1, minify: false)
         | 
| 53 | 
            +
                  body = {
         | 
| 54 | 
            +
                    service: service,
         | 
| 55 | 
            +
                    page: page,
         | 
| 56 | 
            +
                    minify: minify
         | 
| 57 | 
            +
                  }
         | 
| 58 | 
            +
                  url = @host + '/service'
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  Seer.request(url, body, @header)
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                # Get hosts by custom search
         | 
| 64 | 
            +
                # @param query [String] Custom query
         | 
| 65 | 
            +
                # @param page [Fixnum] The page of results
         | 
| 66 | 
            +
                # @param minify [Boolean] Only return IP address (default false)
         | 
| 67 | 
            +
                # @return [Hash] Result
         | 
| 68 | 
            +
                def search(query, page: 1, minify: false)
         | 
| 69 | 
            +
                  body = {
         | 
| 70 | 
            +
                    query: query,
         | 
| 71 | 
            +
                    page: page,
         | 
| 72 | 
            +
                    minify: minify
         | 
| 73 | 
            +
                  }
         | 
| 74 | 
            +
                  url = @host + '/search'
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                  Seer.request(url, body, @header)
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                # Aggregations by query and field
         | 
| 80 | 
            +
                # @param query [String] Custom query
         | 
| 81 | 
            +
                # @param fields [String] The field you want to aggs
         | 
| 82 | 
            +
                # @return [Hash] Result
         | 
| 83 | 
            +
                def aggs(query, fields)
         | 
| 84 | 
            +
                  body = {
         | 
| 85 | 
            +
                    query: query,
         | 
| 86 | 
            +
                    fields: fields
         | 
| 87 | 
            +
                  }
         | 
| 88 | 
            +
                  url = @host + '/aggs'
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                  Seer.request(url, body, @header)
         | 
| 91 | 
            +
                end
         | 
| 92 | 
            +
              end
         | 
| 93 | 
            +
            end
         | 
    
        data/lib/seer/org.rb
    ADDED
    
    | @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            module Seer
         | 
| 2 | 
            +
              # ORG API controller
         | 
| 3 | 
            +
              class Org
         | 
| 4 | 
            +
                # Initialize a Org object
         | 
| 5 | 
            +
                # @param token [string]  API token
         | 
| 6 | 
            +
                # @param version [string] :version ('1') API version you want use (defaut 1)
         | 
| 7 | 
            +
                # @param host [string] API host (default http://seer.intra.nsfocus.com:8000/api)
         | 
| 8 | 
            +
                def initialize(token: '', version: '1', host: '')
         | 
| 9 | 
            +
                  @host = host + '/org'
         | 
| 10 | 
            +
                  @header = {
         | 
| 11 | 
            +
                    content_type: 'application/json',
         | 
| 12 | 
            +
                    accept: "application/seer+json;version=#{version}",
         | 
| 13 | 
            +
                    x_seer_token: token
         | 
| 14 | 
            +
                  }
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                # Get organization by ip
         | 
| 18 | 
            +
                # @param ip [String] IP address for search
         | 
| 19 | 
            +
                # @return [Hash] Result
         | 
| 20 | 
            +
                def ip(ip)
         | 
| 21 | 
            +
                  body = { ip: ip }
         | 
| 22 | 
            +
                  url = @host + '/ip'
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  Seer.request(url, body, @header)
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                # Get organization by AS number
         | 
| 28 | 
            +
                # @param asn [Fixnum] AS number
         | 
| 29 | 
            +
                # @return [Hash] Result
         | 
| 30 | 
            +
                def asn(asn)
         | 
| 31 | 
            +
                  body = { asn: asn }
         | 
| 32 | 
            +
                  url = @host + '/asn'
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  Seer.request(url, body, @header)
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
            end
         | 
    
        data/lib/seer/status.rb
    ADDED
    
    | @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            module Seer
         | 
| 2 | 
            +
              # Status API controller
         | 
| 3 | 
            +
              class Status
         | 
| 4 | 
            +
                # Initialize a Status object
         | 
| 5 | 
            +
                # @param token [string] API token
         | 
| 6 | 
            +
                # @param version [string] :version ('1') API version you want use (defaut 1)
         | 
| 7 | 
            +
                # @param host [string] API host (default http://seer.intra.nsfocus.com:8000/api)
         | 
| 8 | 
            +
                def initialize(token: '', version: '1', host: '')
         | 
| 9 | 
            +
                  @host = host + '/status'
         | 
| 10 | 
            +
                  @header = {
         | 
| 11 | 
            +
                    content_type: 'application/json',
         | 
| 12 | 
            +
                    accept: "application/seer+json;version=#{version}",
         | 
| 13 | 
            +
                    x_seer_token: token
         | 
| 14 | 
            +
                  }
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                # Get SEER supported service
         | 
| 18 | 
            +
                # @param service [String] Return all service that SEER supported
         | 
| 19 | 
            +
                # @return [Hash] Result
         | 
| 20 | 
            +
                def service(service)
         | 
| 21 | 
            +
                  body = { service: service }
         | 
| 22 | 
            +
                  url = @host + '/service'
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  response = RestClient.post(
         | 
| 25 | 
            +
                    url,
         | 
| 26 | 
            +
                    JSON.dump(body),
         | 
| 27 | 
            +
                    @header
         | 
| 28 | 
            +
                  )
         | 
| 29 | 
            +
                  JSON.load response
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
            end
         | 
    
        data/lib/seer/version.rb
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            module Seer
         | 
| 2 | 
            +
              # Version
         | 
| 3 | 
            +
              class Version
         | 
| 4 | 
            +
                # Major version
         | 
| 5 | 
            +
                MAJOR = 0
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                # Minor version
         | 
| 8 | 
            +
                MINOR = 1
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                class << self
         | 
| 11 | 
            +
                  # @return [String]
         | 
| 12 | 
            +
                  def to_s
         | 
| 13 | 
            +
                    [MAJOR, MINOR].compact.join('.')
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                # Version
         | 
| 18 | 
            +
                VERSION = Version.to_s
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
    
        data/seer-rb.gemspec
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            require File.expand_path('../lib/seer/version.rb', __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Gem::Specification.new do |s|
         | 
| 4 | 
            +
              s.author = 'ztz'
         | 
| 5 | 
            +
              s.summary = 'Ruby SDK for SEER API'
         | 
| 6 | 
            +
              s.description = 'Ruby SDK for SEER API'
         | 
| 7 | 
            +
              s.email = %w(seer@nsfocus.com)
         | 
| 8 | 
            +
              s.files = Dir['README.md', 'seer-rb.gemspec', 'lib/**/*']
         | 
| 9 | 
            +
              s.homepage = 'https://github.com/seer-project/seer-rb'
         | 
| 10 | 
            +
              s.license = 'MIT'
         | 
| 11 | 
            +
              s.name = 'seer-rb'
         | 
| 12 | 
            +
              s.require_path = 'lib'
         | 
| 13 | 
            +
              s.version = Seer::Version
         | 
| 14 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,54 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: seer-rb
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: '0.1'
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - ztz
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2015-12-26 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies: []
         | 
| 13 | 
            +
            description: Ruby SDK for SEER API
         | 
| 14 | 
            +
            email:
         | 
| 15 | 
            +
            - seer@nsfocus.com
         | 
| 16 | 
            +
            executables: []
         | 
| 17 | 
            +
            extensions: []
         | 
| 18 | 
            +
            extra_rdoc_files: []
         | 
| 19 | 
            +
            files:
         | 
| 20 | 
            +
            - README.md
         | 
| 21 | 
            +
            - lib/environment.rb
         | 
| 22 | 
            +
            - lib/seer.rb
         | 
| 23 | 
            +
            - lib/seer/dns.rb
         | 
| 24 | 
            +
            - lib/seer/hosts.rb
         | 
| 25 | 
            +
            - lib/seer/org.rb
         | 
| 26 | 
            +
            - lib/seer/status.rb
         | 
| 27 | 
            +
            - lib/seer/version.rb
         | 
| 28 | 
            +
            - seer-rb.gemspec
         | 
| 29 | 
            +
            homepage: https://github.com/seer-project/seer-rb
         | 
| 30 | 
            +
            licenses:
         | 
| 31 | 
            +
            - MIT
         | 
| 32 | 
            +
            metadata: {}
         | 
| 33 | 
            +
            post_install_message: 
         | 
| 34 | 
            +
            rdoc_options: []
         | 
| 35 | 
            +
            require_paths:
         | 
| 36 | 
            +
            - lib
         | 
| 37 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 38 | 
            +
              requirements:
         | 
| 39 | 
            +
              - - ">="
         | 
| 40 | 
            +
                - !ruby/object:Gem::Version
         | 
| 41 | 
            +
                  version: '0'
         | 
| 42 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 43 | 
            +
              requirements:
         | 
| 44 | 
            +
              - - ">="
         | 
| 45 | 
            +
                - !ruby/object:Gem::Version
         | 
| 46 | 
            +
                  version: '0'
         | 
| 47 | 
            +
            requirements: []
         | 
| 48 | 
            +
            rubyforge_project: 
         | 
| 49 | 
            +
            rubygems_version: 2.4.8
         | 
| 50 | 
            +
            signing_key: 
         | 
| 51 | 
            +
            specification_version: 4
         | 
| 52 | 
            +
            summary: Ruby SDK for SEER API
         | 
| 53 | 
            +
            test_files: []
         | 
| 54 | 
            +
            has_rdoc: 
         |