engaging-networks-rest 0.6.0 → 1.0.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 +4 -4
- data/.github/workflows/ci.yml +35 -0
- data/.gitignore +53 -0
- data/.rubocop.yml +14 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +18 -0
- data/Gemfile +4 -11
- data/LICENSE.txt +1 -1
- data/README.md +3 -1
- data/Rakefile +10 -25
- data/VERSION +1 -1
- data/engaging-networks-rest.gemspec +23 -60
- data/example.rb +8 -6
- data/lib/engaging_networks_rest/client/pages.rb +8 -9
- data/lib/engaging_networks_rest/client.rb +8 -10
- data/lib/engaging_networks_rest/response/raise_error.rb +11 -7
- data/lib/engaging_networks_rest.rb +4 -2
- metadata +39 -38
- data/spec/client/pages_spec.rb +0 -108
- data/spec/client_spec.rb +0 -24
- data/spec/spec_helper.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50d7f225fefc60a2c7aca2d2bc17c290a0a483548d86b78cb138b1333a131c09
|
4
|
+
data.tar.gz: e172253dbccf464fa9f8862e0dcb5afd3802cc5745f1dd7a79fe4fdfc8981d9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5363d9b2582910b3b54a69eff21226508fe39986a89103f73676ffc5b18436a7d787b3890940e7d1a7d2b8d803534507ba2cdd2b1c3d2531cc2de1409b05f2de
|
7
|
+
data.tar.gz: 0efb3821b1caf980c4a56c2acf87fc2814721e8e7206bcfb853e22de59798a16d48ea3a66b8506b8e781bdd6174bc48ee395da3eb218e49287eeb14035813986
|
@@ -0,0 +1,35 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push]
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
test:
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby-version: ['3.1', '3.2']
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: ${{ matrix.ruby-version }}
|
17
|
+
bundler-cache: true
|
18
|
+
- run: bundle install
|
19
|
+
- run: bundle exec rspec
|
20
|
+
|
21
|
+
rubocop:
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
|
24
|
+
strategy:
|
25
|
+
matrix:
|
26
|
+
ruby-version: ['3.1', '3.2']
|
27
|
+
|
28
|
+
steps:
|
29
|
+
- uses: actions/checkout@v2
|
30
|
+
- uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true
|
34
|
+
- run: bundle install
|
35
|
+
- run: bundle exec rubocop
|
data/.gitignore
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
51
|
+
|
52
|
+
.idea/
|
53
|
+
.byebug_history
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'engaging-networks-rest.gemspec'
|
4
|
+
- 'example.rb'
|
5
|
+
- 'vendor/**/*'
|
6
|
+
|
7
|
+
Metrics/BlockLength:
|
8
|
+
Enabled: false
|
9
|
+
Metrics/MethodLength:
|
10
|
+
Enabled: false
|
11
|
+
Style/Documentation:
|
12
|
+
Enabled: false
|
13
|
+
Style/GuardClause:
|
14
|
+
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.4
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [1.0.0] - 2023-10-17
|
4
|
+
|
5
|
+
### BREAKING CHANGES
|
6
|
+
- Drops support for ruby versions 2.7 and 3.0. Only ruby 3.1 or newer is now supported.
|
7
|
+
- `EngagingNetworksRest.new` and `EngagingNetworksRest::Client.new` now require the `host` parameter
|
8
|
+
|
9
|
+
### Development changes
|
10
|
+
- Removed juwelier. Dependencies are now managed only in the gemspec file.
|
11
|
+
- Replaced byebug with debug
|
12
|
+
- Upgraded required faker version to eliminate the need for pinning psych
|
13
|
+
|
14
|
+
## [0.7.0] - 2023-10-16
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- Adds support for passing a `host` parameter to EngagingNetworksRest.new and EngagingNetworksRest::Client.new
|
18
|
+
- Ruby versions 3.0, 3.1, and 3.2 are officially supported in addition to ruby 2.7
|
data/Gemfile
CHANGED
@@ -1,13 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
gem 'faraday_middleware'
|
3
|
+
source 'https://rubygems.org'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
gem 'juwelier', git: 'https://github.com/flajann2/juwelier.git'
|
9
|
-
gem 'webmock', '> 3.4'
|
10
|
-
gem 'faker', '> 1.9'
|
11
|
-
gem 'pry-byebug', '> 3.6'
|
12
|
-
gem 'faraday-detailed_logger', '>= 2.1.2'
|
13
|
-
end
|
5
|
+
# Gem's dependencies are specified in engaging-networks-rest.gemspec
|
6
|
+
gemspec
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# engaging-networks-rest
|
2
2
|
Client gem for the ENS API to Engaging Networks
|
3
3
|
|
4
|
+
[](https://github.com/controlshift/engaging-networks-rest/actions/workflows/ci.yml)
|
5
|
+
|
4
6
|
## Install
|
5
7
|
|
6
8
|
`gem install engaging-networks-rest`
|
@@ -8,7 +10,7 @@ Client gem for the ENS API to Engaging Networks
|
|
8
10
|
## Usage
|
9
11
|
|
10
12
|
```
|
11
|
-
client = EngagingNetworksRest.new(api_key: 'YOUR API KEY HERE')
|
13
|
+
client = EngagingNetworksRest.new(api_key: 'YOUR API KEY HERE', host: 'us.engagingnetworks.app')
|
12
14
|
|
13
15
|
# get pages by type
|
14
16
|
pages = client.pages(type: 'dcf', status: 'live')
|
data/Rakefile
CHANGED
@@ -1,50 +1,35 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'bundler'
|
5
5
|
begin
|
6
6
|
Bundler.setup(:default, :development)
|
7
7
|
rescue Bundler::BundlerError => e
|
8
|
-
|
9
|
-
|
8
|
+
warn e.message
|
9
|
+
warn 'Run `bundle install` to install missing gems'
|
10
10
|
exit e.status_code
|
11
11
|
end
|
12
12
|
require 'rake'
|
13
13
|
|
14
|
-
require 'juwelier'
|
15
|
-
Juwelier::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
-
gem.name = "engaging-networks-rest"
|
18
|
-
gem.homepage = "http://github.com/controlshift/engaging-networks-rest"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{Client gem for the ENS API to Engaging Networks}
|
21
|
-
gem.description = %Q{Client gem for the ENS API to Engaging Networks}
|
22
|
-
gem.email = "jacinda@controlshiftlabs.com"
|
23
|
-
gem.authors = ["Jacinda Moore"]
|
24
|
-
|
25
|
-
# dependencies defined in Gemfile
|
26
|
-
end
|
27
|
-
Juwelier::RubygemsDotOrgTasks.new
|
28
|
-
|
29
14
|
require 'rspec/core/rake_task'
|
30
|
-
desc
|
15
|
+
desc 'Run specs'
|
31
16
|
RSpec::Core::RakeTask.new do |t|
|
32
|
-
t.pattern =
|
17
|
+
t.pattern = './spec/**/*_spec.rb' # don't need this, it's default.
|
33
18
|
t.rspec_opts = '--color'
|
34
19
|
end
|
35
20
|
|
36
|
-
desc
|
21
|
+
desc 'Code coverage detail'
|
37
22
|
task :simplecov do
|
38
|
-
ENV['COVERAGE'] =
|
23
|
+
ENV['COVERAGE'] = 'true'
|
39
24
|
Rake::Task['test'].execute
|
40
25
|
end
|
41
26
|
|
42
|
-
desc 'Default: run specs
|
43
|
-
task :
|
27
|
+
desc 'Default: run specs'
|
28
|
+
task default: :spec
|
44
29
|
|
45
30
|
require 'rdoc/task'
|
46
31
|
Rake::RDocTask.new do |rdoc|
|
47
|
-
version = File.exist?('VERSION') ? File.read('VERSION') :
|
32
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ''
|
48
33
|
|
49
34
|
rdoc.rdoc_dir = 'rdoc'
|
50
35
|
rdoc.title = "engaging-networks-rest #{version}"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
@@ -1,79 +1,42 @@
|
|
1
|
-
#
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: engaging-networks-rest 0.6.0 ruby lib
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
3
|
Gem::Specification.new do |s|
|
8
4
|
s.name = "engaging-networks-rest".freeze
|
9
|
-
s.version = "0.
|
5
|
+
s.version = "1.0.0"
|
10
6
|
|
11
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
8
|
s.require_paths = ["lib".freeze]
|
13
|
-
s.authors = ["
|
14
|
-
s.date = "
|
9
|
+
s.authors = ["Grey Moore".freeze]
|
10
|
+
s.date = "2023-10-17"
|
15
11
|
s.description = "Client gem for the ENS API to Engaging Networks".freeze
|
16
|
-
s.email = "
|
12
|
+
s.email = "systems@controlshiftlabs.com".freeze
|
17
13
|
s.extra_rdoc_files = [
|
18
14
|
"LICENSE",
|
19
15
|
"LICENSE.txt",
|
20
16
|
"README.md"
|
21
17
|
]
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
"
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
"VERSION",
|
31
|
-
"engaging-networks-rest.gemspec",
|
32
|
-
"example.rb",
|
33
|
-
"lib/engaging_networks_rest.rb",
|
34
|
-
"lib/engaging_networks_rest/client.rb",
|
35
|
-
"lib/engaging_networks_rest/client/pages.rb",
|
36
|
-
"lib/engaging_networks_rest/response/raise_error.rb",
|
37
|
-
"spec/client/pages_spec.rb",
|
38
|
-
"spec/client_spec.rb",
|
39
|
-
"spec/spec_helper.rb"
|
40
|
-
]
|
41
|
-
s.homepage = "http://github.com/controlshift/engaging-networks-rest".freeze
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
s.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
|
25
|
+
s.homepage = 'https://github.com/controlshift/engaging-networks-rest'.freeze
|
42
26
|
s.licenses = ["MIT".freeze]
|
43
|
-
s.rubygems_version = "3.0.8".freeze
|
44
27
|
s.summary = "Client gem for the ENS API to Engaging Networks".freeze
|
45
28
|
|
46
29
|
if s.respond_to? :specification_version then
|
47
30
|
s.specification_version = 4
|
48
|
-
|
49
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
-
s.add_runtime_dependency(%q<faraday>.freeze, [">= 1.0"])
|
51
|
-
s.add_runtime_dependency(%q<faraday_middleware>.freeze, [">= 0"])
|
52
|
-
s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
|
53
|
-
s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
|
54
|
-
s.add_development_dependency(%q<webmock>.freeze, ["> 3.4"])
|
55
|
-
s.add_development_dependency(%q<faker>.freeze, ["> 1.9"])
|
56
|
-
s.add_development_dependency(%q<pry-byebug>.freeze, ["> 3.6"])
|
57
|
-
s.add_development_dependency(%q<faraday-detailed_logger>.freeze, [">= 2.1.2"])
|
58
|
-
else
|
59
|
-
s.add_dependency(%q<faraday>.freeze, [">= 1.0"])
|
60
|
-
s.add_dependency(%q<faraday_middleware>.freeze, [">= 0"])
|
61
|
-
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
62
|
-
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
63
|
-
s.add_dependency(%q<webmock>.freeze, ["> 3.4"])
|
64
|
-
s.add_dependency(%q<faker>.freeze, ["> 1.9"])
|
65
|
-
s.add_dependency(%q<pry-byebug>.freeze, ["> 3.6"])
|
66
|
-
s.add_dependency(%q<faraday-detailed_logger>.freeze, [">= 2.1.2"])
|
67
|
-
end
|
68
|
-
else
|
69
|
-
s.add_dependency(%q<faraday>.freeze, [">= 1.0"])
|
70
|
-
s.add_dependency(%q<faraday_middleware>.freeze, [">= 0"])
|
71
|
-
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
72
|
-
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
73
|
-
s.add_dependency(%q<webmock>.freeze, ["> 3.4"])
|
74
|
-
s.add_dependency(%q<faker>.freeze, ["> 1.9"])
|
75
|
-
s.add_dependency(%q<pry-byebug>.freeze, ["> 3.6"])
|
76
|
-
s.add_dependency(%q<faraday-detailed_logger>.freeze, [">= 2.1.2"])
|
77
31
|
end
|
78
|
-
end
|
79
32
|
|
33
|
+
s.add_runtime_dependency(%q<faraday>.freeze, [">= 1.0"])
|
34
|
+
s.add_runtime_dependency(%q<faraday_middleware>.freeze, [">= 0"])
|
35
|
+
|
36
|
+
s.add_development_dependency(%q<faker>.freeze, ["> 2.20.0"])
|
37
|
+
s.add_development_dependency(%q<faraday-detailed_logger>.freeze, [">= 2.1.2"])
|
38
|
+
s.add_development_dependency(%q<debug>.freeze, ["> 0"])
|
39
|
+
s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
|
40
|
+
s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
|
41
|
+
s.add_development_dependency(%q<webmock>.freeze, ["> 3.4"])
|
42
|
+
end
|
data/example.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
|
2
4
|
|
3
5
|
require 'engaging_networks_rest'
|
@@ -7,16 +9,16 @@ require 'byebug'
|
|
7
9
|
def instrument_connection_with_extended_logging(client)
|
8
10
|
default_options = {
|
9
11
|
headers: {
|
10
|
-
'Accept' =>
|
11
|
-
'Accept-Charset' =>
|
12
|
+
'Accept' => 'application/json;q=0.1',
|
13
|
+
'Accept-Charset' => 'utf-8'
|
12
14
|
}
|
13
15
|
}
|
14
16
|
|
15
|
-
faraday_builder =
|
17
|
+
faraday_builder = lambda do |faraday|
|
16
18
|
faraday.request :json
|
17
|
-
faraday.response :json, :
|
19
|
+
faraday.response :json, content_type: /\bjson$/
|
18
20
|
faraday.use Faraday::Response::Logger if ENV['DEBUG']
|
19
|
-
faraday.use
|
21
|
+
faraday.use EngagingNetworksRest::Response::RaiseError
|
20
22
|
faraday.response :detailed_logger
|
21
23
|
faraday.adapter Faraday.default_adapter
|
22
24
|
end
|
@@ -33,4 +35,4 @@ instrument_connection_with_extended_logging(client)
|
|
33
35
|
|
34
36
|
byebug
|
35
37
|
|
36
|
-
puts
|
38
|
+
puts 'Bye!'
|
@@ -1,13 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module EngagingNetworksRest
|
2
4
|
class Client
|
3
5
|
module Pages
|
4
6
|
def pages(type:, status: nil)
|
5
|
-
filter_params = {'type' => type}
|
6
|
-
unless status.nil?
|
7
|
-
filter_params['status'] = status
|
8
|
-
end
|
7
|
+
filter_params = { 'type' => type }
|
8
|
+
filter_params['status'] = status unless status.nil?
|
9
9
|
|
10
|
-
get(path:
|
10
|
+
get(path: '/ens/service/page', params: filter_params)
|
11
11
|
end
|
12
12
|
|
13
13
|
def page(page_id:)
|
@@ -15,10 +15,9 @@ module EngagingNetworksRest
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def process_page_request(page_id:, supporter_data:, generic_data: {})
|
18
|
-
response = post(path: "/ens/service/page/#{page_id}/process",
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
response = post(path: "/ens/service/page/#{page_id}/process",
|
19
|
+
body: generic_data.merge(supporter: supporter_data))
|
20
|
+
return response if response['status'] == 'SUCCESS'
|
22
21
|
|
23
22
|
raise "Unexpected 'status' value on response: #{response}"
|
24
23
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'faraday_middleware'
|
3
5
|
require 'engaging_networks_rest/client/pages'
|
@@ -7,14 +9,12 @@ module EngagingNetworksRest
|
|
7
9
|
class Client
|
8
10
|
attr_reader :api_key, :connection, :ens_auth_key
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
def initialize(api_key:)
|
12
|
+
def initialize(api_key:, host:)
|
13
13
|
@api_key = api_key
|
14
14
|
|
15
|
-
@connection = Faraday.new(url: "https://#{
|
15
|
+
@connection = Faraday.new(url: "https://#{host}") do |conn|
|
16
16
|
conn.request :json
|
17
|
-
conn.response :json, :
|
17
|
+
conn.response :json, content_type: /\bjson$/
|
18
18
|
|
19
19
|
conn.use Faraday::Response::Logger if ENV['DEBUG']
|
20
20
|
conn.use EngagingNetworksRest::Response::RaiseError
|
@@ -38,11 +38,11 @@ module EngagingNetworksRest
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def get(path:, params: {})
|
41
|
-
request(method: :get, path
|
41
|
+
request(method: :get, path:, params:)
|
42
42
|
end
|
43
43
|
|
44
44
|
def post(path:, body: {})
|
45
|
-
request(method: :post, path
|
45
|
+
request(method: :post, path:, body:)
|
46
46
|
end
|
47
47
|
|
48
48
|
include EngagingNetworksRest::Client::Pages
|
@@ -50,9 +50,7 @@ module EngagingNetworksRest
|
|
50
50
|
private
|
51
51
|
|
52
52
|
def request(method:, path:, params: {}, body: {})
|
53
|
-
unless authenticated?
|
54
|
-
authenticate!
|
55
|
-
end
|
53
|
+
authenticate! unless authenticated?
|
56
54
|
|
57
55
|
response = connection.send(method) do |req|
|
58
56
|
req.headers['Content-Type'] = 'application/json'
|
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module EngagingNetworksRest
|
2
4
|
module Response
|
3
|
-
class NotFound < StandardError
|
4
|
-
|
5
|
+
class NotFound < StandardError; end
|
6
|
+
|
7
|
+
class Unauthorized < StandardError; end
|
8
|
+
|
5
9
|
class InternalError < StandardError; end
|
6
10
|
|
7
11
|
class RaiseError < Faraday::Response::Middleware
|
@@ -10,19 +14,19 @@ module EngagingNetworksRest
|
|
10
14
|
if (400...600).include? status_code
|
11
15
|
case status_code
|
12
16
|
when 401
|
13
|
-
raise Unauthorized
|
17
|
+
raise Unauthorized, error_message(response)
|
14
18
|
when 404
|
15
|
-
raise NotFound
|
19
|
+
raise NotFound, error_message(response)
|
16
20
|
when 500
|
17
|
-
raise InternalError
|
21
|
+
raise InternalError, error_message(response)
|
18
22
|
else
|
19
|
-
raise StandardError
|
23
|
+
raise StandardError, error_message(response)
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
28
|
def error_message(response)
|
25
|
-
"#{response[:method].to_s.upcase} #{response[:url]
|
29
|
+
"#{response[:method].to_s.upcase} #{response[:url]}: #{response[:status]} \n\n #{response[:body]}"
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'engaging_networks_rest/client'
|
2
4
|
|
3
5
|
module EngagingNetworksRest
|
4
6
|
class << self
|
5
|
-
def new(api_key:)
|
6
|
-
EngagingNetworksRest::Client.new(api_key:
|
7
|
+
def new(api_key:, host:)
|
8
|
+
EngagingNetworksRest::Client.new(api_key:, host:)
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: engaging-networks-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Grey Moore
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -39,91 +39,91 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: faker
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 2.20.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 2.20.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: faraday-detailed_logger
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.1.2
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.1.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: debug
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: webmock
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: '3.4'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - ">"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: '3.4'
|
125
125
|
description: Client gem for the ENS API to Engaging Networks
|
126
|
-
email:
|
126
|
+
email: systems@controlshiftlabs.com
|
127
127
|
executables: []
|
128
128
|
extensions: []
|
129
129
|
extra_rdoc_files:
|
@@ -131,8 +131,12 @@ extra_rdoc_files:
|
|
131
131
|
- LICENSE.txt
|
132
132
|
- README.md
|
133
133
|
files:
|
134
|
+
- ".github/workflows/ci.yml"
|
135
|
+
- ".gitignore"
|
136
|
+
- ".rubocop.yml"
|
134
137
|
- ".ruby-gemset"
|
135
138
|
- ".ruby-version"
|
139
|
+
- CHANGELOG.md
|
136
140
|
- Gemfile
|
137
141
|
- LICENSE
|
138
142
|
- LICENSE.txt
|
@@ -145,14 +149,11 @@ files:
|
|
145
149
|
- lib/engaging_networks_rest/client.rb
|
146
150
|
- lib/engaging_networks_rest/client/pages.rb
|
147
151
|
- lib/engaging_networks_rest/response/raise_error.rb
|
148
|
-
|
149
|
-
- spec/client_spec.rb
|
150
|
-
- spec/spec_helper.rb
|
151
|
-
homepage: http://github.com/controlshift/engaging-networks-rest
|
152
|
+
homepage: https://github.com/controlshift/engaging-networks-rest
|
152
153
|
licenses:
|
153
154
|
- MIT
|
154
155
|
metadata: {}
|
155
|
-
post_install_message:
|
156
|
+
post_install_message:
|
156
157
|
rdoc_options: []
|
157
158
|
require_paths:
|
158
159
|
- lib
|
@@ -167,8 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
168
|
- !ruby/object:Gem::Version
|
168
169
|
version: '0'
|
169
170
|
requirements: []
|
170
|
-
rubygems_version: 3.
|
171
|
-
signing_key:
|
171
|
+
rubygems_version: 3.3.26
|
172
|
+
signing_key:
|
172
173
|
specification_version: 4
|
173
174
|
summary: Client gem for the ENS API to Engaging Networks
|
174
175
|
test_files: []
|
data/spec/client/pages_spec.rb
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe EngagingNetworksRest::Client::Pages do
|
4
|
-
let(:api_key) { 'abc-123' }
|
5
|
-
let(:ens_auth_key) { 'tmp-auth-key-456' }
|
6
|
-
let(:standard_headers) { {'Content-Type' => 'application/json', 'Ens-Auth-Token' => ens_auth_key} }
|
7
|
-
|
8
|
-
subject { EngagingNetworksRest::Client.new(api_key: api_key) }
|
9
|
-
|
10
|
-
describe '#pages' do
|
11
|
-
let(:page_type) { 'dcf' }
|
12
|
-
let(:page_status) { 'live' }
|
13
|
-
let(:pages_url) { "https://#{EngagingNetworksRest::Client::ENS_DOMAIN}/ens/service/page" }
|
14
|
-
|
15
|
-
# The API docs don't actually say what this response looks like, so this is a guess.
|
16
|
-
# Fortunately, it doesn't actually matter for our purposes, since we just return whatever JSON we get.
|
17
|
-
let(:response) { [{'id' => 123, 'title' => 'A page'}, {'id' => 234, 'title' => 'Another page'}] }
|
18
|
-
|
19
|
-
shared_examples_for 'list pages' do
|
20
|
-
it 'should get pages' do
|
21
|
-
stub_request(:get, pages_url).with(headers: standard_headers, query: {'type' => page_type, 'status' => page_status})
|
22
|
-
.to_return(status: '200', headers: {content_type: "application/json; charset=utf-8"}, body: response.to_json)
|
23
|
-
|
24
|
-
expect(subject.pages(type: page_type, status: page_status)).to eq response
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should omit status param if not specified' do
|
28
|
-
stub_request(:get, pages_url).with(headers: standard_headers, query: {'type' => page_type})
|
29
|
-
.to_return(status: '200', headers: {content_type: "application/json; charset=utf-8"}, body: response.to_json)
|
30
|
-
|
31
|
-
expect(subject.pages(type: page_type)).to eq response
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'not already authenticated' do
|
36
|
-
before :each do
|
37
|
-
expect(subject).to receive(:authenticate!) do
|
38
|
-
allow(subject).to receive(:ens_auth_key).and_return(ens_auth_key)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
include_examples 'list pages'
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'already authenticated' do
|
46
|
-
before :each do
|
47
|
-
allow(subject).to receive(:ens_auth_key).and_return(ens_auth_key)
|
48
|
-
end
|
49
|
-
|
50
|
-
include_examples 'list pages'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '#process_page_request' do
|
55
|
-
let(:page_id) { 234 }
|
56
|
-
let(:page_req_url) { "https://#{EngagingNetworksRest::Client::ENS_DOMAIN}/ens/service/page/#{page_id}/process" }
|
57
|
-
let(:email) { Faker::Internet.email }
|
58
|
-
let(:supporter_hash) { {'firstName' => 'Joe', 'lastName' => 'Smith', 'emailAddress' => email, 'customField1' => 'foo'} }
|
59
|
-
let(:response) { {'id' => '1234567', 'status' => 'SUCCESS', 'supporterEmailAddress' => email, 'supporterId' => '98765'} }
|
60
|
-
let(:failure_response) { {'status' => 'ERROR', 'message' => 'Something went wrong'} }
|
61
|
-
|
62
|
-
shared_examples_for 'process page request' do
|
63
|
-
it 'should send correct body for supporter and generic data' do
|
64
|
-
stub_request(:post, page_req_url)
|
65
|
-
.with(body: {'txn1' => 'foo', 'txn2' => 'bar', 'suppressAutoResponder' => true, supporter: { 'lastName' => 'Smith', 'emailAddress' => email }}.to_json, headers: standard_headers)
|
66
|
-
.to_return(status: '200', headers: {content_type: "application/json; charset=utf-8"}, body: response.to_json)
|
67
|
-
|
68
|
-
result = subject.process_page_request(page_id: page_id, generic_data: { 'txn1' => 'foo', 'txn2' => 'bar', 'suppressAutoResponder' => true }, supporter_data: { 'lastName' => 'Smith', 'emailAddress' => email })
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should process the page request and return its ID' do
|
72
|
-
stub_request(:post, page_req_url).with(body: {supporter: supporter_hash}.to_json, headers: standard_headers)
|
73
|
-
.to_return(status: '200', headers: {content_type: "application/json; charset=utf-8"}, body: response.to_json)
|
74
|
-
|
75
|
-
result = subject.process_page_request(page_id: page_id, supporter_data: supporter_hash)
|
76
|
-
|
77
|
-
expect(result['id']).to eq '1234567'
|
78
|
-
expect(result['supporterId']).to eq '98765'
|
79
|
-
expect(result['supporterEmailAddress']).to eq email
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should raise if response status is not SUCCESS' do
|
83
|
-
stub_request(:post, page_req_url).with(body: {supporter: supporter_hash}.to_json, headers: standard_headers)
|
84
|
-
.to_return(status: '200', headers: {content_type: "application/json; charset=utf-8"}, body: failure_response.to_json)
|
85
|
-
|
86
|
-
expect { subject.process_page_request(page_id: page_id, supporter_data: supporter_hash) }.to raise_error(RuntimeError, /Unexpected 'status' value on response.*Something went wrong/)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'not already authenticated' do
|
91
|
-
before :each do
|
92
|
-
expect(subject).to receive(:authenticate!) do
|
93
|
-
allow(subject).to receive(:ens_auth_key).and_return(ens_auth_key)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
include_examples 'process page request'
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'already authenticated' do
|
101
|
-
before :each do
|
102
|
-
allow(subject).to receive(:ens_auth_key).and_return(ens_auth_key)
|
103
|
-
end
|
104
|
-
|
105
|
-
include_examples 'process page request'
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
data/spec/client_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe EngagingNetworksRest::Client do
|
4
|
-
let(:api_key) { 'abc123' }
|
5
|
-
let(:content_type_header) { {'Content-Type' => 'application/json'} }
|
6
|
-
|
7
|
-
subject { EngagingNetworksRest::Client.new(api_key: api_key) }
|
8
|
-
|
9
|
-
describe '#authenticate!' do
|
10
|
-
let(:auth_url) { "https://#{EngagingNetworksRest::Client::ENS_DOMAIN}/ens/service/authenticate" }
|
11
|
-
let(:auth_key) { '75491e42-99dc-45ce-b637-a681bede875c' }
|
12
|
-
let(:auth_key_body) { "{\"ens-auth-token\":\"#{auth_key}\",\"expires\":3600000}" }
|
13
|
-
|
14
|
-
before :each do
|
15
|
-
stub_request(:post, auth_url).with(body: api_key, headers: content_type_header).to_return(body: auth_key_body, headers: content_type_header)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should set the ens_auth_key on the client' do
|
19
|
-
subject.authenticate!
|
20
|
-
|
21
|
-
expect(subject.ens_auth_key).to eq auth_key
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require 'webmock/rspec'
|
3
|
-
require 'faker'
|
4
|
-
|
5
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
6
|
-
|
7
|
-
require 'engaging_networks_rest'
|
8
|
-
|
9
|
-
RSpec.configure do |config|
|
10
|
-
config.include WebMock::API
|
11
|
-
|
12
|
-
config.before :each do
|
13
|
-
WebMock.reset!
|
14
|
-
end
|
15
|
-
|
16
|
-
config.after :each do
|
17
|
-
WebMock.reset!
|
18
|
-
end
|
19
|
-
end
|