soaspec 0.2.15 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec45b1e98edf6a23e7067fcd802bae1478eb8c60
4
- data.tar.gz: b84b9bcfbb604e1289575e71aec19b5d7ee29b86
3
+ metadata.gz: 8891885f86ed542e4af5f296faa308b68561c3db
4
+ data.tar.gz: 320f15c1d25758222199077605fd2438b3dc8210
5
5
  SHA512:
6
- metadata.gz: 8d9024d5b130efee645a4cdb1bfa08dea28d069b0f457f2d89f8a6634219b284f927eff09ffb9ff6964995637af40748a21952262377d9e3fc0c5ee8ae99820d
7
- data.tar.gz: d890a5f985ede66673e32e8a086fbe4920ee5addd5f519ecb5b137c97e0baa8a287481f3a69858bb31936ec27d759f9d460310110a7b04effc2fef496b59241f
6
+ metadata.gz: 548d8865e81795e26b96d1c6e2bb1db109f74beba399df4714a7e6a3d7b167f9e0b43f2fa74218ac285bbe384ac992a4f2b4797d3b66b71ab985b02d64a98ddb
7
+ data.tar.gz: 8a89c6cb47d43e6fb24dec5cc407d5c0628ff00d570d638aaa08ddcfaedc31666f1f33dfa42b1955f8e6fc4a0b6e0e7b257f986985d92c52c9b0e103637b375d
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Version 0.2.16
2
+ * Enhancement
3
+ * Move debug oauth into OAuth2 class
4
+
1
5
  Version 0.2.14
2
6
  * Bug Fix
3
7
  * Remove default log file being created before it is changed to a custom location
data/demo/extract.html CHANGED
@@ -10,30 +10,24 @@
10
10
  <div ng-app="codeDemo" ng-controller="extract">
11
11
  <p>
12
12
  <b>Sample response</b>
13
- <p>
14
- {"root":
15
- {"parent1":
16
- {"child1":5,"child2":"parent1 word"},
17
- "parent2":
18
- {"uniq":"val","child2":"word2"}}
19
- }
13
+ <p> {{ sampleData }}
20
14
  </p>
21
15
  </p>
22
16
  <p>Method:
23
17
  <select ng-model="index">
24
- <option value="0" selected="selected">Unique element from body</option>
25
- <option value="1">Element from body via JSONPath</option>
26
- <option value="2">List of values matching JSONPath</option>
18
+ <option ng-repeat="option in myData" value="{{$index}}">{{option.desc}}
19
+ </option>
27
20
  </select>
28
21
  </p>
29
- <p ng-bind="myData[index].method"></p>
30
- <p ng-bind="myData[index].result"></p>
22
+ <p>Code: {{ myData[index].method }}</p>
23
+ <p>Result: {{ myData[index].result }} </p>
31
24
  </div>
32
25
  <script>
33
26
  var app = angular.module('codeDemo', []);
34
27
  app.controller('extract', function($scope, $http) {
35
28
  $http.get("extract.json").then(function(response) {
36
- $scope.myData = response.data;
29
+ $scope.myData = response.data.methods;
30
+ $scope.sampleData = response.data.sampleData;
37
31
  });
38
32
  });
39
33
  </script>
data/demo/extract.json CHANGED
@@ -1,14 +1,36 @@
1
- [
2
- {
3
- "method": "@exchange['uniq']",
4
- "result": "'val'"
5
- },
6
- {
7
- "method": "@exchange['$..parent1.child2']",
8
- "result": "'parent1 word'"
9
- },
10
- {
11
- "method": "@exchange.values_at_path('$..child2')",
12
- "result": "['parent1 word', 'word2']"
13
- }
14
- ]
1
+ {
2
+ "sampleData":
3
+ {"root":
4
+ {"parent1":
5
+ {"child1":5,"child2":"parent1 word"},
6
+ "parent2":
7
+ {"uniq":"val","child2":"word2"}}
8
+ },
9
+ "methods": [
10
+ {
11
+ "desc": "Get response object",
12
+ "method": "@exchange.response",
13
+ "result": "RestClient::Response or Savon::Response"
14
+ },
15
+ {
16
+ "desc": "Unique element from body",
17
+ "method": "@exchange['uniq']",
18
+ "result": "'val'"
19
+ },
20
+ {
21
+ "desc": "Element from body via JSONPath",
22
+ "method": "@exchange['$..parent1.child2']",
23
+ "result": "'parent1 word'"
24
+ },
25
+ {
26
+ "desc": "List of values matching JSONPath",
27
+ "method": "@exchange.values_at_path('$..child2')",
28
+ "result": "['parent1 word', 'word2']"
29
+ },
30
+ {
31
+ "desc": "Convert response into hash",
32
+ "method": "@exchange.to_hash",
33
+ "result": "{:root=>{:parent1=>{:child1=>5, :child2=>\"word\"}, :parent2=>{:uniq=>\"val\", :child2=>\"word2\"}}}"
34
+ }
35
+ ]
36
+ }
data/lib/soaspec.rb CHANGED
@@ -40,13 +40,14 @@ module Soaspec
40
40
  @auto_oauth = true
