fortenet 3.0.2 → 3.0.3

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
  SHA1:
3
- metadata.gz: 1e67a8b5988114736828681492465ac7762c2030
4
- data.tar.gz: c67486ddabb475c3a6306155b50a6aaa7f7a119e
3
+ metadata.gz: 4ef7780ec10bbeaeb46a6972034216bf7f891462
4
+ data.tar.gz: e5a55d9e20235b79aedc8635732a01511b15441f
5
5
  SHA512:
6
- metadata.gz: 8440db39840e0bf2968d7dad4133be984850287670550e168c8243387758f8f53bb80bc34295ed6a8a0c069f485378e6f6b5fda7d58ee03860031306ba53287b
7
- data.tar.gz: c8f951a2f8d2affe0565837083834a0fa36c2501152eafa6103b0e6562ce2b56eaae5c6e1cc4ecb01e9183b322dddb86e77e764f894ab2d4e9db8c9304bba7a0
6
+ metadata.gz: 023e76cb886af4dbd45432d8fadea074314acb3cf337ed1d38921ceda17788f172e69c1bb3ea35b742af5551ea2968fc49eb9395af47b8678613cdf4cfe0bc65
7
+ data.tar.gz: fdf169c1efbab195c7a79236f0061428cfaf213fd290be10cf518e21f6e3bf193d04f6e142448cd13415e42a448dfe885bf4ed9873bcc4492a7d090617d14935
data/README.md CHANGED
@@ -2,19 +2,18 @@
2
2
 
3
3
  Simple Ruby wrapper for Forte Payments REST API
4
4
 
