engaging_networks 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +4 -0
  7. data/Gemfile +15 -0
  8. data/Gemfile.lock +140 -0
  9. data/Guardfile +24 -0
  10. data/LICENSE.txt +20 -0
  11. data/README.md +116 -0
  12. data/Rakefile +53 -0
  13. data/VERSION +1 -0
  14. data/engaging_networks.gemspec +117 -0
  15. data/lib/engaging_networks/action.rb +75 -0
  16. data/lib/engaging_networks/action_create_action.rb +51 -0
  17. data/lib/engaging_networks/action_model.rb +23 -0
  18. data/lib/engaging_networks/api.rb +93 -0
  19. data/lib/engaging_networks/base.rb +25 -0
  20. data/lib/engaging_networks/campaign.rb +48 -0
  21. data/lib/engaging_networks/client.rb +19 -0
  22. data/lib/engaging_networks/duplicate_campaign_action.rb +35 -0
  23. data/lib/engaging_networks/request/multitoken.rb +74 -0
  24. data/lib/engaging_networks/response/collection.rb +23 -0
  25. data/lib/engaging_networks/response/object.rb +31 -0
  26. data/lib/engaging_networks/response/raise_error.rb +30 -0
  27. data/lib/engaging_networks/response/wrapper.rb +152 -0
  28. data/lib/engaging_networks/scrape/client.rb +64 -0
  29. data/lib/engaging_networks/supporter.rb +22 -0
  30. data/lib/engaging_networks/version.rb +10 -0
  31. data/lib/engaging_networks.rb +33 -0
  32. data/spec/engaging_networks/action_create_action_spec.rb +64 -0
  33. data/spec/engaging_networks/action_spec.rb +54 -0
  34. data/spec/engaging_networks/campaign_spec.rb +109 -0
  35. data/spec/engaging_networks/collection_spec.rb +15 -0
  36. data/spec/engaging_networks/duplicate_campaign_action_spec.rb +15 -0
  37. data/spec/engaging_networks/supporter_spec.rb +72 -0
  38. data/spec/fixtures/EaCampaignInfo/failure.xml +2 -0
  39. data/spec/fixtures/EaCampaignInfo/success.xml +10 -0
  40. data/spec/fixtures/EaCampaignInfo/success_array.xml +18 -0
  41. data/spec/fixtures/SupporterData/aoxml_success.xml +22 -0
  42. data/spec/fixtures/SupporterData/aoxml_success_array.xml +40 -0
  43. data/spec/fixtures/SupporterData/failure.xml +7 -0
  44. data/spec/fixtures/SupporterData/success.xml +21 -0
  45. data/spec/fixtures/action/api_success.json +1 -0
  46. data/spec/fixtures/action/error.json +1 -0
  47. data/spec/fixtures/action/success.json +1 -0
  48. data/spec/fixtures/api-supporter-template.csv +2 -0
  49. data/spec/fixtures/import.service/error.txt +1 -0
  50. data/spec/fixtures/import.service/success.txt +1 -0
  51. data/spec/spec_helper.rb +51 -0
  52. metadata +236 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad132e63642e804398bce5424f1cf63c814ae67f
