sticapi_client 0.1.3 → 0.1.4

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: cf18fe6fad043acaa4128623adffe1163923a40f
4
- data.tar.gz: 15c597e2f555bc893894ffb4f38d49355e3ee253
3
+ metadata.gz: 559cdd316e08891d00fef7d3930800d133d43618
4
+ data.tar.gz: c33024f1165418ab7008b5c26c66dfe31e98289b
5
5
  SHA512:
6
- metadata.gz: 50c270950a3356b4695c51a9cc1967ca56657db676c21c3e1b37c43da3d33d0ff935b4342280fb85cfd2baa83edc99aa252c69a8ccd59a1832d5243e3495d41e
7
- data.tar.gz: '07478757078379e8e0c72455657de08781e2eee5818073ce88b70cd2c6ed5b1bcdf916babb2834b19b42933325311cf8934a7872f16e750fde94e6d6ac1005ce'
6
+ metadata.gz: 9f934bbeb4bc1694c9dcae039d649bf66360c3d3d9da7aec6b1bc3313d039d523625df0332bdeca46b89afbe0dca30f0d8dd0dcf329bbf52100548059d4c529d
7
+ data.tar.gz: e27e325a674a6d930a98e0b93ab18dd65b5d0ec11af9520fd6ff5f0a02f86e443831bb4167a954c1ce75b7f7fb3a02ab48c081d2d5a4f5bdfad4d1bab3bf9363
@@ -1,22 +1,16 @@
1
1
  module SticapiController
2
2
  def self.included(base)
3
3
  base.send(:before_action, :get_token)
4
- base.send(:after_action, :update_token)
4
+ # base.send(:after_action, :update_token)
5
5
  end
6
6
 
7
7
  def initialize
8
8
  super
9
- #self references the instance of the UsersController class
10
9
  @model_class = self.class
11
- puts @model_class # UsersController
10
+ return
12
11
  end
13
12
 
14
13
  def get_token
15
14
  SticapiClient::SticapiClient.instance.get_token
16
15
  end
17
-
18
- def update_token
19
- puts 'update_token'
20
- puts @model_class # UsersController
21
- end
22
16
  end
@@ -17,7 +17,7 @@ module Devise
17
17
  }
18
18
  token = JWT.encode payload, secret, 'HS256'
19
19
 
20
- uri = URI.parse("http://#{SticapiClient::SticapiClient.instance.host}:#{SticapiClient::SticapiClient.instance.port}/users/log_in")
20
+ uri = URI.parse("#{SticapiClient::SticapiClient.instance.uri}/users/log_in")
21
21
  http = Net::HTTP.new(uri.host, uri.port)
22
22
  request = Net::HTTP::Post.new(uri.request_uri)
23
23
  request['Content-Type'] = 'application/json'
@@ -26,6 +26,7 @@ module Devise
26
26
  request['uid'] = SticapiClient::SticapiClient.instance.uid
27
27
  request.body = { data: token }.to_json
28
28
  response = http.request(request)
29
+ SticapiClient::SticapiClient.instance.update_token(response)
29
30
 
30
31
  case response
31
32
  when Net::HTTPSuccess
@@ -1,3 +1,3 @@
1
1
  module SticapiClient
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -34,21 +34,29 @@ module SticapiClient
34
34
  @expiry = ''
35
35
  end
36
36
 
37
+ def uri
38
+ "http://#{@host}:#{@port}#{@urn}"
39
+ end
40
+
37
41
  def get_token
38
42
  if @access_token.blank?
39
- uri = ''
40
- uri = URI.parse("http://#{@host}:#{@port}#{@urn}/auth/sign_in")
43
+ uri = URI.parse("#{self.uri}/auth/sign_in")
44
+ puts uri
41
45
  http = Net::HTTP.new(uri.host, uri.port)
42
46
  request = Net::HTTP::Post.new(uri.request_uri)
43
47
  request['email'] = @user
44
48
  request['password'] = @password
45
49
  response = http.request(request)
46
- @access_token = response['access-token']
47
- @client = response['client']
48
- @uid = response['uid']
49
- @expiry = response['expiry']
50
+ update_token(response)
50
51
  end
51
52
  end
53
+
54
+ def update_token(response)
55
+ @access_token = response['access-token']
56
+ @client = response['client']
57
+ @uid = response['uid']
58
+ @expiry = response['expiry']
59
+ end
52
60
  end
53
61
  end
54
62
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sticapi_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Viana