5
- Learn about the Forte Payments REST API at https://www.forte.net/devdocs/api_resources/forte_api_v3.htm
5
+ Learn about the [Forte Payments REST API](https://www.forte.net/devdocs/api_resources/forte_api_v3.htm)
6
6
 
7
7
  ### Installation
8
- Add this line to your application's Gemfile:
9
8
  ```ruby
10
9
  # in your Gemfile
11
- gem 'fortenet', '3.0.1', git: 'https://github.com/iiwo/fortenet'
10
+ gem 'fortenet'
12
11
 
13
12
  # then...
14
13
  bundle install
15
14
  ```
16
15
 
17
- ### Usage
16
+ ### Setup
18
17
  Create an initializer
19
18
  ```ruby
20
19
  # config/initializers/fortenet.rb
@@ -23,6 +22,7 @@ Create an initializer
23
22
  config.endpoint = ENV['FORTE_ENDPOINT']
24
23
  config.api_login_id = ENV['FORTE_API_LOGIN_ID']
25
24
  config.secure_transaction_key = ENV['FORTE_SECURE_TRANSACTION_KEY']
25
+
26
26
  # use the ID values without the prefixes ie. 123456 and not org_123456
27
27
  config.account_id = ENV['FORTE_ACCOUNT_ID'] # this is also called organization ID
28
28
  config.location_id = ENV['FORTE_LOCATION_ID']
@@ -34,12 +34,23 @@ Create an initializer
34
34
  # optionally configure proxy
35
35
  config.proxy_host = ENV['FORTE_PROXY_HOST']
36
36
  config.proxy_port = ENV['FORTE_PROXY_PORT']
37
- config.proxy_user =ENV['FORTE_PROXY_USER']
37
+ config.proxy_user = ENV['FORTE_PROXY_USER']
38
38
  config.proxy_password = ENV['FORTE_PROXY_PASSWORD']
39
39
  end
40
40
  ```
41
41
 
42
- Perform a request
42
+ ### Usage
43
+
44
+ `Fortenet::Client` implements `find`, `create`, `update`, and `destroy` for interacting with Forte.
45
+
46
+ The first arg for all commands is the relative path without any leading backslashes. The second arg for find/create/update is the request data and may either be a hash or a json string.
47
+
48
+ For example `Fortenet::Client.new.create('transactions, data)` will ensure data is a json string and post to forteat "/organizations/org_#{account_id}/locations/loc_#{location_id}/transactions" with headers setup using initializer config settings for authentication.
49
+
50
+ Forte client calls will return an [`HTTParty::Response`](http://www.rubydoc.info/github/jnunemaker/httparty/HTTParty/Response) which you can interact with. You can also call `parsed_response` on the actual `Fortenet::Client` instance to get back json parsed hash with symbolized keys.
51
+
52
+ #### Examples
53
+
43
54
  ```ruby
44
55
  client = Fortenet::Client.new
45
56
 
@@ -67,11 +78,3 @@ client.create('transactions', request)
67
78
  # sample PUT request
68
79
  client.update('transactions', request)
69
80
  ```
70
-
71
- ## Contributing
72
-
73
- 1. Fork it ( https://github.com/[my-github-username]/fortenet/fork )
74
- 2. Create your feature branch (`git checkout -b my-new-feature`)
75
- 3. Commit your changes (`git commit -am 'Add some feature'`)
76
- 4. Push to the branch (`git push origin my-new-feature`)
77
- 5. Create a new Pull Request
@@ -1,4 +1,5 @@
1
1
  require 'httparty'
2
+ require 'json'
2
3
  require 'fortenet/version'
3
4
 
4
5
  module Fortenet
@@ -29,9 +30,9 @@ module Fortenet
29
30
 
30
31
  end
31
32
 
33
+ require 'fortenet/options'
32
34
  require 'fortenet/request'
33
35
  require 'fortenet/client'
34
36
 
35
-
36
37
  # default starting point
37
38
  Fortenet.debug_output = $stdout
@@ -1,36 +1,32 @@
1
1
  module Fortenet
2
2
  class Client < Fortenet::Request
3
-
4
- def initialize(account_id = Fortenet.account_id, location_id = Fortenet.location_id, attrs = {})
5
- @location_id = location_id
6
- @account_id = account_id
7
- end
8
-
9
- def base_path
10
- "/organizations/org_#{@account_id}/locations/loc_#{@location_id}/"
3
+ def initialize(account_id = Fortenet.account_id, location_id = Fortenet.location_id)
4
+ self.base_path = "/organizations/org_#{account_id}/locations/loc_#{location_id}/"
11
5
  end
12
6
 
13
7
  def find(relative_path, data = nil)
14
- self.get(base_path+relative_path, query: data)
8
+ get(base_path + relative_path, query: data)
15
9
  end
16
10
 
17
11
  def create(relative_path, data = nil)
18
- self.post(base_path+relative_path, body: data_to_json(data))
12
+ post(base_path + relative_path, body: data_to_json(data))
19
13
  end
20
14
 
21
15
  def update(relative_path, data = nil)
22
- self.put(base_path+relative_path, body: data_to_json(data))
16
+ put(base_path + relative_path, body: data_to_json(data))
23
17
  end
24
18
 
25
19
  def destroy(relative_path)
26
- self.delete(base_path+relative_path)
20
+ delete(base_path + relative_path)
27
21
  end
28
22
 
29
23
  private
30
24
 
31
- def data_to_json(data)
32
- data.is_a?(Hash) ? data.to_json : data
33
- end
25
+ attr_accessor :base_path
26
+
27
+ def data_to_json(data)
28
+ data.is_a?(Hash) ? data.to_json : data
29
+ end
34
30
 
35
31
  end
36
- end
32
+ end
@@ -0,0 +1,35 @@
1
+ module Fortenet
2
+ class Options
3
+ def initialize(options)
4
+ self.options = options
5
+ end
6
+
7
+ def call
8
+ {
9
+ format: :plan,
10
+ headers: header_settings
11
+ }.merge(proxy_settings).merge(options)
12
+ end
13
+
14
+ private
15
+
16
+ attr_accessor :options
17
+
18
+ def proxy_settings
19
+ {}.tap do |options|
20
+ options[:http_proxyaddr] = Fortenet.proxy_host if Fortenet.proxy_host.present?
21
+ options[:http_proxyport] = Fortenet.proxy_port if Fortenet.proxy_port.present?
22
+ options[:http_proxyuser] = Fortenet.proxy_user if Fortenet.proxy_user.present?
23
+ options[:http_proxypass] = Fortenet.proxy_password if Fortenet.proxy_user.present?
24
+ end
25
+ end
26
+
27
+ def header_settings
28
+ {
29
+ 'X-Forte-Auth-Organization-Id' => "org_#{Fortenet.account_id}",
30
+ 'Content-Type' => 'application/json',
31
+ 'Authorization' => "Basic #{Base64.strict_encode64("#{Fortenet.api_login_id}:#{Fortenet.secure_transaction_key}")}"
32
+ }
33
+ end
34
+ end
35
+ end
@@ -1,56 +1,42 @@
1
- require 'httparty'
2
- require 'json'
3
-
4
1
  module Fortenet
5
2
  class Request
6
3
  include HTTParty
4
+
7
5
  format :json
8
6
  headers 'Accept' => 'application/json'
9
7
 
10
- def get(path, options={})
11
- set_auth(options)
12
- @response = self.class.get(Fortenet.endpoint + path, options)
13
- end
8
+ attr_reader :response
14
9
 
15
- def post(path, options={})
16
- set_auth(options)
17
- @response = self.class.post(Fortenet.endpoint + path, options)
10
+ def get(path, **options)
11
+ self.response = self.class.get(Fortenet.endpoint + path, set_auth(options))
18
12
  end
19
13
 
20
- def put(path, options={})
21
- set_auth(options)
22
- @response = self.class.put(Fortenet.endpoint + path, options)
14
+ def post(path, **options)
15
+ self.response = self.class.post(Fortenet.endpoint + path, set_auth(options))
23
16
  end
24
17
 
25
- def delete(path, options={})
26
- set_auth(options)
27
- @response = self.class.delete(Fortenet.endpoint + path, options)
18
+ def put(path, **options)
19
+ self.response = self.class.put(Fortenet.endpoint + path, set_auth(options))
28
20
  end
29
21
 
30
- def response
31
- @response
22
+ def delete(path, **options)
23
+ self.response = self.class.delete(Fortenet.endpoint + path, set_auth(options))
32
24
  end
33
25
 
34
26
  def parsed_response
35
- self.response.parsed_response if self.response.present?
27
+ return if response.nil?
28
+
29
+ JSON.parse response.body, symbolize_names: true
36
30
  end
37
31
 
38
32
  private
39
33
 
40
- def set_auth(options)
41
- client_id_and_secret = Base64.strict_encode64("#{Fortenet.api_login_id}:#{Fortenet.secure_transaction_key}")
42
- #options[:ssl_version] = :TLSv1
43
- options[:headers] ||= {}
44
- options[:headers]['X-Forte-Auth-Organization-Id'] = "org_#{Fortenet.account_id}"
45
- options[:headers]["Content-Type"] = "application/json"
46
- options[:headers]['Authorization'] = "Basic #{client_id_and_secret}"
47
-
48
- options[:http_proxyaddr] = Fortenet.proxy_host if Fortenet.proxy_host.present?
49
- options[:http_proxyport] = Fortenet.proxy_port if Fortenet.proxy_port.present?
50
- options[:http_proxyuser] = Fortenet.proxy_user if Fortenet.proxy_user.present?
51
- options[:http_proxypass] = Fortenet.proxy_password if Fortenet.proxy_user.present?
52
- end
34
+ attr_writer :response
35
+
36
+ def set_auth(options)
37
+ Fortenet::Options.new(options).call
38
+ end
53
39
 
54
40
  end
55
41
 
56
- end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Fortenet
2
- VERSION = "3.0.2"
2
+ VERSION = '3.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fortenet
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iwo Dziechciarow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-29 00:00:00.000000000 Z
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -67,6 +67,7 @@ files:
67
67
  - fortenet.gemspec
68
68
  - lib/fortenet.rb
69
69
  - lib/fortenet/client.rb
70
+ - lib/fortenet/options.rb
70
71
  - lib/fortenet/request.rb
71
72
  - lib/fortenet/version.rb
72
73
  homepage: https://github.com/ArcadiaPower/fortenet