Class: Zanshin::SDK::Client

Inherits:
Object
  • Object
show all
Includes:
Account, Alerts, OrganizationFollowers, OrganizationFollowing, OrganizationMembers, OrganizationScanTargets, Organizations, Summaries
Defined in:
lib/zanshin/client.rb

Overview

Zanshin SDK Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Summaries

#get_alert_summaries, #get_following_alert_summaries, #get_following_scan_summaries, #get_scan_summaries

Methods included from OrganizationScanTargets

#check_organization_scan_target, #create_organization_scan_target, #delete_organization_scan_target, #get_organization_scan_target, #get_organization_scan_target_scan, #iter_organization_scan_target_scans, #iter_organization_scan_targets, #start_organization_scan_target_scan, #stop_organization_scan_target_scan, #update_organization_scan_target

Methods included from OrganizationMembers

#create_organization_members_invite, #delete_organization_member, #delete_organization_member_invite, #get_organization_member, #get_organization_member_invite, #iter_organization_members, #iter_organization_members_invites, #resend_organization_member_invite, #reset_organization_member_mfa, #reset_organization_member_password, #update_organization_member

Methods included from OrganizationFollowing

#accept_organization_following_request, #decline_organization_following_request, #get_organization_following_request, #iter_organization_following, #iter_organization_following_requests, #stop_organization_following

Methods included from OrganizationFollowers

#create_organization_follower_request, #delete_organization_follower_request, #get_organization_follower_request, #iter_organization_follower_requests, #iter_organization_followers, #stop_organization_follower

Methods included from Organizations

#get_organization, #iter_organizations, #update_organization

Methods included from Alerts

#create_alert_comment, #get_alert, #iter_alert_comments, #iter_alert_history, #iter_alerts, #iter_alerts_following_history, #iter_alerts_history, #iter_following_alerts, #iter_grouped_alerts, #iter_grouped_following_alerts, #update_alert

Methods included from Account

#accept_invite, #create_api_key, #delete_api_key, #get_invite, #get_me, #iter_api_keys, #iter_invites

Constructor Details

#initialize(profile, api_key, api_url, user_agent, proxy_url) ⇒ Client

Initialize a new Zanshin SDK instance

Parameters:

  • profile (String)

    Which configuration file section to use for settings

  • api_key (String)

    Optional override of the API key to use

  • api_url (String)

    Optional override of the base URL of the Zanshin API to use

  • user_agent (String)

    Optional addition of the user agent to use in requests performed

  • proxy_url (String)

    Optional URL indicating which proxy server to use


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/zanshin/client.rb', line 74

def initialize(profile: 'default',
               api_key: ENV.fetch('ZANSHIN_API_KEY', nil),
               api_url: ENV.fetch('ZANSHIN_API_URL', nil) || ZANSHIN_API,
               user_agent: ENV.fetch('ZANSHIN_USER_AGENT', nil),
               proxy_url: ENV.fetch('HTTP_PROXY', ENV.fetch('HTTPS_PROXY', nil)))
  @logger = Logger.new($stdout)
  @logger.level = Logger::WARN

  config = get_config(profile)

  @api_key = api_key || config['api_key'] || raise('No API key found')
  @api_url = validate_url(api_url || config['api_url'])
  @user_agent = add_sdk_agent(user_agent || config['user_agent'])
  @proxy_url = validate_proxy(proxy_url || config['proxy_url'])

  update_request
  @logger.debug('Zanshin SDK Initialized')
end

Instance Attribute Details

#api_keyObject #api_key=(value) ⇒ Object

Overloads:

  • #api_keyObject

    Gets the current value of api_key

    Returns:

    • api_key

  • #api_key=(value) ⇒ Object

    Sets the api_key

    Parameters:

    • the (value)

      new api_key


36
37
38
# File 'lib/zanshin/client.rb', line 36

def api_key
  @api_key
end

#api_urlObject #api_url=(value) ⇒ Object

Overloads:

  • #api_urlObject

    Gets the current value of api_url

    Returns:

    • api_url

  • #api_url=(value) ⇒ Object

    Sets the api_url

    Parameters:

    • the (value)

      new api_url


43
44
45
# File 'lib/zanshin/client.rb', line 43

def api_url
  @api_url
end

#httpObject #http=(`: HTTPClient`) ⇒ Object

Overloads:

  • #httpObject

    Gets the current value of http

    Returns:

    • http

  • #http=(`: HTTPClient`) ⇒ Object

    Sets the http

    Parameters:

    • the (value)

      new http


65
66
67
# File 'lib/zanshin/client.rb', line 65

def http
  @http
end

#proxy_urlObject #proxy_url=(value) ⇒ Object

Overloads:

  • #proxy_urlObject

    Gets the current value of proxy_url

    Returns:

    • proxy_url

  • #proxy_url=(value) ⇒ Object

    Sets the proxy_url

    Parameters:

    • the (value)

      new proxy_url


57
58
59
# File 'lib/zanshin/client.rb', line 57

def proxy_url
  @proxy_url
end

#user_agentObject #user_agent=(value) ⇒ Object

Overloads:

  • #user_agentObject

    Gets the current value of user_agent

    Returns:

    • user_agent

  • #user_agent=(value) ⇒ Object

    Sets the user_agent

    Parameters:

    • the (value)

      new user_agent


50
51
52
# File 'lib/zanshin/client.rb', line 50

def user_agent
  @user_agent
end