41
41
 
42
42
  class << self
43
- # Specify whether to see params sent to and retrieved from oauth. This will put password in log file, only recommended for debugging
44
- attr_writer :debug_oauth
45
43
  # Folder used to store templates for API calls
44
+ # @return [String]
46
45
  attr_reader :template_folder
47
46
  # Stores last exchange
47
+ # @return [Exchange]
48
48
  attr_accessor :last_exchange
49
49
  # Automatically add Authorization header to RestHandler where oauth2 credentials are specified
50
+ # @return [Boolean] Whether to add authorization header
50
51
  attr_accessor :auto_oauth
51
52
 
52
53
  # Folder used to store templates for API calls
@@ -55,23 +56,17 @@ module Soaspec
55
56
  @template_folder = folder.include?('\\') ? folder.split('\\') : folder.split('/')
56
57
  end
57
58
 
58
- # Folder used to store credentials
59
- # Used in auth2_file command
60
- # @param [String] folder
61
- attr_writer :credentials_folder
62
-
63
59
  # Credentials folder used to store secret data (not in source control) E.g passwords
64
- attr_reader :credentials_folder
65
-
66
- # Used so that exchange class knows what context it's in
67
- # @param [ExchangeHandler] handler A class inheriting from Soaspec::ExchangeHandler. Exchange class uses this
68
- attr_writer :api_handler
60
+ # Used in oauth2_file command
61
+ # @return [String] folder in which credentials are stored
62
+ attr_accessor :credentials_folder
69
63
 
70
- # Exchange Handler class currently being used
71
- attr_reader :api_handler
64
+ # Used so that exchange class knows what context it's in.
65
+ # @return [ExchangeHandler] handler A class inheriting from Soaspec::ExchangeHandler. Exchange class uses this
66
+ attr_accessor :api_handler
72
67
 
73
- # Set whether to transform strings to keys in request automatically
74
- # @param [Boolean] use_keys
68
+ # Set whether to transform strings to keys in request automatically.
69
+ # @return [Boolean]
75
70
  attr_writer :always_use_keys
76
71
 
77
72
  # @return [Boolean] Whether to transform strings to keys in request automatically
@@ -81,10 +76,20 @@ module Soaspec
81
76
 
82
77
  # @return [Boolean] Whether to see params sent to & received from oauth URL
83
78
  def debug_oauth?
84
- @debug_oauth || false
79
+ puts 'Soaspec.debug_oauth? now deprecated. Please use Soaspec::OAuth2.debug_oauth? instead'
80
+ Soaspec::OAuth2.debug_oauth?
81
+ end
82
+
83
+ # Specify whether to see params sent to and retrieved from oauth.
84
+ # This will put password in log file, only recommended for debugging
85
+ # @param [String] set Whether to debug oauth
86
+ def debug_oauth=(set)
87
+ puts 'Soaspec.debug_oauth= now deprecated. Please use Soaspec::OAuth2.debug_oauth= instead'
88
+ Soaspec::OAuth2.debug_oauth = set
85
89
  end
86
90
 
87
91
  # Whether to log all API traffic
92
+ # @param [Boolean] set
88
93
  def log_api_traffic=(set)
89
94
  puts 'Soaspec.log_api_traffic= now deprecated. Please use Soaspec::SpecLogger.log_api_traffic= instead'
90
95
  Soaspec::SpecLogger.log_api_traffic = set
