Class: Minisky
- Inherits:
-
Object
- Object
- Minisky
- Includes:
- Requests
- Defined in:
- lib/minisky/minisky.rb,
lib/minisky/compat.rb,
lib/minisky/errors.rb,
lib/minisky/version.rb,
lib/minisky/requests.rb
Overview
The default API client class for making requests to AT Protocol servers. Can be used
with authentication – with the credentials stored in a YAML file – or without it, for
unauthenticated requests only (by passing nil as the config file name).
Defined Under Namespace
Modules: Requests, Ruby2Compat Classes: AuthError, BadResponse, ClientErrorResponse, Error, ExpiredTokenError, FieldNotSetError, ServerErrorResponse, UnexpectedRedirect, User
Constant Summary collapse
- VERSION =
"0.5.1"- NSID_REGEXP =
Regexp for NSID identifiers, used in lexicon names for record collection and API endpoints
/^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\.[a-zA-Z]([a-zA-Z]{0,61}[a-zA-Z])?)$/
Instance Attribute Summary collapse
-
#config ⇒ Hash
readonly
Loaded contents of the config file.
-
#host ⇒ String
readonly
The hostname (or base URL) of the server.
Attributes included from Requests
#auto_manage_tokens, #default_progress, #send_auth_headers, #stop_fetch_on_empty_page
Instance Method Summary collapse
-
#initialize(host, config_file, options = {}) ⇒ Minisky
constructor
Creates a new client instance.
- #save_config ⇒ Object
Methods included from Requests
#access_token_expired?, #base_url, #check_access, #fetch_all, #get_request, #log_in, #perform_token_refresh, #post_request, #reset_tokens, #token_expiration_date, #user
Methods included from Ruby2Compat
Constructor Details
#initialize(host, config_file, options = {}) ⇒ Minisky
Creates a new client instance.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/minisky/minisky.rb', line 45 def initialize(host, config_file, = {}) @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 = nil end if active_repl? @default_progress = '.' end if .each do |k, v| self.send("#{k}=", v) end end end |
Instance Attribute Details
#config ⇒ Hash (readonly)
Returns loaded contents of the config file.
35 36 37 |
# File 'lib/minisky/minisky.rb', line 35 def config @config end |
#host ⇒ String (readonly)
Returns the hostname (or base URL) of the server.
32 33 34 |
# File 'lib/minisky/minisky.rb', line 32 def host @host end |
Instance Method Details
#save_config ⇒ Object
70 71 72 |
# File 'lib/minisky/minisky.rb', line 70 def save_config File.write(@config_file, YAML.dump(@config)) if @config_file end |