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



7
8
9
10
11
# File 'lib/soaspec/exchange_handlers/rest_accessors.rb', line 7

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



41
42
43
44
45
# File 'lib/soaspec/exchange_handlers/rest_accessors.rb', line 41

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)

    Params client_id: nil, client_secret: nil, token_url: nil, username: nil, password: nil, security_token: nil



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/soaspec/exchange_handlers/rest_accessors.rb', line 15

def oauth2(params)
  # Method to send request to get oauth token based on parameters
  define_method('oauth_response') do
    OAuth2.new(params, api_username).response
  end

  define_method('access_token') do
    oauth_response['access_token']
  end

  define_method('instance_url') do
    oauth_response['instance_url']
  end
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



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

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



48
49
50
51
52
# File 'lib/soaspec/exchange_handlers/rest_accessors.rb', line 48

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