@@ -3,7 +3,7 @@ module Soaspec
3
3
  # in an exchange from the ExchangeHandler that it's tied to
4
4
  module ExchangeExtractor
5
5
  # Request of API call. Either intended request or actual request
6
- # @response [Object] Object representing request of API
6
+ # @return [Object] Object representing request of API
7
7
  def request
8
8
  exchange_handler.request(@response)
9
9
  end
@@ -3,14 +3,14 @@ module Soaspec
3
3
  module RestExchangeFactory
4
4
  # Make REST Exchange with 'post' method within this Handler context
5
5
  # @param [Hash, String] params Exchange parameters. If String is used it will be for the request payload
6
- # @option override_parameters [String] :name Name to appear in traffic logs
7
- # @option override_parameters [Hash] :params Extra parameters (E.g. headers)
8
- # @option override_parameters [String] :suburl URL appended to base_url of class
9
- # @option override_parameters [Hash] :q Query for REST
6
+ # @option params [String] :name Name to appear in traffic logs
7
+ # @option params [Hash] :params Extra parameters (E.g. headers)
8
+ # @option params [String] :suburl URL appended to base_url of class
9
+ # @option params [Hash] :q Query for REST
10
10
  # Following are for the body of the request
11
- # @option override_parameters [Hash] :body Hash to be converted to JSON in request body
12
- # @option override_parameters [String] :payload String to be passed directly in request body
13
- # @option override_parameters [String] :template_name Path to file to be read via ERB and passed in request body
11
+ # @option params [Hash] :body Hash to be converted to JSON in request body
12
+ # @option params [String] :payload String to be passed directly in request body
13
+ # @option params [String] :template_name Path to file to be read via ERB and passed in request body
14
14
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
15
15
  def post(params = {})
16
16
  perform_exchange_with(:post, params)
@@ -18,14 +18,14 @@ module Soaspec
18
18
 
19
19
  # Make REST Exchange with 'patch' method within this Handler context
20
20
  # @param [Hash, String] params Exchange parameters. If String is used it will be for the request payload
21
- # @option override_parameters [String] :name Name to appear in traffic logs
22
- # @option override_parameters [Hash] :params Extra parameters (E.g. headers)
23
- # @option override_parameters [String] suburl URL appended to base_url of class
24
- # @option override_parameters [Hash] :q Query for REST
21
+ # @option params [String] :name Name to appear in traffic logs
22
+ # @option params [Hash] :params Extra parameters (E.g. headers)
23
+ # @option params [String] suburl URL appended to base_url of class
24
+ # @option params [Hash] :q Query for REST
25
25
  # Following are for the body of the request
26
- # @option override_parameters [Hash] :body Hash to be converted to JSON in request body
27
- # @option override_parameters [String] :payload String to be passed directly in request body
28
- # @option override_parameters [String] :template_name Path to file to be read via ERB and passed in request body
26
+ # @option params [Hash] :body Hash to be converted to JSON in request body
27
+ # @option params [String] :payload String to be passed directly in request body
28
+ # @option params [String] :template_name Path to file to be read via ERB and passed in request body
29
29
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
30
30
  def patch(params)
31
31
  perform_exchange_with(:patch, params)
@@ -33,14 +33,14 @@ module Soaspec
33
33
 
34
34
  # Make REST Exchange with 'put' method within this Handler context
35
35
  # @param [Hash, String] params Exchange parameters. If String is used it will be for the request payload
36
- # @option override_parameters [String] :name Name to appear in traffic logs
37
- # @option override_parameters [Hash] :params Extra parameters (E.g. headers)
38
- # @option override_parameters [String] :suburl URL appended to base_url of class
39
- # @option override_parameters [Hash] :q Query for REST
36
+ # @option params [String] :name Name to appear in traffic logs
37
+ # @option params [Hash] :params Extra parameters (E.g. headers)
38
+ # @option params [String] :suburl URL appended to base_url of class
39
+ # @option params [Hash] :q Query for REST
40
40
  # Following are for the body of the request
41
- # @option override_parameters [Hash] :body Hash to be converted to JSON in request body
42
- # @option override_parameters [String] :payload String to be passed directly in request body
43
- # @option override_parameters [String] :template_name Path to file to be read via ERB and passed in request body
41
+ # @option params [Hash] :body Hash to be converted to JSON in request body
42
+ # @option params [String] :payload String to be passed directly in request body
43
+ # @option params [String] :template_name Path to file to be read via ERB and passed in request body
44
44
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
45
45
  def put(params = {})