4
+ data.tar.gz: 62e650e7c5007ee3ed6b7f9749bfbf506600be19
5
+ SHA512:
6
+ metadata.gz: 8c08078367980d7f084b788d80e2b7257e265d9cf3a9a43721cf86a0b2105118396c3ca731764e613efc9c06a28ce733740026938e5d5b8c4bf1c0c7030032a6
7
+ data.tar.gz: bab9d5592f51d724353e315f852ed030a09b6da152531fcce807af08d4b062d5c5cc3aaea8cfebb46001a58e50e480b965621eff293d8f47d5e247cf61aeba31
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ ruby_engaging_networks
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.4
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - "2.2.4"
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'vertebrae'
4
+ gem 'json'
5
+ gem 'activesupport', ">= 3.2"
6
+ gem 'activemodel', ">= 3.2"
7
+ gem 'mechanize'
8
+
9
+ group :development do
10
+ gem "rspec", "~> 3.4"
11
+ gem 'webmock'
12
+ gem 'pry-byebug'
13
+ gem "bundler"
14
+ gem "jeweler", "~> 2.0.0"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,140 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (4.2.6)
5
+ activesupport (= 4.2.6)
6
+ builder (~> 3.1)
7
+ activesupport (4.2.6)
8
+ i18n (~> 0.7)
9
+ json (~> 1.7, >= 1.7.7)
10
+ minitest (~> 5.1)
11
+ thread_safe (~> 0.3, >= 0.3.4)
12
+ tzinfo (~> 1.1)
13
+ addressable (2.4.0)
14
+ builder (3.2.2)
15
+ byebug (9.0.5)
16
+ coderay (1.1.1)
17
+ crack (0.4.3)
18
+ safe_yaml (~> 1.0.0)
19
+ descendants_tracker (0.0.4)
20
+ thread_safe (~> 0.3, >= 0.3.1)
21
+ diff-lcs (1.2.5)
22
+ domain_name (0.5.20160310)
23
+ unf (>= 0.0.5, < 1.0.0)
24
+ faraday (0.9.2)
25
+ multipart-post (>= 1.2, < 3)
26
+ faraday_middleware (0.10.0)
27
+ faraday (>= 0.7.4, < 0.10)
28
+ git (1.3.0)
29
+ github_api (0.14.0)
30
+ addressable (~> 2.4.0)
31
+ descendants_tracker (~> 0.0.4)
32
+ faraday (~> 0.8, < 0.10)
33
+ hashie (>= 3.4)
34
+ oauth2
35
+ hashdiff (0.3.0)
36
+ hashie (3.4.4)
37
+ highline (1.7.8)
38
+ http-cookie (1.0.2)
39
+ domain_name (~> 0.5)
40
+ i18n (0.7.0)
41
+ jeweler (2.0.1)
42
+ builder
43
+ bundler (>= 1.0)
44
+ git (>= 1.2.5)
45
+ github_api
46
+ highline (>= 1.6.15)
47
+ nokogiri (>= 1.5.10)
48
+ rake
49
+ rdoc
50
+ json (1.8.3)
51
+ jwt (1.5.1)
52
+ mechanize (2.7.4)
53
+ domain_name (~> 0.5, >= 0.5.1)
54
+ http-cookie (~> 1.0)
55
+ mime-types (>= 1.17.2, < 3)
56
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
57
+ net-http-persistent (~> 2.5, >= 2.5.2)
58
+ nokogiri (~> 1.6)
59
+ ntlm-http (~> 0.1, >= 0.1.1)
60
+ webrobots (>= 0.0.9, < 0.2)
61
+ method_source (0.8.2)
62
+ mime-types (2.99.2)
63
+ mini_portile2 (2.1.0)
64
+ minitest (5.9.0)
65
+ multi_json (1.12.1)
66
+ multi_xml (0.5.5)
67
+ multipart-post (2.0.0)
68
+ net-http-digest_auth (1.4)
69
+ net-http-persistent (2.9.4)
70
+ nokogiri (1.6.8)
71
+ mini_portile2 (~> 2.1.0)
72
+ pkg-config (~> 1.1.7)
73
+ ntlm-http (0.1.1)
74
+ oauth2 (1.1.0)
75
+ faraday (>= 0.8, < 0.10)
76
+ jwt (~> 1.0, < 1.5.2)
77
+ multi_json (~> 1.3)
78
+ multi_xml (~> 0.5)
79
+ rack (>= 1.2, < 3)
80
+ pkg-config (1.1.7)
81
+ pry (0.10.3)
82
+ coderay (~> 1.1.0)
83
+ method_source (~> 0.8.1)
84
+ slop (~> 3.4)
85
+ pry-byebug (3.4.0)
86
+ byebug (~> 9.0)
87
+ pry (~> 0.10)
88
+ rack (1.6.4)
89
+ rake (11.1.2)
90
+ rdoc (4.2.2)
91
+ json (~> 1.4)
92
+ rspec (3.4.0)
93
+ rspec-core (~> 3.4.0)
94
+ rspec-expectations (~> 3.4.0)
95
+ rspec-mocks (~> 3.4.0)
96
+ rspec-core (3.4.4)
97
+ rspec-support (~> 3.4.0)
98
+ rspec-expectations (3.4.0)
99
+ diff-lcs (>= 1.2.0, < 2.0)
100
+ rspec-support (~> 3.4.0)
101
+ rspec-mocks (3.4.1)
102
+ diff-lcs (>= 1.2.0, < 2.0)
103
+ rspec-support (~> 3.4.0)
104
+ rspec-support (3.4.1)
105
+ safe_yaml (1.0.4)
106
+ slop (3.6.0)
107
+ thread_safe (0.3.5)
108
+ tzinfo (1.2.2)
109
+ thread_safe (~> 0.1)
110
+ unf (0.1.4)
111
+ unf_ext
112
+ unf_ext (0.0.7.2)
113
+ vertebrae (0.2.11)
114
+ activesupport
115
+ faraday
116
+ faraday_middleware
117
+ hashie
118
+ webmock (2.1.0)
119
+ addressable (>= 2.3.6)
120
+ crack (>= 0.3.2)
121
+ hashdiff
122
+ webrobots (0.1.2)
123
+
124
+ PLATFORMS
125
+ ruby
126
+
127
+ DEPENDENCIES
128
+ activemodel (>= 3.2)
129
+ activesupport (>= 3.2)
130
+ bundler
131
+ jeweler (~> 2.0.0)
132
+ json
133
+ mechanize
134
+ pry-byebug
135
+ rspec (~> 3.4)
136
+ vertebrae
137
+ webmock
138
+
139
+ BUNDLED WITH
140
+ 1.12.5
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 ChangeSprout, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # engaging_networks
2
+
3
+ A ruby binding for the Engaging Networks API
4
+
5
+ [![Build Status](https://travis-ci.org/controlshift/ruby_engaging_networks.svg)](https://travis-ci.org/controlshift/ruby_engaging_networks)
6
+
7
+ This API client wraps undocumented features of the Engaging Networks platform in ruby bindings that can be used to approximate
8
+ API-ish behavior. It does not use the [ENS API](https://speca.io/engagingnetworks/engaging-network-services?key=726cda99f0551ef286486bb847f5fb5d) and is intended
9
+ as a stopgap until EN builds out a full API.
10
+
11
+ ## Usage
12
+
13
+ create a client object
14
+
15
+ ```ruby
16
+ require 'engaging_networks'
17
+ en = EngagingNetworks.new({public_token: 'PUBLIC_TOKEN', private_token: 'PRIVATE_TOKEN'})
18
+ ```
19
+
20
+ If you need to use and endpoint like campaign create that screen scrapes, you'll also need to set an EN username and password for a
21
+ user that has permission.
22
+
23
+ ```ruby
24
+ require 'engaging_networks'
25
+ en = EngagingNetworks.new({public_token: 'PUBLIC_TOKEN', private_token: 'PRIVATE_TOKEN', username: 'foo', password: 'bar'})
26
+ ```
27
+
28
+ Get a campaign by id
29
+
30
+ ```ruby
31
+ campaign = en.campaign.get 456
32
+ campaign.obj
33
+ => #<EngagingNetworks::Response::Object:0x00000101685f68
34
+ @fields=
35
+ {"clientId"=>"123",
36
+ "campaignId"=>"456",
37
+ "campaignStatus"=>"Live",
38
+ "campaignName"=>"Test Campaign",
39
+ "campaignExportName"=>"Test Campaign",
40
+ "description"=>nil}>
41
+ ```
42
+
43
+ Duplicate a campaign
44
+
45
+
46
+ ```ruby
47
+ action = en.campaign.duplicate reference_name: 'foo',
48
+ format_name: 'API New Supporter Template',
49
+ csv_string: 'Email,First Name,Last Name,City,Country Code,Country Name,Postal Code,Mobile Phone,Language,Originating Action',
50
+ csv_file_name: 'upload.csv',
51
+ segment_id: 'Test Segment Id',
52
+ segment_name: 'Test Segment',
53
+ template_campaign_id: 26967,
54
+ new_campaign_reference_name: 'New Test Campaign4'
55
+ action.job_id
56
+ => '1234'
57
+ ```
58
+
59
+ Create a campaign via screen scrape
60
+ ```ruby
61
+ id = en.campaign.create(name: 'ControlShift test 2', description: 'description')
62
+ # returns the campaign id
63
+ ```
64
+
65
+ Search for a campaign by name (exact match only)
66
+
67
+ ```ruby
68
+ action = en.campaign.search "Foo"
69
+ action.campaignName
70
+ => 'Foo'
71
+ ```
72
+
73
+ check if supporter exists
74
+
75
+ ```ruby
76
+ en.supporter.exists? 'email@example.com'
77
+ => false
78
+ ```
79
+ create an action
80
+
81
+ ```ruby
82
+ action = en.action.create(client_id: 123, campaign_id: 123, form_id: 123, first_name: 'George',
83
+ last_name: 'Washington', city: 'Detroit', country: country_code, country_name: 'United States',
84
+ email: 'george@washington.com', address_line_1: 'address1', address_line_2: 'address2',
85
+ post_code: '02052', state: 'MI', mobile_phone: '518-207-6768', originating_action: 'xxx',
86
+ opt_in: true,
87
+ additional_fields: {'Some Custom Field Name': 'field value'})
88
+
89
+ action.valid?
90
+ => true
91
+ action.result
92
+ => true
93
+ ```
94
+
95
+ The truth of the opt_in field determines whether or not the member is opted in.
96
+
97
+ And then check again, and now supporter exists!
98
+
99
+ ```ruby
100
+ en.supporter.exists? 'email@example.com'
101
+ => true
102
+ ```
103
+
104
+ Supporters by date
105
+
106
+ ```
107
+ en.supporter.export Date.new(2014,6,5)
108
+ => [{...}]
109
+
110
+ ```
111
+
112
+ ## Copyright
113
+
114
+ Copyright (c) 2015 ChangeSprout Inc. See LICENSE.txt for
115
+ further details.
116
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ require './lib/engaging_networks/version.rb'
16
+
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
19
+ gem.name = "engaging_networks"
20
+ gem.homepage = "http://github.com/jlev/engaging_networks"
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{A wrapper for the Engaging Networks API}
23
+ gem.description = %Q{Gem for interacting with the Engaging Networks API}
24
+ gem.email = "josh@levinger.net"
25
+ gem.authors = ["Josh Levinger", "Nathan Woodhull"]
26
+
27
+ # dependencies defined in Gemfile
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rspec/core'
32
+ require 'rspec/core/rake_task'
33
+ RSpec::Core::RakeTask.new(:spec) do |spec|
34
+ spec.pattern = FileList['spec/**/*_spec.rb']
35
+ end
36
+
37
+ desc "Code coverage detail"
38
+ task :simplecov do
39
+ ENV['COVERAGE'] = "true"
40
+ Rake::Task['spec'].execute
41
+ end
42
+
43
+ task :default => :spec
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "engaging_networks #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
@@ -0,0 +1,117 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: engaging_networks 0.2.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "engaging_networks"
9
+ s.version = "0.2.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Josh Levinger", "Nathan Woodhull"]
14
+ s.date = "2016-06-10"
15
+ s.description = "Gem for interacting with the Engaging Networks API"
16
+ s.email = "josh@levinger.net"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ ".ruby-gemset",
25
+ ".ruby-version",
26
+ ".travis.yml",
27
+ "Gemfile",
28
+ "Gemfile.lock",
29
+ "Guardfile",
30
+ "LICENSE.txt",
31
+ "README.md",
32
+ "Rakefile",
33
+ "VERSION",
34
+ "engaging_networks.gemspec",
35
+ "lib/engaging_networks.rb",
36
+ "lib/engaging_networks/action.rb",
37
+ "lib/engaging_networks/action_create_action.rb",
38
+ "lib/engaging_networks/action_model.rb",
39
+ "lib/engaging_networks/api.rb",
40
+ "lib/engaging_networks/base.rb",
41
+ "lib/engaging_networks/campaign.rb",
42
+ "lib/engaging_networks/client.rb",
43
+ "lib/engaging_networks/duplicate_campaign_action.rb",
44
+ "lib/engaging_networks/request/multitoken.rb",
45
+ "lib/engaging_networks/response/collection.rb",
46
+ "lib/engaging_networks/response/object.rb",
47
+ "lib/engaging_networks/response/raise_error.rb",
48
+ "lib/engaging_networks/response/wrapper.rb",
49
+ "lib/engaging_networks/scrape/client.rb",
50
+ "lib/engaging_networks/supporter.rb",
51
+ "lib/engaging_networks/version.rb",
52
+ "spec/engaging_networks/action_create_action_spec.rb",
53
+ "spec/engaging_networks/action_spec.rb",
54
+ "spec/engaging_networks/campaign_spec.rb",
55
+ "spec/engaging_networks/collection_spec.rb",
56
+ "spec/engaging_networks/duplicate_campaign_action_spec.rb",
57
+ "spec/engaging_networks/supporter_spec.rb",
58
+ "spec/fixtures/EaCampaignInfo/failure.xml",
59
+ "spec/fixtures/EaCampaignInfo/success.xml",
60
+ "spec/fixtures/EaCampaignInfo/success_array.xml",
61
+ "spec/fixtures/SupporterData/aoxml_success.xml",
62
+ "spec/fixtures/SupporterData/aoxml_success_array.xml",
63
+ "spec/fixtures/SupporterData/failure.xml",
64
+ "spec/fixtures/SupporterData/success.xml",
65
+ "spec/fixtures/action/api_success.json",
66
+ "spec/fixtures/action/error.json",
67
+ "spec/fixtures/action/success.json",
68
+ "spec/fixtures/api-supporter-template.csv",
69
+ "spec/fixtures/import.service/error.txt",
70
+ "spec/fixtures/import.service/success.txt",
71
+ "spec/spec_helper.rb"
72
+ ]
73
+ s.homepage = "http://github.com/jlev/engaging_networks"
74
+ s.licenses = ["MIT"]
75
+ s.rubygems_version = "2.4.8"
76
+ s.summary = "A wrapper for the Engaging Networks API"
77
+
78
+ if s.respond_to? :specification_version then
79
+ s.specification_version = 4
80
+
81
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
82
+ s.add_runtime_dependency(%q<vertebrae>, [">= 0"])
83
+ s.add_runtime_dependency(%q<json>, [">= 0"])
84
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.2"])
85
+ s.add_runtime_dependency(%q<activemodel>, [">= 3.2"])
86
+ s.add_runtime_dependency(%q<mechanize>, [">= 0"])
87
+ s.add_development_dependency(%q<rspec>, ["~> 3.4"])
88
+ s.add_development_dependency(%q<webmock>, [">= 0"])
89
+ s.add_development_dependency(%q<pry-byebug>, [">= 0"])
90
+ s.add_development_dependency(%q<bundler>, [">= 0"])
91
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.0"])
92
+ else
93
+ s.add_dependency(%q<vertebrae>, [">= 0"])
94
+ s.add_dependency(%q<json>, [">= 0"])
95
+ s.add_dependency(%q<activesupport>, [">= 3.2"])
96
+ s.add_dependency(%q<activemodel>, [">= 3.2"])
97
+ s.add_dependency(%q<mechanize>, [">= 0"])
98
+ s.add_dependency(%q<rspec>, ["~> 3.4"])
99
+ s.add_dependency(%q<webmock>, [">= 0"])
100
+ s.add_dependency(%q<pry-byebug>, [">= 0"])
101
+ s.add_dependency(%q<bundler>, [">= 0"])
102
+ s.add_dependency(%q<jeweler>, ["~> 2.0.0"])
103
+ end
104
+ else
105
+ s.add_dependency(%q<vertebrae>, [">= 0"])
106
+ s.add_dependency(%q<json>, [">= 0"])
107
+ s.add_dependency(%q<activesupport>, [">= 3.2"])
108
+ s.add_dependency(%q<activemodel>, [">= 3.2"])
109
+ s.add_dependency(%q<mechanize>, [">= 0"])
110
+ s.add_dependency(%q<rspec>, ["~> 3.4"])
111
+ s.add_dependency(%q<webmock>, [">= 0"])
112
+ s.add_dependency(%q<pry-byebug>, [">= 0"])
113
+ s.add_dependency(%q<bundler>, [">= 0"])
114
+ s.add_dependency(%q<jeweler>, ["~> 2.0.0"])
115
+ end
116
+ end
117
+
@@ -0,0 +1,75 @@
1
+ require 'json'
2
+ require 'nokogiri'
3
+
4
+ module EngagingNetworks
5
+ class InvalidActionError < StandardError ; end
6
+
7
+ class Action < Base
8
+ # individual get unavailable
9
+ # need to export and search actions
10
+ def export(startDate)
11
+ client.get_request(data_path, {startDate: startDate,
12
+ token_type: EngagingNetworks::Request::MultiTokenAuthentication::PRIVATE})
13
+ end
14
+
15
+ def create(action_hash, additional_options = {})
16
+ # accept either hashes or objects as input
17
+ action = if action_hash.is_a?(Hash)
18
+ ActionCreateAction.new(action_hash)
19
+ else
20
+ action_hash
21
+ end
22
+
23
+ if action.valid?
24
+ # parameters required for fake ajax form submission
25
+ ajax_form_params = {
26
+ 'ea.AJAX.submit' => true,
27
+ 'ea.submitted.page' => 1,
28
+ 'ea_requested_action' => 'ea_submit_user_form',
29
+ 'ea_javascript_enabled' => true,
30
+ 'ea.campaign.mode' => 'DEMO',
31
+ 'ea.retain.account.session.error' => true,
32
+ 'ea.clear.campaign.session.id' => true,
33
+ 'v' => 'c%3AshowBuild'
34
+ }
35
+
36
+ # clientId, campaignId, formId
37
+ client_params = {'ea.client.id' => action.client_id,
38
+ 'ea.campaign.id' => action.campaign_id,
39
+ 'ea.form.id' => action.form_id}
40
+
41
+ # merge params hashes
42
+ post_params = {}
43
+ post_params = post_params.merge(ajax_form_params)
44
+ post_params = post_params.merge(client_params)
45
+ post_params = post_params.merge(action.to_params)
46
+ post_params = post_params.merge(additional_options)
47
+
48
+ # call post request, with get param ?format=json
49
+ rsp = client.post_request_with_get_params(action_path, {'format'=>'json'}, post_params)
50
+ action.raw_response = rsp
51
+ body = rsp.body
52
+ json_body = JSON.parse(body)
53
+
54
+ # parse json for first form field, apisuccess div
55
+ if json_body['messages'].empty? || body =~ /apisuccess/
56
+ if body =~ /apisuccess/
57
+ success_div = json_body['pages'][0]['form']['fields'][0]['value']
58
+
59
+ # TODO, this seems really fragile...
60
+ action.result = Nokogiri::HTML(success_div).css('#apisuccess').text == "success"
61
+ else
62
+ action.result = true
63
+ end
64
+ else
65
+ raise EngagingNetworks::InvalidActionError.new("Engaging Networks responded with: #{ body }")
66
+ end
67
+
68
+ action
69
+ else
70
+ action
71
+ end
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,51 @@
1
+ module EngagingNetworks
2
+ class ActionCreateAction < ActionModel
3
+ attr_accessor :client_id, :campaign_id, :form_id, :title, :first_name, :last_name, :city, :country, :country_name, :email, :address_line_1,
4
+ :address_line_2, :post_code, :state, :mobile_phone, :originating_action, :additional_fields, :result, :raw_response, :opt_in
5
+
6
+ validates :client_id, presence: true, numericality: true
7
+ validates :campaign_id, presence: true, numericality: true
8
+ validates :form_id, presence: true, numericality: true
9
+
10
+ validates :country, inclusion: { in: %w(AX AF AL DZ AS AD AO AI AQ AG AR AM AW AU AT AZ BS BH BD BB BY BE BZ BJ BM
11
+ BT BO BA BW BV BR IO BN BG BF BI KH CM CA CV KY CF TD CL CN CX CC CO KM CD CG CK CR CI HR CU CY CZ DK DJ
12
+ DM DO EC EG SV GQ ER EE ET FK FO FJ FI FR GF PF TF GA GM GE DE GH GI GR GL GD GP GU GT GN GW GY HT HM HN
13
+ HK HU IS IN ID IR IQ IE IL IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV
14
+ ML MT MH MQ MR MU YT MX FM MD MC MN MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG NU NF MP NO OM PK PW PS PA
15
+ PG PY PE PH PN PL PT PR QA RE RO RU RW SH KN LC PM VC WS SM ST SA SN CS SC SL SG SK SI SB SO ZA GS ES LK
16
+ SD SR SJ SZ SE CH SY TW TJ TZ TH TL TG TK TO TT TN TR TM TC TV UG UA AE GB US UM UY UZ VU VA VE VN VG VI
17
+ WF EH YE ZM ZW) } # ISO2 country codes
18
+
19
+ validates :first_name, :last_name, :email, presence: true
20
+
21
+ def to_params
22
+ hsh = {
23
+ 'Title' => title,
24
+ 'Email address' => email,
25
+ 'First name' => first_name,
26
+ 'Last name' => last_name,
27
+ 'City' => city,
28
+ 'Country' => country,
29
+ 'Country Name' => country_name,
30
+ 'Address Line 1' => address_line_1,
31
+ 'Address Line 2' => address_line_2,
32
+ 'Post Code' => post_code,
33
+ 'State' => state,
34
+ 'Mobile Phone' => mobile_phone,
35
+ 'Originating Action' => originating_action,
36
+ 'Opt in' => opt_in_value
37
+ }
38
+ if additional_fields
39
+ hsh.merge(additional_fields)
40
+ else
41
+ hsh
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def opt_in_value
48
+ opt_in ? 'Y' : 'N'
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ module EngagingNetworks
2
+ class ActionModel
3
+ include ::ActiveModel::Validations
4
+ extend ::ActiveModel::Naming
5
+ include ::ActiveModel::Conversion
6
+
7
+ def initialize(attrs = {})
8
+ attrs.each do |key,value|
9
+ if self.respond_to?("#{key}=")
10
+ self.send("#{key}=", value)
11
+ end
12
+ end
13
+ end
14
+
15
+ def persisted?
16
+ false
17
+ end
18
+
19
+ def self.reflect_on_association(association)
20
+ nil
21
+ end
22
+ end
23
+ end