bayonet_client 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ed9d0a860656422bcd61a74b7f1f066c47af17f
4
+ data.tar.gz: 0e9170b2c397ce7b0c7683990b8012f34c34a004
5
+ SHA512:
6
+ metadata.gz: ca8532de822ef2514d6ac322a14fb9e49a545d46ce2c6a01a58d23593bb2ea93acd80af4e9993a4b5705531dfce8922a28f63e94445fb0c68bd02401ae1a62dc
7
+ data.tar.gz: 01fed1dad20b252ea759630c350fa19a0297854878f85c6cd43f4ecc56191154901d56c3681afc5be63eaa6a5f967ccb6349d23ffbae4d4e200c66decd5b453f
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
11
+ *.iml
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bayonet_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 imran-bayonet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,132 @@
1
+ ## Bayonet
2
+ Bayonet enables companies to feed and consult a global database about online consumers’ reputation, based on historic payments. Start making smarter business decisions today.
3
+
4
+ ### Introduction
5
+ Bayonet’s API is organized around REST and exposes endpoints for HTTP requests. It is designed to have predictable, resource-oriented URLs and uses standard HTTP response codes to indicate the outcome of operations. Request and response payloads are formatted as JSON.
6
+
7
+ ### About the service
8
+ Bayonet provides an Ecosystem of Trust and Protection where companies can colaborate with each other to combat online fraud together. We provide a secure platform to share and consult data to understand when a consumer is related to fraudulent activity or has a fraud-free record. Different technologies that run algorithms to link parameters seen in different transactions, fed by companies connected to the ecosystem are employed in order to build consumer profiles. By consulting Bayonet’s API, a response with data provided by companies themselves is available in real-time for your risk assesment process to analyze it and take better decisions.
9
+
10
+ ### Bayonet's API details
11
+ To know more about Bayonet's API and its domain and technical details, please see the "Integration Specs V 1.0" document provided by the Bayonet team.
12
+
13
+ ## Getting started
14
+ To use this SDK, please make sure:
15
+ * You have Ruby 2.0 or superior installed on your system.
16
+ * You have an API KEY (sandbox and/or live) provided by Bayonet's team.
17
+ * Install the 'bayonet_client' package on your system
18
+
19
+ ```sh
20
+ gem install bayonet_client
21
+ ```
22
+ Or if you want to build the gem from source:
23
+
24
+ ```sh
25
+ gem build bayonet_client.gemspec
26
+ ```
27
+ * Require 'bayonet_client' in your file
28
+
29
+ ```ruby
30
+ require 'bayonet_client'
31
+ ```
32
+ * Create config options, with parameters (api_key, api_version).
33
+
34
+ ```ruby
35
+ client = BayonetClient::Client.new(api_key, api_version)
36
+ ```
37
+
38
+ ## Usage
39
+ Once you have Bayonet's SDK configured, you can call the three APIs with the following syntax:
40
+ * Consulting API
41
+
42
+ ```ruby
43
+ client.consulting({
44
+ channel: 'mpos',
45
+ email: 'example@bayonet.io',
46
+ consumer_name: 'Example name',
47
+ cardholder_name: 'Example name',
48
+ payment_method: 'card',
49
+ card_number: '4111111111111111',
50
+ transaction_amount: '999',
51
+ currency_code: 'MXN',
52
+ transaction_time: '1476012879',
53
+ coupon: false,
54
+ payment_gateway: 'stripe',
55
+ shipping_address : {
56
+ address_line_1 : 'example line 1',
57
+ address_line_2 : 'example line 2',
58
+ city : 'Mexico City',
59
+ state : 'Mexico DF',
60
+ country : 'MEX',
61
+ zip_code : '64000'
62
+ }
63
+ })
64
+ ```
65
+ * Feedback API
66
+
67
+ ```ruby
68
+ client.feedback({
69
+ transaction_status: 'success',
70
+ transaction_id: 'uhffytd65rds56yt',
71
+ ...
72
+ })
73
+ ```
74
+ * Feedback-historical API
75
+
76
+ ```ruby
77
+ client.feedback_historical({
78
+ channel: 'mpos',
79
+ type: 'transaction',
80
+ email: 'example@bayonet.io',
81
+ consumer_name: 'Example name',
82
+ payment_method: 'card',
83
+ card_number: '4111111111111111',
84
+ transaction_amount: '999',
85
+ currency_code: 'MXN',
86
+ transaction_time: '1423823404',
87
+ transaction_status: 'bank_decline',
88
+ transaction_id: 'uhffytd65rds56yt',
89
+ coupon: false,
90
+ payment_gateway: 'stripe',
91
+ device_fingerprint: 'AF567GHGJJJ87JH',
92
+ bank_auth_code: '5353888',
93
+ telephone: '0000000000',
94
+ expedited_shipping: false,
95
+ bank_decline_reason: 'stolen_card',
96
+ shipping_address: {
97
+ address_line_1: 'example line 1',
98
+ address_line_2: 'example line 2',
99
+ city: 'Mexico City',
100
+ state: 'Mexico DF',
101
+ country: 'MEX',
102
+ zip_code: '64000'
103
+ }
104
+ })
105
+ ```
106
+
107
+ ## Error handling
108
+ Bayonet's SDK raises exceptions both when setting up the client object and executing functions:
109
+ ```ruby
110
+ begin
111
+ client = bayonet.BayonetClient(api_key, api_version)
112
+ rescue BayonetClient::InvalidClientSetupError => e
113
+ puts e.message
114
+ end
115
+ ```
116
+
117
+ ```ruby
118
+ begin
119
+ client.consulting(params) # Or, client.feedback(params) Or, client.feedback_historical(params)
120
+ rescue BayonetClient::BayonetError => e
121
+ puts e.reason_code
122
+ puts e.reason_message
123
+ end
124
+ ```
125
+
126
+ For a full list of error codes and their messages, please refer to the Bayonet API documentation.
127
+
128
+ ## Testing
129
+ You can run the test suite with the following command:
130
+ ```sh
131
+ bundle exec rake
132
+ ```
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ task :default => :spec
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.pattern = './spec/**/*_spec.rb'
7
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bayonet_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'bayonet_client'
8
+ spec.version = BayonetClient::VERSION
9
+ spec.authors = ['Bayonet']
10
+ spec.email = ['support@bayonet.io']
11
+
12
+ spec.summary = %q{Bayonet Ruby API Gem}
13
+ spec.description = %q{Bayonet Ruby API. See https://bayonet.io for details.}
14
+ spec.homepage = 'https://bayonet.io'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'httparty'
25
+
26
+ spec.add_development_dependency 'rspec', '~> 3.5'
27
+ spec.add_development_dependency 'rake'
28
+ end
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'bayonet_client'
5
+
6
+ require 'irb'
7
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,81 @@
1
+ require 'httparty'
2
+ require_relative './bayonet_client/version'
3
+ require_relative './bayonet_client/response.rb'
4
+ require_relative './bayonet_client/exceptions.rb'
5
+
6
+ module BayonetClient
7
+
8
+ class Client
9
+
10
+ def initialize(api_key, version)
11
+
12
+ if version.nil? || version.empty?
13
+ message = 'Please specify Api version'
14
+ raise BayonetClient::InvalidClientSetupError.new message
15
+ elsif !BayonetClient::SUPPORTED_API_VERSIONS.include?(version)
16
+ message = 'This library does not support version specified. Consider updating your dependencies'
17
+ raise BayonetClient::InvalidClientSetupError.new message
18
+ end
19
+
20
+ @api_key = api_key
21
+ @version = version
22
+ end
23
+
24
+ def consulting(params)
25
+ if validate_params(params)
26
+ serialized = json_from_params(params)
27
+ request('/consulting', serialized)
28
+ else
29
+ raise BayonetClient::BayonetError.new(params, '', '', 'Invalid params. Please make sure you pass a params hash')
30
+ end
31
+ end
32
+
33
+ def feedback(params)
34
+ serialized = json_from_params(params)
35
+ request('/feedback', serialized)
36
+ end
37
+
38
+ def feedback_historical(params)
39
+ serialized = json_from_params(params)
40
+ request('/feedback-historical', serialized)
41
+ end
42
+
43
+ def validate_params(params)
44
+ params.class == Hash
45
+ end
46
+
47
+ def json_from_params(params)
48
+ # Add api_key to params
49
+ params[:api_key] = @api_key
50
+ params.to_json
51
+ end
52
+
53
+ def request(route, json_params)
54
+ request_json_string(route, json_params)
55
+ end
56
+
57
+ def request_json_string(route, request_json_args)
58
+ fq_hostname = fully_qualified_api_host_name
59
+ url = "#{fq_hostname}#{route}"
60
+
61
+ headers = {'User-Agent' => 'OfficialBayonetRubySDK',
62
+ 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
63
+
64
+ raw_resp = HTTParty.post(
65
+ url, body: request_json_args, headers: headers, verify: false)
66
+
67
+ if raw_resp.code == 200
68
+ BayonetClient::BayonetResponse.new(raw_resp)
69
+ else
70
+ raise BayonetClient::BayonetError.new(request_json_args, headers, raw_resp.code, raw_resp)
71
+ end
72
+ end
73
+
74
+ def fully_qualified_api_host_name
75
+ default_domain = 'api.bayonet.io'
76
+ api_version_namespace = 'v' + @version
77
+ "https://#{default_domain}/#{api_version_namespace}"
78
+ end
79
+ end
80
+
81
+ end
@@ -0,0 +1,31 @@
1
+ require 'json'
2
+
3
+ module BayonetClient
4
+
5
+ class BayonetError < Exception
6
+ attr_accessor :request_body, :request_headers, :http_response_code, :http_response_json,
7
+ :reason_code, :reason_message
8
+
9
+ def initialize(request_body, request_headers,
10
+ http_response_code, http_response_json)
11
+ self.request_body = request_body
12
+ self.request_headers = request_headers
13
+ self.http_response_code = http_response_code
14
+ self.http_response_json = http_response_json
15
+
16
+ # Get reason_code and reason_message from response
17
+ if http_response_json.class == HTTParty::Response && http_response_json.key?('reason_code')
18
+ self.reason_code = http_response_json['reason_code']
19
+ end
20
+ if http_response_json.class == HTTParty::Response && http_response_json.key?('reason_message')
21
+ self.reason_message = http_response_json['reason_message']
22
+ else
23
+ self.reason_message = http_response_json
24
+ end
25
+ end
26
+ end
27
+
28
+ class InvalidClientSetupError < Exception
29
+ end
30
+
31
+ end
@@ -0,0 +1,35 @@
1
+ require 'json'
2
+
3
+ module BayonetClient
4
+
5
+ class BayonetResponse
6
+ attr_accessor :feedback_api_trans_code, :rules_triggered,
7
+ :risk_level, :payload, :reason_code,
8
+ :reason_message, :request_body
9
+
10
+ def initialize(parsed_response)
11
+
12
+ if parsed_response.key?('feedback_api_trans_code')
13
+ self.feedback_api_trans_code = parsed_response['feedback_api_trans_code']
14
+ end
15
+ if parsed_response.key?('rules_triggered')
16
+ self.rules_triggered = parsed_response['rules_triggered']
17
+ end
18
+ if parsed_response.key?('risk_level')
19
+ self.risk_level = parsed_response['risk_level']
20
+ end
21
+ if parsed_response.key?('payload')
22
+ self.payload = parsed_response['payload']
23
+ end
24
+ if parsed_response.key?('reason_code')
25
+ self.reason_code = parsed_response['reason_code']
26
+ end
27
+ if parsed_response.key?('reason_message')
28
+ self.reason_message = parsed_response['reason_message']
29
+ end
30
+ if parsed_response.key?('request_body')
31
+ self.request_body = parsed_response['request_body']
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ module BayonetClient
2
+ VERSION = '0.1.0'
3
+ SUPPORTED_API_VERSIONS = ['1']
4
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bayonet_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bayonet
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Bayonet Ruby API. See https://bayonet.io for details.
56
+ email:
57
+ - support@bayonet.io
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bayonet_client.gemspec
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/bayonet_client.rb
71
+ - lib/bayonet_client/exceptions.rb
72
+ - lib/bayonet_client/response.rb
73
+ - lib/bayonet_client/version.rb
74
+ homepage: https://bayonet.io
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.5.1
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Bayonet Ruby API Gem
98
+ test_files: []