Module: Soaspec::RestAccessors

Included in:
RestHandler
Defined in:
lib/soaspec/exchange_handlers/rest_accessors.rb

Overview

Accessors specific to REST handler

Instance Method Summary collapse

Instance Method Details

#base_url(url) ⇒ Object

Defines method ‘base_url_value’ containing base URL used in REST requests

Parameters:

  • url (String)

    Base Url to use in REST requests. Suburl is appended to this



9
10
11
12
13
# File 'lib/soaspec/exchange_handlers/rest_accessors.rb', line 9

def base_url(url)
  define_method('base_url_value') do
    url
  end
end

#headers(headers) ⇒ Object

Parameters:

  • headers (Hash)

    Hash of REST headers used in RestClient



43
44
45
46
47
# File 'lib/soaspec/exchange_handlers/rest_accessors.rb', line 43

def headers(headers)
  define_method('rest_client_headers') do
    headers
  end
end

#oauth2(params) ⇒ Object

Will create access_token method based on passed parameters

Parameters:

  • params (Hash)

    OAuth 2 parameters



23
24
25
26
27
28
29
30
# File 'lib/soaspec/exchange_handlers/rest_accessors.rb', line 23

def oauth2(params)
  # @!method oauth_obj Object to handle oauth2
  define_method('oauth_obj') { OAuth2.new(params, api_username) }
  # @!method access_token Retrieve OAuth2 access token
  define_method('access_token') { oauth_obj.access_token }
  # @!method instance_url Retrieve instance url from OAuth request
  define_method('instance_url') { oauth_obj.response['instance_url'] }
end

#oauth2_file(path_to_filename) ⇒ Object

Pass path to YAML file containing OAuth2 parameters

Parameters:

  • path_to_filename (String)

    Will have Soaspec.credentials_folder appended to it if set



34
35
36
37
38
39
40
# File 'lib/soaspec/exchange_handlers/rest_accessors.rb', line 34

def oauth2_file(path_to_filename)
  full_path = Soaspec.credentials_folder ? File.join(Soaspec.credentials_folder, path_to_filename) : path_to_filename
  full_path += '.yml' unless full_path.end_with?('.yml')
  file_hash = YAML.load_file(full_path)
  raise 'File at ' + full_path + ' is not a hash ' unless file_hash.is_a? Hash
  oauth2 file_hash
end

#pascal_keys(set) ⇒ Object

Convert each key from snake_case to PascalCase



50
51
52
53
54
# File 'lib/soaspec/exchange_handlers/rest_accessors.rb', line 50

def pascal_keys(set)
  define_method('pascal_keys?') do
    set
  end
end