adobe-campaign 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de1679f1ea719170ca93ad2f55aee14d102f30a7
4
+ data.tar.gz: d57b65eb5e6bd7e21574e84625eb4e201353c4c1
5
+ SHA512:
6
+ metadata.gz: a34d6979b594397ddc4c87630f17666a693f38d071c3d282e773e129b7171502423e1fb9a6c57221362cb9a65f706a289a8024f1bca13172057c0812c8cd5198
7
+ data.tar.gz: 0aece9875ca3c0ad716e88ce247fa36736412a326814b162be8bddc75207eaff63fb50e1c03d52e012166394e14d48614ad2641e7d94fd640dd859c05367c6ae
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
+ /cache/
11
+ /vendor/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,34 @@
1
+ AllCops:
2
+ Include:
3
+ - Rakefile
4
+ - config.ru
5
+ - lib/tasks/**/*.rake
6
+ Exclude:
7
+ - vendor/**/*
8
+ - bin/**/*
9
+
10
+ UseCache: true
11
+ CacheRootDirectory: 'cache/'
12
+ TargetRubyVersion: 2.3
13
+
14
+ Rails:
15
+ Enabled: true
16
+
17
+ Documentation:
18
+ Enabled: false
19
+
20
+ MethodLength:
21
+ Severity: warning
22
+ Max: 15
23
+
24
+ Metrics/LineLength:
25
+ Max: 120
26
+
27
+ Metrics/AbcSize:
28
+ Max: 20
29
+
30
+ Metrics/CyclomaticComplexity:
31
+ Max: 9
32
+
33
+ Metrics/ClassLength:
34
+ Max: 200
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify your gem's dependencies in adobe-campaign.gemspec
5
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ # A sample Guardfile
3
+ # More info at https://github.com/guard/guard#readme
4
+
5
+ ## Uncomment and set this to only include directories you want to watch
6
+ # directories %w(app lib config test spec features) \
7
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
8
+
9
+ ## Note: if you are using the `directories` clause above and you are not
10
+ ## watching the project directory ('.'), then you will want to move
11
+ ## the Guardfile to a watched dir and symlink it back, e.g.
12
+ #
13
+ # $ mkdir config
14
+ # $ mv Guardfile config/
15
+ # $ ln -s config/Guardfile .
16
+ #
17
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
18
+
19
+ guard :rubocop, cli: ['--format', 'clang', '--auto-correct'] do
20
+ watch(/.+\.rb$/)
21
+ watch(/.+\.rake$/)
22
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
23
+ end
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Adobe::Campaign
2
+
3
+ Based off the documentation here: https://docs.campaign.adobe.com/doc/standard/en/api/ACS_API.html
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'adobe-campaign'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install adobe-campaign
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/soberstadt/adobe-campaign.
34
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
8
+
9
+ import './lib/tasks/adobe.rake'
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'adobe/campaign/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'adobe-campaign'
9
+ spec.version = Adobe::Campaign::VERSION
10
+ spec.authors = ['Spencer Oberstadt']
11
+ spec.email = ['soberstadt@gmail.com']
12
+
13
+ spec.summary = 'A ruby wrapper for connecting your Rails app with Adobe Campaign.'
14
+ spec.homepage = 'https://github.com/soberstadt/adobe-campaign'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'rails', '>= 3.1'
22
+ spec.add_runtime_dependency 'activesupport', '>= 3.1.0'
23
+ spec.add_runtime_dependency 'rest-client', '>= 1.6.0'
24
+ spec.add_runtime_dependency 'jwt', '~> 1.0'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.11'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'guard-rubocop'
30
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'adobe/campaign'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start
data/bin/setup ADDED
@@ -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,14 @@
1
+ # frozen_string_literal: true
2
+ require 'rest-client'
3
+
4
+ require 'adobe/campaign/version'
5
+ require 'adobe/campaign/configuration'
6
+ require 'adobe/campaign/railtie' if defined? ::Rails::Railtie
7
+ require 'adobe/campaign/base'
8
+ require 'adobe/campaign/profile'
9
+ require 'adobe/campaign/service'
10
+
11
+ module Adobe
12
+ module Campaign
13
+ end
14
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+ module Adobe
3
+ module Campaign
4
+ class Base
5
+ class << self
6
+ def endpoint
7
+ raise 'You can not call requests directly on Adobe::Campaign::Base'
8
+ end
9
+
10
+ def all
11
+ get_request(endpoint)
12
+ end
13
+
14
+ def find(search_text)
15
+ get_request("#{endpoint}/byText?text=#{search_text}")
16
+ end
17
+
18
+ def post(body)
19
+ post_request(endpoint, body)
20
+ end
21
+
22
+ def get_request(url)
23
+ full_url = url_prefix(url)
24
+ resp = RestClient::Request.execute(
25
+ method: :get,
26
+ url: full_url,
27
+ headers: Adobe::Campaign::Base.auth_headers
28
+ )
29
+ JSON.parse(resp.body)
30
+ end
31
+
32
+ def post_request(url, body)
33
+ full_url = url_prefix(url)
34
+ json = body.is_a?(String) ? body : body.to_json
35
+ resp = RestClient.post(full_url, json, auth_headers.merge('Content-Type' => 'application/json'))
36
+ JSON.parse(resp.body)
37
+ end
38
+
39
+ def auth_headers
40
+ {
41
+ 'Authorization' => "Bearer #{access_token}",
42
+ 'X-Api-Key' => Adobe::Campaign.configuration.api_key
43
+ }
44
+ end
45
+
46
+ def access_token
47
+ Adobe::Campaign::Base.load_access_token
48
+ end
49
+
50
+ def load_access_token
51
+ return @access_token if @access_token && @access_token_expires > Time.zone.now
52
+ as_url = "https://#{Adobe::Campaign.configuration.ims_host}/ims/exchange/jwt"
53
+ as_payload = {
54
+ client_id: Adobe::Campaign.configuration.api_key,
55
+ client_secret: Adobe::Campaign.configuration.api_secret,
56
+ jwt_token: Adobe::Campaign.configuration.signed_jwt
57
+ }
58
+ access_token_resp = RestClient.post(as_url, as_payload, {})
59
+ json = JSON.parse(access_token_resp.body)
60
+ @access_token_expires = 1439.minutes.from_now
61
+ @access_token = json.dig('access_token')
62
+ end
63
+
64
+ protected
65
+
66
+ def url_prefix(url)
67
+ url.starts_with?('http') ? url : url_join('https://mc.adobe.io/cru/campaign/', url)
68
+ end
69
+
70
+ def url_join(*args)
71
+ base = args.map { |arg| arg.gsub(%r{^/*(.*?)/*$}, '\1') }.join('/')
72
+ args.last.ends_with?('/') ? "#{base}/" : base
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ module Adobe
3
+ module Campaign
4
+ class << self
5
+ attr_accessor :configuration
6
+ end
7
+
8
+ def self.configure
9
+ self.configuration ||= Configuration.new
10
+ yield(configuration)
11
+ end
12
+
13
+ class Configuration
14
+ # Required. The issuer, your organization ID in the format org_ident@AdobeOrg.
15
+ attr_accessor :org_id
16
+
17
+ # Required. The subject, your API client account ID in the format: id@techacct.adobe.com.
18
+ attr_accessor :tech_acct
19
+
20
+ # Required. Api key retrieved from https://www.adobe.io/console/integrations
21
+ attr_accessor :api_key
22
+ attr_accessor :api_secret
23
+
24
+ attr_accessor :signed_jwt
25
+
26
+ attr_accessor :ims_host
27
+
28
+ def initialize
29
+ @org_id = ''
30
+ @tech_acct = ''
31
+ @api_key = ''
32
+ @api_secret = ''
33
+ @signed_jwt = ''
34
+ @ims_host = 'ims-na1.adobelogin.com'
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ module Adobe
3
+ module Campaign
4
+ class Profile < Adobe::Campaign::Base
5
+ def self.endpoint
6
+ 'profileAndServices/profile'
7
+ end
8
+
9
+ def self.by_email(search_text)
10
+ get_request("#{endpoint}/byEmail?email=#{search_text}")
11
+ end
12
+
13
+ def self.profile_subscriptions(person_pkey)
14
+ get_request("#{endpoint}/#{person_pkey}/subscriptions/")
15
+ end
16
+
17
+ # Example Create Payload
18
+ # {
19
+ # "birthDate": '',
20
+ # "email": 'a.test@cru.org',
21
+ # "emailFormat": 'unknown',
22
+ # "fax": '',
23
+ # "firstName": 'A Test',
24
+ # "gender": 'male',
25
+ # "lastName": 'Profile',
26
+ # "location": {
27
+ # "address1": '123 North St',
28
+ # "address2": '',
29
+ # "address3": '',
30
+ # "address4": '',
31
+ # "city": 'Orlando',
32
+ # "countryCode": 'US',
33
+ # "stateCode": 'FL',
34
+ # "zipCode": '32714'
35
+ # },
36
+ # "middleName": '',
37
+ # "mobilePhone": '',
38
+ # "phone": '',
39
+ # "salutation": 'Mr'
40
+ # }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Adobe
3
+ module Campaign
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load File.join(File.dirname(__FILE__), '../../tasks/adobe.rake')
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ module Adobe
3
+ module Campaign
4
+ class Service < Adobe::Campaign::Base
5
+ def self.endpoint
6
+ 'profileAndServices/service'
7
+ end
8
+
9
+ def self.post_subscription(service_subs_url, person_pkey)
10
+ payload = {
11
+ 'subscriber' => {
12
+ 'PKey' => person_pkey
13
+ }
14
+ }
15
+ post_request(service_subs_url, payload)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ module Adobe
3
+ module Campaign
4
+ VERSION = '0.1.0.1'
5
+ end
6
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ # rubocop:disable Metrics/BlockLength
3
+ require 'jwt'
4
+ require 'adobe/campaign'
5
+
6
+ namespace :adobe do
7
+ desc 'Generate a long-life JWT for exchanging with the adobelogic server'
8
+ task :generate_jwt do
9
+ unless ENV['key']
10
+ puts 'You must include a reference to the private key'
11
+ puts 'example: rake adobe:generate_jwt key=~/certs/adobe/private.key'
12
+ exit 1
13
+ end
14
+
15
+ key_path = File.expand_path(ENV['key'])
16
+ unless File.exist? key_path
17
+ puts 'private key does not exist!'
18
+ exit 1
19
+ end
20
+
21
+ org_id = Adobe::Campaign.configuration.org_id
22
+ tech_acct = Adobe::Campaign.configuration.tech_acct
23
+ api_key = Adobe::Campaign.configuration.api_key
24
+ ims_host = Adobe::Campaign.configuration.ims_host
25
+ payload = {
26
+ 'exp' => 1.year.from_now.to_time.to_i,
27
+ 'iss' => "#{org_id}@AdobeOrg",
28
+ 'sub' => "#{tech_acct}@techacct.adobe.com",
29
+ 'aud' => "https://#{ims_host}/c/#{api_key}",
30
+ "https://#{ims_host}/s/ent_campaign_sdk" => true
31
+ }
32
+ priv_key = OpenSSL::PKey::RSA.new(File.read(key_path))
33
+ signed_jwt = JWT.encode(payload, priv_key, 'RS256')
34
+ puts 'Your new signed JWT:'
35
+ puts signed_jwt
36
+ puts "It will expire: #{10.years.from_now}"
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adobe-campaign
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Spencer Oberstadt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: jwt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.11'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - soberstadt@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - ".ruby-version"
136
+ - ".travis.yml"
137
+ - Gemfile
138
+ - Guardfile
139
+ - README.md
140
+ - Rakefile
141
+ - adobe-campaign.gemspec
142
+ - bin/console
143
+ - bin/setup
144
+ - lib/adobe/campaign.rb
145
+ - lib/adobe/campaign/base.rb
146
+ - lib/adobe/campaign/configuration.rb
147
+ - lib/adobe/campaign/profile.rb
148
+ - lib/adobe/campaign/railtie.rb
149
+ - lib/adobe/campaign/service.rb
150
+ - lib/adobe/campaign/version.rb
151
+ - lib/tasks/adobe.rake
152
+ homepage: https://github.com/soberstadt/adobe-campaign
153
+ licenses: []
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.6.8
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: A ruby wrapper for connecting your Rails app with Adobe Campaign.
175
+ test_files: []