maropost 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2eced5aa76526e6c12db30667da7a6f7961a2525
4
- data.tar.gz: df0738586b465c3df0d3bbc17741e55f1dc513aa
3
+ metadata.gz: 4f1d07946245385970b68fe9cd20e8549f05c1b5
4
+ data.tar.gz: 1091979701bc837560a1bb8bb23db1fb0372ffca
5
5
  SHA512:
6
- metadata.gz: 62cfaf444071f7acc822ab7b6ed3766253911734de0fe35c94b53c44695728c04b15e870b542e8810cb2eff94aaf341879945e93e4ef69dfc9497caa8d407ba3
7
- data.tar.gz: 7018b61ccb441a8a7607e0121d0d939eec348472308c7aca3dac93698601a3b06ad2a8739bf2e63fd7d16393e406df349cd08411600f189d851a9e9ade5ddb8f
6
+ metadata.gz: eb95f1e698305bcd6ac2ea87cabb819b5b9387a1b28c3e7a27b28855cafbdc19ab0fbc50ccd9df0279738b833871eb24407a92b4354191060c6ef5f521b28c22
7
+ data.tar.gz: 77f5bd5ad8fd7f50a4b1d50ddb7c7832dd75cb49abc55c78cf97a74d012e15881db4c566ea0afa0d6a947121611136fa62382a3d85b7e59c4e30ade04cd73dba
data/.gitignore CHANGED
@@ -7,4 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- /.gem
10
+ *.gem
@@ -0,0 +1 @@
1
+ 2.4.0
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in maropost.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ gem 'bundler', '~> 1.15'
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.5'
10
+ gem 'webmock'
11
+ end
data/README.md CHANGED
@@ -22,7 +22,34 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ To find a contact in Maropost:
26
+ ``` ruby
27
+ Maropost::Api.find('email@example.com')
28
+ ```
29
+
30
+ To create or update a contact in Maropost:
31
+ ```ruby
32
+ Maropost::Api.update_subscriptions(
33
+ Maropost::Contact.new(
34
+ { email: email,
35
+ ama_rewards: ama_rewards,
36
+ ama_membership: ama_membership,
37
+ ama_insurance: ama_insurance,
38
+ ama_travel: ama_travel,
39
+ ama_new_member_series: ama_new_member_series,
40
+ ama_fleet_safety: ama_fleet_safety,
41
+ personal_vehicle_reminder: personal_vehicle_reminder,
42
+ business_vehicle_reminder: business_vehicle_reminder,
43
+ associate_vehicle_reminder: associate_vehicle_reminder,
44
+ ama_vr_reminder: ama_vr_reminder,
45
+ ama_vr_reminder_email: ama_vr_reminder_email,
46
+ ama_vr_reminder_sms: ama_vr_reminder_sms,
47
+ ama_vr_reminder_autocall: ama_vr_reminder_autocall,
48
+ cell_phone_number: cell_phone_number.present? ? "1#{cell_phone_number}" : '',
49
+ phone_number: phone_number }.stringify_keys
50
+ )
51
+ )
52
+ ```
26
53
 
27
54
  ## Development
28
55
 
