abenity_ruby 1.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e9404be5d05526d6e087b2225f4f9bc2ed761e3f07f6b0b2dbd9bbccc28f0aaa
4
+ data.tar.gz: 6128f55f43debfcfc97dc120e62401397e22fbff122cacbb5e3f991a1cc01bcb
5
+ SHA512:
6
+ metadata.gz: cf35f7875a1354090183a54ce60f4922dff6ff36daf12e25e6e3f460d5a6c2a08977f1932ce2be51b7f3a17f9ba8fae347b096f88716352da9efa8889546e068
7
+ data.tar.gz: 734169422eb10b3a5b400263e7b80fea97ee40e6b0157e6202ba10faef4692d1bf6b9a47a95e466828352bcf37724dd82ecda9c5abe67e662850425f7f86481e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /keys
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.1
File without changes
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in abenity_ruby.gemspec
6
+ gemspec
7
+
8
+ gem 'nokogiri', '1.8.2'
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ abenity_ruby (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ mini_portile2 (2.3.0)
10
+ minitest (5.11.3)
11
+ nokogiri (1.8.2)
12
+ mini_portile2 (~> 2.3.0)
13
+ rake (10.5.0)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ abenity_ruby!
20
+ bundler (~> 1.16)
21
+ minitest (~> 5.0)
22
+ nokogiri (= 1.8.2)
23
+ rake (~> 10.0)
24
+
25
+ BUNDLED WITH
26
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Roland Creative Group
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.
@@ -0,0 +1,29 @@
1
+ # AbenityRuby
2
+
3
+ A Ruby library for using the Abenity API.
4
+
5
+ You can find the full API documentation in the [official documentation](http://api.abenity.com/documentation).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'abenity_ruby'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install abenity_ruby
22
+
23
+ ## Usage
24
+
25
+ ### See examples folder
26
+
27
+ ## License
28
+
29
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "abenity_ruby/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "abenity_ruby"
8
+ spec.version = AbenityRuby::VERSION
9
+ spec.authors = ["Brent Linville"]
10
+ spec.email = ["webmaster@abenity.com"]
11
+
12
+ spec.summary = %q{A Ruby library for using the Abenity API.}
13
+ spec.description = %q{A Ruby library for using the Abenity API.}
14
+ spec.homepage = "https://github.com/Abenity/abenity-ruby"
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_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "abenity_ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ require "abenity_ruby"
2
+
3
+ ApiClient = AbenityRuby::ApiClient.new(
4
+ "api_username",
5
+ "api_password",
6
+ "api_key"
7
+ )
8
+
9
+ results = ApiClient.deactivate_member('client_user_id');
10
+
11
+ if results['status'] == 'ok'
12
+ puts "Success!"
13
+ else
14
+ puts "There were some errors: \n"
15
+ results['error'].each do |key, value|
16
+ puts "#{key}: #{value} \n"
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require "abenity_ruby"
2
+
3
+ ApiClient = AbenityRuby::ApiClient.new(
4
+ "api_username",
5
+ "api_password",
6
+ "api_key"
7
+ )
8
+
9
+ results = ApiClient.reactivate_member('client_user_id');
10
+
11
+ if results['status'] == 'ok'
12
+ puts "Success!"
13
+ else
14
+ puts "There were some errors: \n"
15
+ results['error'].each do |key, value|
16
+ puts "#{key}: #{value} \n"
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ require "abenity_ruby"
2
+ require "date"
3
+ require "time"
4
+
5
+ ApiClient = AbenityRuby::ApiClient.new(
6
+ "api_username",
7
+ "api_password",
8
+ "api_key"
9
+ )
10
+
11
+ member_info = {
12
+ "creation_time" => (DateTime.now).strftime('%FT%T%:z'),
13
+ "salt" => rand(0..100000),
14
+ "send_welcome_email" => "1",
15
+ "client_user_id" => "1",
16
+ "email" => "john.smith@acme.com",
17
+ "firstname" => "John",
18
+ "lastname" => "Smith",
19
+ "address" => "2134 Main Street",
20
+ "city" => "Irvine",
21
+ "state" => "CA",
22
+ "zip" => "92620",
23
+ "country" => "US",
24
+ "phone" => "234-234-2345",
25
+ "position" => "NA"
26
+ }
27
+
28
+ results = ApiClient.sso_member(
29
+ member_info,
30
+ File.read("file_path_to_private_key")
31
+ )
32
+
33
+ if results['status'] == 'ok'
34
+ puts "Success! Token URL: #{results['data']['token_url']}"
35
+ else
36
+ puts "There were some errors: \n"
37
+ results['error'].each do |key, value|
38
+ puts "#{key}: #{value} \n"
39
+ end
40
+ end
@@ -0,0 +1,218 @@
1
+ require "abenity_ruby/version"
2
+ require "openssl"
3
+ require "base64"
4
+ require "net/https"
5
+ require "uri"
6
+ require "json"
7
+ require "nokogiri"
8
+ require "cgi"
9
+
10
+ module AbenityRuby
11
+ class ApiClient
12
+ PUBLIC_KEY = "-----BEGIN RSA PUBLIC KEY-----\n" +
13
+ "MIGJAoGBALw1VRlS2vYgeIWhjyz+oUaZk4h7AC+BLgUxdZnzVBzyWQCVmv17XvXG\n" +
14
+ "fg+Aqv5Ltix8K37VcrKjleasnJo1R79pGm0H3c0WfpGgXMTGB+mSijFwelZw/L4d\n" +
15
+ "vl7SvA8MEDrN/KthGPy4r/UeV4USvi/y78ducmaIWg0naF9lefpDAgMBAAE=\n" +
16
+ "-----END RSA PUBLIC KEY-----"
17
+
18
+ # Public: Initialize an API Client
19
+ #
20
+ # api_username - A String of the API username
21
+ # api_password - A String of the API password
22
+ # api_key - A String of the API key
23
+ # version - An Integer naming the API version number
24
+ # environment - A String naming the environment
25
+ # timeout - An Integer specifiying the timeout on a request
26
+ def initialize(api_username, api_password, api_key, version = 2, environment = 'live', timeout = 10)
27
+ @api_username = api_username
28
+ @api_password = api_password
29
+ @api_key = api_key
30
+ @version = version
31
+
32
+ if environment == 'live'
33
+ @api_url = 'https://api.abenity.com'
34
+ else
35
+ @api_url = 'https://sandbox.abenity.com'
36
+ end
37
+
38
+ @timeout = timeout
39
+
40
+ @encrypt_cipher = OpenSSL::Cipher.new("DES3")
41
+ @encrypt_cipher.encrypt
42
+
43
+ @triple_des_key = @encrypt_cipher.random_key
44
+ @triple_des_iv = @encrypt_cipher.random_iv
45
+ end
46
+
47
+ # Public: Send a HTTP request to the API
48
+ #
49
+ # api_method - The API method to be called
50
+ # http_method - The HTTP method to be used (GET, POST, PUT, DELETE, etc.)
51
+ # data - Any data to be sent to the API
52
+ #
53
+ # Returns a data-object of the response
54
+ def send_request(api_method, http_method = 'GET', data = nil)
55
+ if data.is_a?(Hash)
56
+ data['api_username'] = @api_username
57
+ data['api_password'] = @api_password
58
+ data['api_key'] = @api_key
59
+
60
+ post_data = data.map{|k,v| "#{CGI::escape(k)}=#{CGI::escape(v)}"}.join('&')
61
+ else
62
+ post_data = sprintf(
63
+ "api_username=%s&api_password=%s&api_key=%s&%s",
64
+ CGI::escape(@api_username),
65
+ CGI::escape(@api_password),
66
+ CGI::escape(@api_key),
67
+ data
68
+ )
69
+ end
70
+
71
+ uri = URI.parse("#{@api_url}/v#{@version}/client#{api_method}")
72
+ http = Net::HTTP.new(uri.host, uri.port)
73
+ http.use_ssl = true
74
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
75
+
76
+ request = http_method == 'GET' ? Net::HTTP::Get.new(uri.request_uri) : Net::HTTP::Post.new(uri.request_uri)
77
+ request.body = !data.nil? ? post_data : ''
78
+
79
+ request.initialize_http_header({
80
+ "User-Agent" => "abenity/abenity-ruby v1"
81
+ })
82
+
83
+ response = http.request(request)
84
+
85
+ return parse_response(response.body)
86
+ end
87
+
88
+ # Public: Single Sign-On a member
89
+ #
90
+ # member_profile - A hash of key/value pairs that describes the member
91
+ # private_key - Your RSA private key, used to sign your message
92
+ #
93
+ # Returns the raw API response
94
+ def sso_member(member_profile, private_key)
95
+ # Convert member profile hash to a HTTP query string
96
+ payload_string = member_profile.map{|k,v| "#{k}=#{v}"}.join('&')
97
+
98
+ # URL encode and Base 64 encode the IV
99
+ iv_urlencoded = "#{CGI::escape(Base64.strict_encode64(@triple_des_iv))}decode"
100
+
101
+ payload = encrypt_payload(payload_string, @triple_des_iv)
102
+ cipher = encrypt_cipher(@triple_des_key)
103
+ signature = sign_message(payload, private_key)
104
+
105
+ data = sprintf(
106
+ "Payload=%s&Cipher=%s&Signature=%s&Iv=%s",
107
+ payload,
108
+ cipher,
109
+ signature,
110
+ iv_urlencoded
111
+ )
112
+
113
+ return send_request('/sso_member.json', 'POST', data)
114
+ end
115
+
116
+ # Public: Deactivate a Member
117
+ #
118
+ # client_user_id - The unique Client User ID for the member
119
+ # send_notification - Set to true to send a notification email
120
+ #
121
+ # Returns the raw API response
122
+ def deactivate_member(client_user_id, send_notification = 'false')
123
+ data = {
124
+ 'client_user_id' => client_user_id,
125
+ 'send_notification' => send_notification
126
+ }
127
+
128
+ return send_request('/deactivate_member.json', 'POST', data)
129
+ end
130
+
131
+ # Public: Reactivate a Member
132
+ #
133
+ # client_user_id - The unique Client User ID for the member
134
+ # send_notification - Set to true to send a notification email
135
+ #
136
+ # Returns the raw API response
137
+ def reactivate_member(client_user_id, send_notification = 'false')
138
+ data = {
139
+ 'client_user_id' => client_user_id,
140
+ 'send_notification' => send_notification
141
+ }
142
+
143
+ return send_request('/reactivate_member.json', 'POST', data)
144
+ end
145
+
146
+ private
147
+
148
+ # Private: Parse the API response
149
+ #
150
+ # response - The response string
151
+ # format - The format of the response to parse
152
+ #
153
+ # Returns the parsed response as a data hash
154
+ def parse_response(response, format = 'json')
155
+ result = nil
156
+
157
+ if format == 'json'
158
+ result = JSON.parse(response)
159
+ elsif format == 'xml'
160
+ result = Nokogiri::XML(response)
161
+ end
162
+
163
+ return result
164
+ end
165
+
166
+ # Private: Symmetrically encrypt a string of information
167
+ #
168
+ # payload_string - An input string
169
+ # iv - An initialization vector for Triple-DES in CBC mode
170
+ #
171
+ # Returns a base64-encoded and url-encoded representation of the $payload_string
172
+ def encrypt_payload(payload_string, iv)
173
+ payload_urlencoded = ''
174
+
175
+ encrypted = @encrypt_cipher.update(payload_string) + @encrypt_cipher.final
176
+ encypted_base64 = Base64.strict_encode64(encrypted)
177
+ payload_urlencoded = "#{CGI::escape(encypted_base64)}decode"
178
+
179
+ return payload_urlencoded
180
+ end
181
+
182
+ # Private: Asymmetrically encrypt a symmetrical encryption key
183
+ #
184
+ # triple_des_key - A Triple DES (3DES) encryption key
185
+ #
186
+ # Returns a base64-encoded and url-encoded representation of the $triple_des_key
187
+ def encrypt_cipher(triple_des_key)
188
+ triple_des_key_urlencoded = ''
189
+
190
+ key = OpenSSL::PKey::RSA.new(PUBLIC_KEY)
191
+ encrypted_triple_des = key.public_encrypt(triple_des_key)
192
+ encrypted_base64 = Base64.strict_encode64(encrypted_triple_des)
193
+ triple_des_key_urlencoded = "#{CGI::escape(encrypted_base64)}decode"
194
+
195
+ return triple_des_key_urlencoded
196
+ end
197
+
198
+ # Private: Sign a message using a private RSA key
199
+ #
200
+ # payload - The message to be signed
201
+ # private_key - An RSA private key
202
+ #
203
+ # Returns a base64-encoded and url-encoded hash of the $payload_string
204
+ def sign_message(payload, private_key)
205
+ signature_urlencoded = ''
206
+
207
+ key = OpenSSL::PKey::RSA.new(private_key)
208
+
209
+ payload_decoded = CGI::unescape(payload.chomp('decode'))
210
+
211
+ signature = key.sign(OpenSSL::Digest::MD5.new, payload_decoded)
212
+ signature_base64 = Base64.strict_encode64(signature)
213
+ signature_urlencoded = "#{CGI::escape(signature_base64)}decode"
214
+
215
+ return signature_urlencoded
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,3 @@
1
+ module AbenityRuby
2
+ VERSION = "1.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: abenity_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brent Linville
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: A Ruby library for using the Abenity API.
56
+ email:
57
+ - webmaster@abenity.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - abenity_ruby.gemspec
71
+ - bin/console
72
+ - bin/setup
73
+ - examples/deactivate_member.rb
74
+ - examples/reactivate_member.rb
75
+ - examples/sso_member.rb
76
+ - lib/abenity_ruby.rb
77
+ - lib/abenity_ruby/version.rb
78
+ homepage: https://github.com/Abenity/abenity-ruby
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.7.5
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A Ruby library for using the Abenity API.
102
+ test_files: []