Class: ARest
- Inherits:
-
Object
- Object
- ARest
- Defined in:
- lib/arest.rb
Instance Method Summary collapse
-
#delete(path, **options) ⇒ Object
Perform a HTTP DELETE request.
-
#get(path, **options) ⇒ Object
Perform a HTTP GET request.
-
#initialize(base_url, **options) ⇒ ARest
constructor
Input: * base_url - the base URL for REST API.
- #inspect ⇒ Object
-
#post(path, **options) ⇒ Object
Perform a HTTP POST request.
-
#put(path, **options) ⇒ Object
Perform a HTTP PUT request.
Constructor Details
#initialize(base_url, **options) ⇒ ARest
Input:
-
base_url - the base URL for REST API
Options:
-
headers (Hash) to set up headers c = ARest.new “localhost:3000/_api/v1”, headers: => “Token token=AHDIUHSBC.…”
-
username and password for basic http authentication c = ARest.new “localhost:3000/_api/v1”, username: “user1”, password: “password.8”
-
Authentication token c = ARest.new “localhost:3000/_api/v1”, token: ‘AdbsuUDhwb3hqhj…’
40 41 42 43 44 45 46 |
# File 'lib/arest.rb', line 40 def initialize(base_url, **) @base_url = base_url @headers = [:headers] @auth_user = [:username] @auth_password = [:password] @auth_token = [:token] end |
Instance Method Details
#delete(path, **options) ⇒ Object
Perform a HTTP DELETE request. Requires a path to current operation If given, headers and http authentication can be override
Input
-
path - relative to URI given in constructor
Options Hash
-
headers - overrides the header given in constructor
-
username, password - overrides the http authentication
-
token - overrides authorization token
-
form_data - hash with HTML form data
100 101 102 |
# File 'lib/arest.rb', line 100 def delete(path, **) execute :delete, path, end |
#get(path, **options) ⇒ Object
Perform a HTTP GET request. Requires a path to current operation If given, headers and http authentication can be override
Input
-
path - relative to URI given in constructor
Options Hash
-
headers - overrides the header given in constructor
-
username, password - overrides the http authentication
-
token - overrides authorization token
-
form_data - hash with HTML form data
58 59 60 |
# File 'lib/arest.rb', line 58 def get(path, **) execute :get, path, end |
#inspect ⇒ Object
104 105 106 |
# File 'lib/arest.rb', line 104 def inspect "<ARest #{@base_url}#{if @headers then ', with headers' else '' end}#{if @auth_user && @auth_password then ', authenticating as '+@auth_user else '' end}>" end |
#post(path, **options) ⇒ Object
Perform a HTTP POST request. Requires a path to current operation If given, headers and http authentication can be override
Input
-
path - relative to URI given in constructor
Options Hash
-
headers - overrides the header given in constructor
-
username, password - overrides the http authentication
-
token - overrides authorization token
-
form_data - hash with HTML form data
72 73 74 |
# File 'lib/arest.rb', line 72 def post(path, **) execute :post, path, end |
#put(path, **options) ⇒ Object
Perform a HTTP PUT request. Requires a path to current operation If given, headers and http authentication can be override
Input
-
path - relative to URI given in constructor
Options Hash
-
headers - overrides the header given in constructor
-
username, password - overrides the http authentication
-
token - overrides authorization token
-
form_data - hash with HTML form data
86 87 88 |
# File 'lib/arest.rb', line 86 def put(path, **) execute :put, path, end |