@@ -1,5 +1,7 @@
1
- require "maropost/version"
2
-
3
- module Maropost
4
- # Your code goes here...
5
- end
1
+ require 'json'
2
+ require 'rest_client'
3
+ require 'rest_client/jogger'
4
+ require 'maropost/version'
5
+ require 'maropost/configuration'
6
+ require 'maropost/api'
7
+ require 'maropost/contact'
@@ -0,0 +1,77 @@
1
+ module Maropost
2
+ class Api
3
+ def self.find(email)
4
+ response = request(:get,
5
+ "#{Maropost.configuration.api_url}/contacts/email.json?contact[email]=#{email}")
6
+ Maropost::Contact.new(JSON.parse response.body)
7
+ rescue RestClient::ResourceNotFound
8
+ nil
9
+ end
10
+
11
+ def self.update_subscriptions(contact)
12
+ if existing_contact = find(contact.email)
13
+ contact.id = existing_contact.id
14
+ update(contact)
15
+ else
16
+ create(contact)
17
+ end
18
+ end
19
+
20
+ def self.create(contact)
21
+ response = request(:post,
22
+ "#{Maropost.configuration.api_url}/contacts.json",
23
+ create_or_update_payload(contact))
24
+ Maropost::Contact.new(JSON.parse response.body)
25
+ rescue RestClient::UnprocessableEntity, RestClient::BadRequest => e
26
+ contact.errors << 'Unable to create or update contact'
27
+ contact
28
+ end
29
+
30
+ def self.update(contact)
31
+ response = request(:put,
32
+ "#{Maropost.configuration.api_url}/contacts/#{contact.id}.json",
33
+ create_or_update_payload(contact))
34
+ Maropost::Contact.new(JSON.parse response.body)
35
+ rescue RestClient::UnprocessableEntity, RestClient::BadRequest => e
36
+ contact.errors << 'Unable to update contact'
37
+ contact
38
+ end
39
+
40
+ private
41
+
42
+ def self.request(method, url, payload = {})
43
+ RestClient::Request.logged_request(
44
+ method: method,
45
+ timeout: 10,
46
+ open_timeout: 10,
47
+ url: url,
48
+ payload: {auth_token: Maropost.configuration.auth_token}.merge(payload).to_json,
49
+ headers: { content_type: 'application/json', accept: 'application/json' },
50
+ verify_ssl: OpenSSL::SSL::VERIFY_PEER
51
+ )
52
+ end
53
+
54
+ def self.create_or_update_payload(contact)
55
+ { contact: { email: contact.email,
56
+ custom_field: {
57
+ ama_rewards: contact.ama_rewards,
58
+ ama_membership: contact.ama_membership,
59
+ ama_insurance: contact.ama_insurance,
60
+ ama_travel: contact.ama_travel,
61
+ ama_new_member_series: contact.ama_new_member_series,
62
+ ama_fleet_safety: contact.ama_fleet_safety,
63
+ personal_vehicle_reminder: contact.personal_vehicle_reminder,
64
+ business_vehicle_reminder: contact.business_vehicle_reminder,
65
+ associate_vehicle_reminder: contact.associate_vehicle_reminder,
66
+ ama_vr_reminder: contact.ama_vr_reminder,
67
+ ama_vr_reminder_email: contact.ama_vr_reminder_email,
68
+ ama_vr_reminder_sms: contact.ama_vr_reminder_sms,
69
+ ama_vr_reminder_autocall: contact.ama_vr_reminder_autocall,
70
+ cell_phone_number: contact.cell_phone_number,
71
+ phone: contact.phone_number
72
+ }
73
+ }
74
+ }
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,20 @@
1
+ module Maropost
2
+ attr_accessor :configuration
3
+
4
+ def self.configuration
5
+ @configuration ||= Configuration.new
6
+ end
7
+
8
+ def self.configure
9
+ yield(configuration)
10
+ end
11
+
12
+ class Configuration
13
+ attr_accessor :api_url, :auth_token
14
+
15
+ def initialize
16
+ self.api_url = "http://example.com"
17
+ self.auth_token = "auth_token"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ module Maropost
2
+ class Contact
3
+ attr_accessor :id, :email,
4
+ :ama_rewards, :ama_membership, :ama_insurance, :ama_travel, :ama_new_member_series, :ama_fleet_safety,
5
+ :personal_vehicle_reminder, :business_vehicle_reminder, :associate_vehicle_reminder,
6
+ :ama_vr_reminder, :ama_vr_reminder_email, :ama_vr_reminder_sms, :ama_vr_reminder_autocall,
7
+ :phone_number, :cell_phone_number, :errors
8
+
9
+ def initialize(data)
10
+ self.id = data['id']
11
+ self.email = data['email']
12
+ self.ama_rewards = data['ama_rewards'] || '0'
13
+ self.ama_membership = data['ama_membership'] || '0'
14
+ self.ama_insurance = data['ama_insurance'] || '0'
15
+ self.ama_travel = data['ama_travel'] || '0'
16
+ self.ama_new_member_series = data['ama_new_member_series'] || '0'
17
+ self.ama_fleet_safety = data['ama_fleet_safety'] || '0'
18
+ self.personal_vehicle_reminder = data['personal_vehicle_reminder'] || ''
19
+ self.business_vehicle_reminder = data['business_vehicle_reminder'] || ''
20
+ self.associate_vehicle_reminder = data['associate_vehicle_reminder'] || ''
21
+ self.ama_vr_reminder = data['ama_vr_reminder'] || '0'
22
+ self.ama_vr_reminder_email = data['ama_vr_reminder_email'] || '0'
23
+ self.ama_vr_reminder_sms = data['ama_vr_reminder_sms'] || '0'
24
+ self.ama_vr_reminder_autocall = data['ama_vr_reminder_autocall'] || '0'
25
+ self.phone_number = data['phone'] || ''
26
+ self.cell_phone_number = data['cell_phone_number'] || ''
27
+
28
+ self.errors = []
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Maropost
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -4,21 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'maropost/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "maropost"
7
+ spec.name = 'maropost'
8
8
  spec.version = Maropost::VERSION
