widgets_api_client 0.2.0.2 → 0.2.0.3

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: b8a33b70b243fa7d2421fb28b4cf5b2c774ce7d3
4
- data.tar.gz: 218218f461ba3096a5e1445e53b24408033c41e8
3
+ metadata.gz: 89b50c0f3e061c4b200839f78c429666389ab3b2
4
+ data.tar.gz: 508dbede320fee45134eea74cb53aadb3e8ef245
5
5
  SHA512:
6
- metadata.gz: 58153cf80012217ffefcac576d76a2ebabb4136199d91820e08797bdcafd8e31eed3aa4842b9ae3bb1acdb8995f0b46c49f4dc5301c5aaaeecddbac8e26e6e9c
7
- data.tar.gz: 5bcab61761acf1bb84671b8a43fa6672e8da88771eb645e94be4e8991a16410382649b0d6697494ac8d597a81033e658a196d5951017cae9d3fe59c8f4d405c3
6
+ metadata.gz: 7372c62b61ca82f1bde5e5f33b4021d2b78d652f9a44a62d5d898ade2c87e852b86b9ecb8f6c7d78975cc2305ca0283f3bf02b2f3726b5e5162047b6708655cf
7
+ data.tar.gz: '085521c804f2e104a4dfd56cfdf58c7e3fcce2634a8d904ed1965b2d05bc2b5b1ecc2ff570debb6911d4b6c5a062b5972575415af12caa3273d660b199ce6023'
@@ -5,8 +5,6 @@ require 'json'
5
5
  #
6
6
  class Authentication
7
7
  attr_accessor :grant_type
8
- attr_accessor :client_id
9
- attr_accessor :client_secret
10
8
  attr_accessor :username
11
9
  attr_accessor :password
12
10
  attr_accessor :token
@@ -16,45 +14,32 @@ class Authentication
16
14
  # Inialise the authentication model
17
15
  #
18
16
  # @param [String] grant_type Token grant type
19
- # @param [String] client_id
20
- # @param [String] client_secret
21
17
  # @param [String] username
22
18
  # @param [String] password
23
19
  # @param [String] token Bearer token
24
20
  # @param [String] refresh_token Refresh token
25
21
  #
26
- def initialize(grant_type: nil, client_id: nil, client_secret: nil,
27
- username: nil, password: nil, token: nil, refresh_token: nil)
22
+ def initialize(grant_type: nil, username: nil, password: nil, token: nil, refresh_token: nil)
28
23
  self.grant_type = grant_type
29
- self.client_id = client_id
30
- self.client_secret = client_secret
31
24
  self.username = username
32
25
  self.password = password
33
26
  self.token = token
34
27
  self.refresh_token = refresh_token
35
28
  end
36
29
 
37
- #
38
- # Converts Authentication object to Json object
39
- #
40
- # @param [Refrence] *data authentication object refrence
41
- #
42
- # @return [Json] Json represenatation of authentication object
43
- #
44
- def to_json(*data)
45
- hash = {
30
+ def as_json(options={})
31
+ hash_data = {
46
32
  grant_type: @grant_type,
47
- client_id: @client_id,
48
- client_secret: @client_secret,
49
33
  username: @username,
50
34
  password: @password,
51
35
  token: @token,
52
36
  refresh_token: @refresh_token
53
- }
54
- hash.delete_if { |k, v| v.nil? || v.empty? }
55
- hash.to_json(*data)
56
- end
57
-
37
+ }
38
+
39
+ hash.delete_if { |k, v| v.nil? || v.empty? }
40
+ hash_data
41
+ end
42
+
58
43
  #
59
44
  # Gets Json represenatation of authentication object
60
45
  #
@@ -63,6 +48,10 @@ class Authentication
63
48
  # @return [Json] Json represenatation of authentication object
64
49
  #
65
50
  def self.get_payload(auth_data)
66
- auth_data.to_json
51
+ user.as_json.to_json
52
+ end
53
+
54
+ def self.get_payload_with_client_info(auth_data)
55
+ auth_data.as_json.merge!({'client_id' => ApplicationConfig.client_id, 'client_secret' => ApplicationConfig.client_secret}).to_json
67
56
  end
68
57
  end
data/lib/domain/user.rb CHANGED
@@ -69,6 +69,6 @@ class User
69
69
  end
70
70
 
71
71
  def self.get_payload_with_client_info(user)
72
- user.as_json.merge({'client_id' => ApplicationConfig.client_id, 'client_secret' => ApplicationConfig.client_secret}).to_json
72
+ user.as_json.merge!({'client_id' => ApplicationConfig.client_id, 'client_secret' => ApplicationConfig.client_secret}).to_json
73
73
  end
74
74
  end
@@ -1,7 +1,6 @@
1
1
  require 'rest-client'
2
2
  require 'json'
3
3
  require_relative '../domain/authentication.rb'
4
- require_relative '../domain/application_config.rb'
5
4
 
6
5
  #
7
6
  # Authentication Service for token activies
@@ -15,8 +14,7 @@ class AuthenticationService
15
14
  # @return [Json] Response with brearer and refresh token
16
15
  #
17
16
  def self.create_authentication(auth_data)
18
- auth_data = get_auth_with_client_info(auth_data)
19
- auth_payload = Authentication.get_payload(auth_data)
17
+ auth_payload = Authentication.get_payload_with_client_info(auth_data)
20
18
  RestClient::Request.execute(method: :post,
21
19
  url: ApplicationConfig.get_url('create_authentication_path'),
22
20
  payload: auth_payload,
@@ -32,8 +30,7 @@ class AuthenticationService
32
30
  # @return [Json] Response with brearer and refresh token
33
31
  #
34
32
  def self.refresh_authentication_token(auth_data, bearer_token)
35
- auth_data = get_auth_with_client_info(auth_data)
36
- auth_payload = Authentication.get_payload(auth_data)
33
+ auth_payload = Authentication.get_payload_with_client_info(auth_data)
37
34
  RestClient::Request.execute(method: :post,
38
35
  url: ApplicationConfig.get_url('create_authentication_path'),
39
36
  payload: auth_payload,
@@ -57,17 +54,4 @@ class AuthenticationService
57
54
  headers: { 'Content-Type': 'application/json',
58
55
  'Authorization': bearer_token })
59
56
  end
60
-
61
- #
62
- # Sets Client id and secrets to Authentication object
63
- #
64
- # @param [Object] auth_data Authentication object
65
- #
66
- # @return [Object] Authentication object
67
- #
68
- def self.get_auth_with_client_info(auth_data)
69
- auth_data.client_id = ApplicationConfig.client_id
70
- auth_data.client_secret = ApplicationConfig.client_secret
71
- auth_data
72
- end
73
57
  end
@@ -1,6 +1,5 @@
1
1
  require 'rest-client'
2
2
  require 'json'
3
- require_relative '../domain/application_config.rb'
4
3
  require_relative '../domain/user.rb'
5
4
 
6
5
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: widgets_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.2
4
+ version: 0.2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sachin Murthy