Class: Minisky

Inherits:
Object
  • Object
show all
Includes:
Requests
Defined in:
lib/minisky/errors.rb,
lib/minisky/minisky.rb,
lib/minisky/version.rb,
lib/minisky/requests.rb

Defined Under Namespace

Modules: Requests Classes: AuthError, BadResponse, ClientErrorResponse, Error, ExpiredTokenError, ServerErrorResponse, UnexpectedRedirect, User

Constant Summary collapse

VERSION =
"0.4.0"

Instance Attribute Summary collapse

Attributes included from Requests

#auto_manage_tokens, #default_progress, #send_auth_headers

Instance Method Summary collapse

Methods included from Requests

#base_url, #check_access, #fetch_all, #get_request, #log_in, #perform_token_refresh, #post_request, #reset_tokens, #user

Constructor Details

#initialize(host, config_file, options = {}) ⇒ Minisky

Returns a new instance of Minisky.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/minisky/minisky.rb', line 6

def initialize(host, config_file, options = {})
  @host = host
  @config_file = config_file

  if @config_file
    @config = YAML.load(File.read(@config_file))

    if user.id.nil? || user.pass.nil?
      raise AuthError, "Missing user id or password in the config file #{@config_file}"
    end
  else
    @config = {}
    @send_auth_headers = false
    @auto_manage_tokens = false
  end

  if options
    options.each do |k, v|
      self.send("#{k}=", v)
    end
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/minisky/minisky.rb', line 4

def config
  @config
end

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/minisky/minisky.rb', line 4

def host
  @host
end

Instance Method Details

#save_configObject



29
30
31
# File 'lib/minisky/minisky.rb', line 29

def save_config
  File.write(@config_file, YAML.dump(@config)) if @config_file
end