9
- spec.authors = ["Michael van den Beuken", "Ruben Estevez", "Jordan Babe", "Mathieu Gilbert", "Ryan Jones", "Darko Dosenovic", "Jonathan Weyermann", "Adam Melnyk", "Kayt Campbell", "Kathleen Robertson", "Jesse Doyle", "Sinead Errity"]
10
- spec.email = ["michael.beuken@gmail.com", "ruben.a.estevez@gmail.com", "jorbabe@gmail.com", "mathieu.gilbert@ama.ab.ca", "ryan.michael.jones@gmail.com", "darko.dosenovic@ama.ab.ca", "jonathan.weyermann@ama.ab.ca", "adam.melnyk@ama.ab.ca", "kayt.campbell@ama.ab.ca", "kathleen.robertson@ama.ab.ca", "jesse.doyle@ama.ab.ca", "sinead.errity@ama.ab.ca"]
9
+ spec.authors = ['Michael van den Beuken', 'Ruben Estevez', 'Jordan Babe', 'Mathieu Gilbert', 'Ryan Jones', 'Darko Dosenovic', 'Jonathan Weyermann', 'Adam Melnyk', 'Kayt Campbell', 'Kathleen Robertson', 'Jesse Doyle', 'Sinead Errity', 'Serene Yew', 'Martin Echtner']
10
+ spec.email = ['michael.beuken@gmail.com', 'ruben.a.estevez@gmail.com', 'jorbabe@gmail.com', 'mathieu.gilbert@ama.ab.ca', 'ryan.michael.jones@gmail.com', 'darko.dosenovic@ama.ab.ca', 'jonathan.weyermann@ama.ab.ca', 'adam.melnyk@ama.ab.ca', 'kayt.campbell@ama.ab.ca', 'kathleen.robertson@ama.ab.ca', 'jdoyle@ualberta.ca', 'sinead.errity@ama.ab.ca', 'serene.yew@ama.ab.ca', 'martin.echtner@ama.ab.ca']
11
11
  spec.summary = %q{Interact with the Maropost API}
12
12
  spec.description = %q{Interact with the Maropost API}
13
- spec.homepage = "https://github.com/amaabca/maropost"
14
- spec.license = "MIT"
13
+ spec.homepage = 'https://github.com/amaabca/maropost'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = "exe"
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+
19
+ spec.bindir = 'exe'
18
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
21
+ spec.require_paths = %w(lib spec)
22
+
23
+ spec.add_dependency 'rest-client'
24
+ spec.add_dependency 'rest-client-jogger'
20
25
 
21
- spec.add_development_dependency "bundler", "~> 1.11"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.required_ruby_version = '>= 2.2'
24
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maropost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van den Beuken
@@ -16,53 +16,41 @@ authors:
16
16
  - Kathleen Robertson
17
17
  - Jesse Doyle
18
18
  - Sinead Errity
19
+ - Serene Yew
20
+ - Martin Echtner
19
21
  autorequire:
20
22
  bindir: exe
21
23
  cert_chain: []