46
46
  perform_exchange_with(:put, params)
@@ -49,10 +49,10 @@ module Soaspec
49
49
  # Make REST Exchange with 'get' method within this Handler context.
50
50
  # If merely a string is passed it will be used as the URL appended to base_url (same as suburl). Otherwise a Hash is expected
51
51
  # @param [Hash, String] params Exchange parameters. If String is used it will be for suburl
52
- # @option override_parameters [String] :name Name to appear in traffic logs
53
- # @option override_parameters [String] :suburl URL appended to base_url of class
54
- # @option override_parameters [Hash] :params Extra parameters (E.g. headers)
55
- # @option override_parameters [Hash] :q Query for REST
52
+ # @option params [String] :name Name to appear in traffic logs
53
+ # @option params [String] :suburl URL appended to base_url of class
54
+ # @option params [Hash] :params Extra parameters (E.g. headers)
55
+ # @option params [Hash] :q Query for REST
56
56
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
57
57
  def get(params = {})
58
58
  perform_exchange_with(:get, params)
@@ -61,10 +61,10 @@ module Soaspec
61
61
  # Make REST Exchange with 'delete' method within this Handler context.
62
62
  # If merely a string is passed it will be used as the URL appended to base_url (same as suburl). Otherwise a Hash is expected
63
63
  # @param [Hash, String] params Exchange parameters. If String is used it will be for suburl
64
- # @option override_parameters [String] :name Name to appear in traffic logs
65
- # @option override_parameters [String] :suburl URL appended to base_url of class
66
- # @option override_parameters [Hash] :q Query for REST
67
- # @option override_parameters [Hash] :params Extra parameters (E.g. headers)
64
+ # @option params [String] :name Name to appear in traffic logs
65
+ # @option params [String] :suburl URL appended to base_url of class
66
+ # @option params [Hash] :q Query for REST
67
+ # @option params [Hash] :params Extra parameters (E.g. headers)
68
68
  # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
69
69
  def delete(params = {})
70
70
  perform_exchange_with(:delete, params)
@@ -219,7 +219,7 @@ module Soaspec
219
219
  end
220
220
  end
221
221
 
222
- # @response [RestClient::Request] Request of API call. Either intended request or actual request
222
+ # @return [RestClient::Request] Request of API call. Either intended request or actual request
223
223
  def request(response)
224
224
  return 'Request not yet sent' if response.nil?
225
225
 
@@ -11,12 +11,12 @@ module Soaspec
11
11
 
12
12
  # Will create access_token method based on passed parameters
13
13
  # @param [Hash] params OAuth 2 parameters
14
- # @param_value [token_url] URL to retrieve OAuth token from. @Note this can be set globally instead of here
15
- # @param_value [client_id] Client ID
16
- # @param_value [client_secret] Client Secret
17
- # @param_value [username] Username used in password grant
18
- # @param_value [password] Password used in password grant
19
- # @param_value [security_token] Security Token used in password grant
14
+ # @option params [token_url] URL to retrieve OAuth token from. @Note this can be set globally instead of here
15
+ # @option params [client_id] Client ID
16
+ # @option params [client_secret] Client Secret
17
+ # @option params [username] Username used in password grant
18
+ # @option params [password] Password used in password grant
19
+ # @option params [security_token] Security Token used in password grant
20
20
  def oauth2(params)
21
21
  # @!method oauth_obj Object to handle oauth2
22
22
  define_method('oauth_obj') { OAuth2.new(params, api_username) }
@@ -21,6 +21,13 @@ module Soaspec
21
21
  attr_accessor :access_tokens
22
22
  # List of URLs to that define the instance of an application
23
23
  attr_accessor :instance_urls
24
+ # Specify whether to see params sent to and retrieved from oauth. This will put password in log file, only recommended for debugging
25
+ attr_writer :debug_oauth
26
+
27
+ # @return [Boolean] Whether to see params sent to & received from oauth URL
28
+ def debug_oauth?
29
+ @debug_oauth || false
30
+ end
24
31
  end
25
32
 
