incentivale-sdk-ruby 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a638195cbe1382179e3841bfd9e6c221c410cc18b68e19d4b0badeee243bb14
4
- data.tar.gz: 2d5ce107eaa538d13ffcf3c8f7ad18404490536e6864de29ec516daa278e9c75
3
+ metadata.gz: df7544f9d5950fe3c3708e4b3e13768ed61acf49bcfb8020e5c4fd930051e29d
4
+ data.tar.gz: e4bfcd457a1b0b1de66e73947cad54e28c40efeede3e3a94ee06b55762934b1f
5
5
  SHA512:
6
- metadata.gz: cdb9b4d8c67da87552d702cbe2302d1d7c28d4a22223f89045a33f34a6de6226cddda15034403f659e5f0f90ec0ab78b994f02e8f49afca4bb9f423b646aba64
7
- data.tar.gz: 0014f4fccae5dc3dc11d65c6dfd06948343fa277a94e697eb9b7f671ef7c54be074aa8d309cdaee9c1358aeb699dfac58ea911082651695173830bce3802cd05
6
+ metadata.gz: c0c50cd01db8d8d44e629d373ceea757a8ab5913185a61615043003a0eee8d5f518b00803fb9aaa745b3830b3d1c7e949b76edc35a8645d9c1042b6b53a66c49
7
+ data.tar.gz: bca2458d00c615776d7277eafd5f8abf0b108ca5eda1c4c30c08f9a40479cbdfee7688fead9b4112ef339f94d0b031259c79f899c7f244a11927ac1bc77c1059
@@ -1,13 +1,22 @@
1
1
  module Incentivale
2
2
  class Client
3
- HOST = 'https://central-incentivale.herokuapp.com' # FIXME 'https://central.incentivale.com.br'
4
-
5
3
  attr_accessor :token
6
4
 
7
5
  def initialize(token)
8
6
  @token = token
9
7
  end
10
8
 
9
+ def self.host
10
+ case Incentivale.configuration.environment
11
+ when :sandbox
12
+ 'https://homologacentral.incentivale.com.br'
13
+ when :production
14
+ 'https://central.incentivale.com.br'
15
+ else
16
+ raise StandardError, 'invalid environment provided'
17
+ end
18
+ end
19
+
11
20
  def get(path, params = {})
12
21
  request.get path, params.merge(campaign_token)
13
22
  end
@@ -3,6 +3,7 @@ module Incentivale
3
3
  attr_accessor :username
4
4
  attr_accessor :password
5
5
  attr_accessor :campaign
6
+ attr_accessor :environment
6
7
 
7
8
  def inspect
8
9
  "#<#{self.class.name}:#{object_id}>"
@@ -5,11 +5,10 @@ module Incentivale
5
5
  attr_accessor :connection
6
6
 
7
7
  def initialize(client)
8
- @connection = Faraday.new(url: Client::HOST) do |builder|
8
+ @connection = Faraday.new(url: Client.host) do |builder|
9
9
  builder.headers['Authorization'] = Auth.new(client).header
10
10
  builder.headers['Content-Type'] = 'application/x-www-form-urlencoded'
11
11
  builder.headers['Connection'] = 'Keep-Alive'
12
- builder.request :url_encoded
13
12
  builder.adapter Faraday.default_adapter
14
13
  end
15
14
  end
@@ -30,15 +30,22 @@ module Incentivale
30
30
  private
31
31
 
32
32
  def token_host
33
- Client::HOST + '/oauth/token'
33
+ Client.host + '/oauth/token'
34
+ end
35
+
36
+ def token_grants
37
+ { username: Incentivale.configuration.username,
38
+ password: Incentivale.configuration.password,
39
+ grant_type: :password }
34
40
  end
35
41
 
36
42
  def generate_new_token
37
- Response.new Faraday.new.post(token_host, {
38
- grant_type: :password,
39
- username: Incentivale.configuration.username,
40
- password: Incentivale.configuration.password
41
- })
43
+ connection = Faraday.new(url: token_host)
44
+ response = connection.post do |request|
45
+ request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
46
+ request.body = URI.encode_www_form(token_grants)
47
+ end
48
+ Response.new(response)
42
49
  end
43
50
  end
44
51
  end
@@ -1,3 +1,3 @@
1
1
  module Incentivale
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incentivale-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Santos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-13 00:00:00.000000000 Z
11
+ date: 2018-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday