Class: ARest

Inherits:
Object
  • Object
show all
Defined in:
lib/arest.rb

Instance Method Summary collapse

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, **options)
  @base_url = base_url
  @headers = options[:headers]
  @auth_user = options[:username]
  @auth_password = options[:password]
  @auth_token = options[: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, **options)
  execute :delete, path, options
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, **options)
  execute :get, path, options
end

#inspectObject



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, **options)
  execute :post, path, options
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, **options)
  execute :put, path, options
end