22
- date: 2016-07-08 00:00:00.000000000 Z
24
+ date: 2017-09-26 00:00:00.000000000 Z
23
25
  dependencies:
24
26
  - !ruby/object:Gem::Dependency
25
- name: bundler
27
+ name: rest-client
26
28
  requirement: !ruby/object:Gem::Requirement
27
29
  requirements:
28
- - - "~>"
30
+ - - ">="
29
31
  - !ruby/object:Gem::Version
30
- version: '1.11'
31
- type: :development
32
+ version: '0'
33
+ type: :runtime
32
34
  prerelease: false
33
35
  version_requirements: !ruby/object:Gem::Requirement
34
36
  requirements:
35
- - - "~>"
37
+ - - ">="
36
38
  - !ruby/object:Gem::Version
37
- version: '1.11'
39
+ version: '0'
38
40
  - !ruby/object:Gem::Dependency
39
- name: rake
41
+ name: rest-client-jogger
40
42
  requirement: !ruby/object:Gem::Requirement
41
43
  requirements:
42
- - - "~>"
44
+ - - ">="
43
45
  - !ruby/object:Gem::Version
44
- version: '10.0'
45
- type: :development
46
+ version: '0'
47
+ type: :runtime
46
48
  prerelease: false
47
49
  version_requirements: !ruby/object:Gem::Requirement
48
50
  requirements:
49
- - - "~>"
51
+ - - ">="
50
52
  - !ruby/object:Gem::Version
51
- version: '10.0'
52
- - !ruby/object:Gem::Dependency
53
- name: rspec
54
- requirement: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - "~>"
57
- - !ruby/object:Gem::Version
58
- version: '3.0'
59
- type: :development
60
- prerelease: false
61
- version_requirements: !ruby/object:Gem::Requirement
62
- requirements:
63
- - - "~>"
64
- - !ruby/object:Gem::Version
65
- version: '3.0'
53
+ version: '0'
66
54
  description: Interact with the Maropost API
67
55
  email:
68
56
  - michael.beuken@gmail.com
@@ -75,14 +63,17 @@ email:
75
63
  - adam.melnyk@ama.ab.ca
76
64
  - kayt.campbell@ama.ab.ca
77
65
  - kathleen.robertson@ama.ab.ca
78
- - jesse.doyle@ama.ab.ca
66
+ - jdoyle@ualberta.ca
79
67
  - sinead.errity@ama.ab.ca
68
+ - serene.yew@ama.ab.ca
69
+ - martin.echtner@ama.ab.ca
80
70
  executables: []
81
71
  extensions: []
82
72
  extra_rdoc_files: []
83
73
  files:
84
74
  - ".gitignore"
85
75
  - ".rspec"
76
+ - ".ruby-version"
86
77
  - ".travis.yml"
87
78
  - Gemfile
88
79
  - LICENSE.txt
@@ -91,6 +82,9 @@ files:
91
82
  - bin/console
92
83
  - bin/setup
93
84
  - lib/maropost.rb
85
+ - lib/maropost/api.rb
86
+ - lib/maropost/configuration.rb
87
+ - lib/maropost/contact.rb
94
88
  - lib/maropost/version.rb
95
89
  - maropost.gemspec
96
90
  homepage: https://github.com/amaabca/maropost
@@ -101,11 +95,12 @@ post_install_message:
101
95
  rdoc_options: []
102
96
  require_paths:
103
97
  - lib
98
+ - spec
104
99
  required_ruby_version: !ruby/object:Gem::Requirement
105
100
  requirements:
106
101
  - - ">="
107
102
  - !ruby/object:Gem::Version
108
- version: '0'
103
+ version: '2.2'
109
104
  required_rubygems_version: !ruby/object:Gem::Requirement
110
105
  requirements:
111
106
  - - ">="
@@ -113,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
108
  version: '0'
114
109
  requirements: []
115
110
  rubyforge_project:
116
- rubygems_version: 2.2.0
111
+ rubygems_version: 2.6.8
117
112
  signing_key:
118
113
  specification_version: 4
119
114
  summary: Interact with the Maropost API