Class: Argonaut::Gateway
- Inherits:
-
Object
- Object
- Argonaut::Gateway
- Defined in:
- lib/argonaut/gateway.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#url_root ⇒ Object
readonly
Returns the value of attribute url_root.
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(api_token:, url_root:) ⇒ Gateway
constructor
Initializes the HTTP gateway to connect to argonaut’s API endpoint The consumer of this API can supply an API token and URL root directly.
- #url_from_path(path) ⇒ Object
Constructor Details
#initialize(api_token:, url_root:) ⇒ Gateway
Initializes the HTTP gateway to connect to argonaut’s API endpoint The consumer of this API can supply an API token and URL root directly. If any of these are not set, information obtained from ~/.argonaut.yml is used. If ~/.argonaut.yml is not found or cannot be read, the environment variables are used. If everything fails, an error is printed to notify the user
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/argonaut/gateway.rb', line 19 def initialize(api_token:, url_root:) if api_token.nil? || api_token.empty? @api_token = config['api_token'] else @api_token = api_token end if url_root.nil? || url_root.empty? @url_root = config['url_root'] else @url_root = url_root end if @url_root.nil? $stderr.puts C::NO_URL_ROOT_ERROR_MESSAGE exit(2) end if @api_token.nil? $stderr.puts C::NO_API_TOKEN_ERROR_MESSAGE exit(2) end end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
8 9 10 |
# File 'lib/argonaut/gateway.rb', line 8 def api_token @api_token end |
#url_root ⇒ Object (readonly)
Returns the value of attribute url_root.
9 10 11 |
# File 'lib/argonaut/gateway.rb', line 9 def url_root @url_root end |
Class Method Details
.load_config_from_file ⇒ Object
83 84 85 86 87 |
# File 'lib/argonaut/gateway.rb', line 83 def self.load_config_from_file YAML.load_file(C::SETTINGS_FILE) rescue nil end |
Instance Method Details
#config ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/argonaut/gateway.rb', line 43 def config return @loaded_config if @loaded_config config_from_file = Argonaut::Gateway.load_config_from_file if config_from_file @loaded_config = config_from_file return @loaded_config end @loaded_config = { 'api_token' => ENV['ARGONAUT_API_TOKEN'], 'url_root' => ENV['ARGONAUT_URL_ROOT'] } if ENV['ARGONAUT_API_TOKEN'].nil? || ENV['ARGONAUT_URL_ROOT'].nil? $stderr.puts C::NO_CONFIG_ERROR_MESSAGE exit(2) end end |
#url_from_path(path) ⇒ Object
63 64 65 66 |
# File 'lib/argonaut/gateway.rb', line 63 def url_from_path(path) # ruby's URI module is shitty, but this should suffice URI.join(@url_root, "/api/readonly/#{path}?token=#{@api_token}").to_s end |