26
33
  # @attr [Hash] OAuth parameters
@@ -29,12 +36,12 @@ module Soaspec
29
36
  attr_accessor :retry_count
30
37
 
31
38
  # @param [Hash] params_sent Parameters to make OAuth request
32
- # @param_value [token_url] URL to retrieve OAuth token from. @Note this can be set globally instead of here
33
- # @param_value [client_id] Client ID
34
- # @param_value [client_secret] Client Secret
35
- # @param_value [username] Username used in password grant
36
- # @param_value [password] Password used in password grant
37
- # @param_value [security_token] Security Token used in password grant
39
+ # @option params_sent [token_url] URL to retrieve OAuth token from. @Note this can be set globally instead of here
40
+ # @option params_sent [client_id] Client ID
41
+ # @option params_sent [client_secret] Client Secret
42
+ # @option params_sent [username] Username used in password grant
43
+ # @option params_sent [password] Password used in password grant
44
+ # @option params_sent [security_token] Security Token used in password grant
38
45
  # @param [String] api_username Username to use which can be set by Soaspec::ExchangeHandler
39
46
  def initialize(params_sent, api_username = nil)
40
47
  self.retry_count = 0 # No initial tries at getting access token
@@ -50,6 +57,12 @@ module Soaspec
50
57
  params[:password] = ERB.new(params[:password]).result(binding) if params[:password]
51
58
  end
52
59
 
60
+ # Retrieve whether to debug oauth parameters based on global settings
61
+ # @return [Boolean] Whether to see params sent to & received from oauth URL
62
+ def debug_oauth?
63
+ self.class.debug_oauth?
64
+ end
65
+
53
66
  # Retrieve instance_url according to access token response.
54
67
  # Some applications have a different instance
55
68
  # It's assumed this will be constant for a set of oauth parameters
@@ -71,7 +84,7 @@ module Soaspec
71
84
 
72
85
  # @return [Hash] Hash containing access token parameters
73
86
  def response
74
- Soaspec::SpecLogger.info "using oauth_params: #{params}" if Soaspec.debug_oauth?
87
+ Soaspec::SpecLogger.info "using oauth_params: #{params}" if debug_oauth?
75
88
  response = RestClient.post(params[:token_url], payload, cache_control: 'no_cache', verify_ssl: false)
76
89
  rescue RestClient::Exception => error
77
90
  Soaspec::SpecLogger.info(["oauth_error: #{error.message}", "oauth_response: #{error.response}"])
@@ -80,13 +93,13 @@ module Soaspec
80
93
  retry if retry_count < 3
81
94
  raise error
82
95
  else
83
- Soaspec::SpecLogger.info(["response_headers: #{response.headers}", "response_body: #{response.body}"]) if Soaspec.debug_oauth?
96
+ Soaspec::SpecLogger.info(["response_headers: #{response.headers}", "response_body: #{response.body}"]) if debug_oauth?
84
97
  JSON.parse(response)
85
98
  end
86
99
 
87
100
  # @return [String] String to represent OAuth for logging logs
88
101
  def request_message
89
- if Soaspec.debug_oauth?
102
+ if debug_oauth?
90
103
  "request_params: #{payload}"
91
104
  else
92
105
  params[:username] ? "User '#{params[:username]}'" : 'client_credentials'
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.2.15'.freeze
2
+ VERSION = '0.2.16'.freeze
3
3
  end
@@ -20,7 +20,7 @@ module Soaspec
20
20
  end
21
21
  end
22
22
 
23
- # @param [Nokogiri::XML::NodeSet]
23
+ # @param [Nokogiri::XML::NodeSet] type WSDL element type
24
24
  # @return [Boolean] Whether WSDL type is an enumeration
25
25
  def enumeration?(type)
26
26
  return false unless type.first
@@ -49,7 +49,7 @@ module Soaspec
49
49
  end
50
50
  end
51
51
 
52
- # @param [Nokogiri::XML::Element]
52
+ # @param [Nokogiri::XML::Element] element Element to check
53
53
  # @return [Boolean] True if Nokogiri element is a complex type, that is, has a complexType element underneath itself
54
54
  def complex_type?(element)
55
55
  element.children.any? { |child| child.name == 'complexType' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.15
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-17 00:00:00.000000000 Z
11
+ date: 2019-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler