kalixa_api 0.1.1 → 0.1.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: 2ba2e88ce0dbe8fdb2d1ed4a34eb04f76f1d5ad9
4
- data.tar.gz: af004ad760d7bceace9e4cc0a9b51671e042650a
3
+ metadata.gz: 25b61f84afd6c64cad085925094d2686af725c44
4
+ data.tar.gz: da10cbf933be7c1930a46db8d410d56ed8d30ec8
5
5
  SHA512:
6
- metadata.gz: 4222f0ff9b9bf4aff321a25f56ac22092da1278691e93e52536fabcced72e9bde76b2fbaf24eae9adea3a8e7ead2b60552c0fd6d4395b8b9694a2fcb2eb21e3f
7
- data.tar.gz: 0ad4e566eb00ff88065590a3f110a7c5a9d983dac5b39dfc8a30e2e38fcc9d1c5ebab09d2a30de1f04588895aa6cc21e5776fce1002f317969e2a736d057ecab
6
+ metadata.gz: ebf644cbc18a069d7a7b4049bb7840cff5d504ac919515676425c578781e1ae0c4b397fa7f164eaaae39000c2ef74b0b94633e815a32a73e5ce56d021b24960d
7
+ data.tar.gz: 370e55b6c1513d0ff372a6963e6e29691ad2dfbc24933cc9b8c23724065001c53da30d02bcb2ad90eb3dbd04628ffa1615eca3e2c664e9b8fe8abc2318f231cd
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kalixa_api (0.1.0)
4
+ kalixa_api (0.1.3)
5
5
  activesupport
6
6
  faraday (~> 0.14)
7
7
  faraday_middleware
data/README.md CHANGED
@@ -20,17 +20,21 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Create ENV variables for:
23
+ Initialize the the gem by setting your username, password and api mode.
24
+
25
+ Example:
26
+
27
+ config/initializers/kalixa_api.rb
24
28
 
25
29
  ```ruby
26
30
 
27
- ENV['KALIXA_API_USER'] # Production Api User
28
- ENV['KALIXA_API_PASSWORD'] # Production Api Password
31
+ KalixaApi.api_user ||= ENV['KALIXA_API_USER']
32
+ KalixaApi.api_password ||= ENV['KALIXA_API_PASSWORD']
29
33
 
30
- ENV['TEST_KALIXA_API_USER'] # Test Api User
31
- ENV['TEST_KALIXA_API_PASSWORD'] # Test Api Password
34
+ KalixaApi.test_api_user ||= ENV['TEST_KALIXA_API_USER']
35
+ KalixaApi.test_api_password ||= ENV['TEST_KALIXA_API_PASSWORD']
32
36
 
33
- ENV['KALIXA_API_MODE'] # If is NOT 'production' all requests will use test user / password and the test api url.
37
+ KalixaApi.api_mode ||= (ENV['KALIXA_API_MODE'].downcase == 'production') rescue false
34
38
 
35
39
  ```
36
40
 
@@ -11,14 +11,15 @@ require 'kalixa_api/v4/merchant'
11
11
 
12
12
  module KalixaApi
13
13
  class << self
14
- attr_accessor :kalixa_api_user, :kalixa_api_password, :test_kalixa_api_user, :test_kalixa_api_password, :api_mode
14
+ attr_accessor :api_user, :api_password, :test_api_user, :test_api_password, :api_mode
15
15
  end
16
16
 
17
- self.kalixa_api_user ||= ENV['KALIXA_API_USER']
18
- self.kalixa_api_password ||= ENV['KALIXA_API_PASSWORD']
17
+ self.api_user ||= ENV['KALIXA_API_USER']
18
+ self.api_password ||= ENV['KALIXA_API_PASSWORD']
19
19
 
20
- self.test_kalixa_api_user ||= ENV['TEST_KALIXA_API_USER']
21
- self.test_kalixa_api_password ||= ENV['TEST_KALIXA_API_PASSWORD']
20
+ self.test_api_user ||= ENV['TEST_KALIXA_API_USER']
21
+ self.test_api_password ||= ENV['TEST_KALIXA_API_PASSWORD']
22
+
23
+ self.api_mode ||= (ENV['KALIXA_API_MODE'].downcase == 'production') rescue false
22
24
 
23
- self.api_mode ||= (ENV['KALIXA_API_MODE'].downcase == 'production')
24
25
  end
@@ -2,21 +2,20 @@ module KalixaApi
2
2
  module V3
3
3
  class HttpService
4
4
 
5
- attr_accessor :kalixa_api_user, :kalixa_api_password, :test_kalixa_api_user, :test_kalixa_api_password, :api_mode
6
-
7
- def initialize(username: nil, password: nil)
8
- @kalixa_api_user = kalixa_api_user || KalixaApi.kalixa_api_user
9
- @kalixa_api_password = kalixa_api_password || KalixaApi.kalixa_api_password
10
- @test_kalixa_api_user = test_kalixa_api_user || KalixaApi.test_kalixa_api_user
11
- @test_kalixa_api_password = test_kalixa_api_password || KalixaApi.test_kalixa_api_password
5
+ attr_accessor :api_user, :api_password, :test_api_user, :test_api_password, :api_mode
12
6
 
7
+ def initialize(api_user: nil, api_password: nil, test_api_user: nil, test_api_password: nil, api_mode: nil)
8
+ @api_user = api_user || KalixaApi.api_user
9
+ @api_password = api_password || KalixaApi.api_password
10
+ @test_api_user = test_api_user || KalixaApi.test_api_user
11
+ @test_api_password = test_api_password || KalixaApi.test_api_password
13
12
  @api_mode = api_mode || KalixaApi.api_mode
14
13
  end
15
14
 
16
15
  def connection
17
16
  @connection ||= begin
18
17
  Faraday.new(:url => 'https://api.kalixa.com') do |faraday|
19
- faraday.basic_auth(@kalixa_api_user , @kalixa_api_password)
18
+ faraday.basic_auth(@api_user , @api_password)
20
19
  faraday.adapter Faraday.default_adapter
21
20
  end
22
21
  end
@@ -25,7 +24,7 @@ module KalixaApi
25
24
  def test_conection
26
25
  @connection ||= begin
27
26
  Faraday.new(:url => 'https://api.test.kalixa.com') do |faraday|
28
- faraday.basic_auth(@test_kalixa_api_user, @test_kalixa_api_password)
27
+ faraday.basic_auth(@test_api_user, @test_api_password)
29
28
  faraday.adapter Faraday.default_adapter
30
29
  end
31
30
  end
@@ -45,7 +44,6 @@ module KalixaApi
45
44
  req.body = data.to_xml(:root => xml_root)
46
45
  end
47
46
  end
48
-
49
47
  end
50
48
 
51
49
  def get_request(url, data, xml_root)
@@ -2,14 +2,13 @@ module KalixaApi
2
2
  module V4
3
3
  class HttpService
4
4
 
5
- attr_accessor :kalixa_api_user, :kalixa_api_password, :test_kalixa_api_user, :test_kalixa_api_password, :api_mode
6
-
7
- def initialize(username: nil, password: nil)
8
- @kalixa_api_user = kalixa_api_user || KalixaApi.kalixa_api_user
9
- @kalixa_api_password = kalixa_api_password || KalixaApi.kalixa_api_password
10
- @test_kalixa_api_user = test_kalixa_api_user || KalixaApi.test_kalixa_api_user
11
- @test_kalixa_api_password = test_kalixa_api_password || KalixaApi.test_kalixa_api_password
5
+ attr_accessor :api_user, :api_password, :test_api_user, :test_api_password, :api_mode
12
6
 
7
+ def initialize(api_user: nil, api_password: nil, test_api_user: nil, test_api_password: nil, api_mode: nil)
8
+ @api_user = api_user || KalixaApi.api_user
9
+ @api_password = api_password || KalixaApi.api_password
10
+ @test_api_user = test_api_user || KalixaApi.test_api_user
11
+ @test_api_password = test_api_password || KalixaApi.test_api_password
13
12
  @api_mode = api_mode || KalixaApi.api_mode
14
13
  end
15
14
 
@@ -17,7 +16,7 @@ module KalixaApi
17
16
  @connection ||= begin
18
17
  Faraday.new(:url => 'https://payments.kalixa.com') do |faraday|
19
18
  faraday.response :json, :content_type => /\bjson$/
20
- faraday.basic_auth(@kalixa_api_user , @kalixa_api_password)
19
+ faraday.basic_auth(@api_user , @api_password)
21
20
  faraday.adapter Faraday.default_adapter
22
21
  end
23
22
  end
@@ -27,7 +26,7 @@ module KalixaApi
27
26
  @test_connection ||= begin
28
27
  Faraday.new(:url => 'https://payments.test.kalixa.com') do |faraday|
29
28
  faraday.response :json, :content_type => /\bjson$/
30
- faraday.basic_auth(@test_kalixa_api_user, @test_kalixa_api_password)
29
+ faraday.basic_auth(@test_api_user, @test_api_password)
31
30
  faraday.adapter Faraday.default_adapter
32
31
  end
33
32
  end
@@ -35,13 +34,13 @@ module KalixaApi
35
34
 
36
35
  def post_request(url, data = {})
37
36
  if @api_mode
38
- test_conection.post do |req|
37
+ connection.post do |req|
39
38
  req.url url
40
39
  req.headers['Content-Type'] = 'application/json'
41
40
  req.body = data.to_json
42
41
  end
43
42
  else
44
- connection.post do |req|
43
+ test_conection.post do |req|
45
44
  req.url url
46
45
  req.headers['Content-Type'] = 'application/json'
47
46
  req.body = data.to_json
@@ -51,19 +50,19 @@ module KalixaApi
51
50
 
52
51
  def get_request(url, data = {})
53
52
  if @api_mode
54
- test_conection.get do |req|
53
+ connection.get do |req|
55
54
  req.url url
56
55
  req.headers['Content-Type'] = 'application/json'
56
+ req.body = data.to_json
57
57
  end
58
58
  else
59
- connection.get do |req|
59
+ test_conection.get do |req|
60
60
  req.url url
61
61
  req.headers['Content-Type'] = 'application/json'
62
62
  req.body = data.to_json
63
63
  end
64
64
  end
65
65
  end
66
-
67
66
  end
68
67
  end
69
68
  end
@@ -1,3 +1,3 @@
1
1
  module KalixaApi
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kalixa_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugeniu Tambur