office_boy 0.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 +7 -0
- data/lib/office_boy.rb +51 -0
- data/lib/office_boy/errors/not_defined_email_template.rb +5 -0
- data/lib/office_boy/errors/not_definied_api_key.rb +5 -0
- data/lib/office_boy/errors/not_definied_subscription_list.rb +5 -0
- data/lib/office_boy/errors/subscriber_not_found.rb +5 -0
- data/lib/office_boy/mail.rb +31 -0
- data/lib/office_boy/request.rb +17 -0
- data/lib/office_boy/subscriber.rb +56 -0
- data/lib/office_boy/version.rb +12 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 19fc9b40583fd4d9e6b3a8b7732c48687f13b35ffa3f4b7c17088fc69ec8d976
|
4
|
+
data.tar.gz: 010f8106f4926bca760fdc085c3b5a2509e02a8bb2476954b68b9c070614b7df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6576a7859b3c3abca78b1f0c3f77efcb71719cdceda63a4777d79d620d2e1223fe03897460ef1f6ba7e66243cd18b8671a67cd374ceca218e4e7cf3e17f759e5
|
7
|
+
data.tar.gz: e6bdd9619ca8e67162c77257e6860fc1418106595eb2644d20107df2f31b9cad981f6f2302a8a4900743108f630985fb01fbf7fb3ca7b9d8794ad8f34381b336
|
data/lib/office_boy.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
require 'office_boy/errors/not_definied_subscription_list'
|
6
|
+
require 'office_boy/errors/not_definied_api_key'
|
7
|
+
require 'office_boy/errors/subscriber_not_found'
|
8
|
+
require 'office_boy/errors/not_defined_email_template'
|
9
|
+
|
10
|
+
require 'office_boy/subscriber'
|
11
|
+
require 'office_boy/mail'
|
12
|
+
require 'office_boy/request'
|
13
|
+
|
14
|
+
module OfficeBoy
|
15
|
+
# Shortcuts
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def deliver(template:, attributes:)
|
19
|
+
Mail.deliver(template: template, attributes: attributes)
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_subscriber(list:, attributes:)
|
23
|
+
Subscriber.add(list: list, attributes: attributes)
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove_subscriber(list:, email:)
|
27
|
+
Subscriber.remove(list: list, email: email)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Configuration
|
32
|
+
|
33
|
+
class << self
|
34
|
+
attr_accessor :configuration
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.configure
|
38
|
+
self.configuration ||= Configuration.new
|
39
|
+
yield(configuration)
|
40
|
+
end
|
41
|
+
|
42
|
+
class Configuration
|
43
|
+
attr_accessor :sendgrid_api_key, :lists, :templates
|
44
|
+
|
45
|
+
def initialize
|
46
|
+
@sendgrid_api_key = nil
|
47
|
+
@lists = {}
|
48
|
+
@templates = {}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module OfficeBoy
|
2
|
+
class Mail
|
3
|
+
def self.deliver(template:, attributes:)
|
4
|
+
raise Errors::NotDefiniedEmailTemplate unless OfficeBoy.configuration.templates.key?(template)
|
5
|
+
|
6
|
+
response = OfficeBoy::Request.call(
|
7
|
+
method_name: :post,
|
8
|
+
path: 'mail/send',
|
9
|
+
payload: {
|
10
|
+
from: {
|
11
|
+
email: attributes[:from_email],
|
12
|
+
name: attributes[:from_name]
|
13
|
+
},
|
14
|
+
template_id: OfficeBoy.configuration.templates[template],
|
15
|
+
personalizations: [
|
16
|
+
{
|
17
|
+
to: [{
|
18
|
+
email: attributes[:to_email],
|
19
|
+
name: attributes[:to_name]
|
20
|
+
}],
|
21
|
+
subject: attributes[:subject]
|
22
|
+
}
|
23
|
+
],
|
24
|
+
headers: attributes[:substitutions]
|
25
|
+
}
|
26
|
+
)
|
27
|
+
|
28
|
+
response.code == 202
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module OfficeBoy
|
2
|
+
class Request
|
3
|
+
def self.call(method_name:, path:, payload: '')
|
4
|
+
raise Errors::NotDefiniedApiKey unless OfficeBoy.configuration.sendgrid_api_key
|
5
|
+
|
6
|
+
RestClient::Request.execute(
|
7
|
+
method: method_name,
|
8
|
+
url: "https://api.sendgrid.com/v3/#{path}",
|
9
|
+
payload: JSON.generate(payload),
|
10
|
+
headers: {
|
11
|
+
'Authorization' => "Bearer #{OfficeBoy.configuration.sendgrid_api_key}",
|
12
|
+
'Content-Type' => 'application/json'
|
13
|
+
}
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module OfficeBoy
|
2
|
+
class Subscriber
|
3
|
+
class << self
|
4
|
+
def add(list:, attributes:)
|
5
|
+
raise Errors::NotDefiniedSubscriptionList unless OfficeBoy.configuration.lists.key?(list)
|
6
|
+
|
7
|
+
list_id = OfficeBoy.configuration.lists[list]
|
8
|
+
|
9
|
+
params = {
|
10
|
+
'list_ids' => [list_id],
|
11
|
+
'contacts' => [attributes]
|
12
|
+
}
|
13
|
+
|
14
|
+
response = OfficeBoy::Request.call(
|
15
|
+
method_name: :put,
|
16
|
+
path: 'marketing/contacts',
|
17
|
+
payload: params
|
18
|
+
)
|
19
|
+
|
20
|
+
response.code == 202
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove(list:, email:)
|
24
|
+
raise Errors::NotDefiniedSubscriptionList unless OfficeBoy.configuration.lists.key?(list)
|
25
|
+
|
26
|
+
list_id = OfficeBoy.configuration.lists[list]
|
27
|
+
|
28
|
+
subscriber = find(list: list_id, email: email)
|
29
|
+
|
30
|
+
raise Errors::SubscriberNotFound unless subscriber
|
31
|
+
|
32
|
+
response = OfficeBoy::Request.call(
|
33
|
+
method_name: :delete,
|
34
|
+
path: "marketing/contacts?ids=#{subscriber['id']}"
|
35
|
+
)
|
36
|
+
|
37
|
+
response.code == 202
|
38
|
+
end
|
39
|
+
|
40
|
+
def find(list:, email:)
|
41
|
+
query = "primary_email LIKE '#{email}%' AND CONTAINS(list_ids, '#{list}')"
|
42
|
+
|
43
|
+
response = OfficeBoy::Request.call(
|
44
|
+
method_name: :post,
|
45
|
+
path: 'marketing/contacts/search',
|
46
|
+
payload: { query: query }
|
47
|
+
)
|
48
|
+
|
49
|
+
parsed_response = JSON.parse(response.body)
|
50
|
+
return unless parsed_response['result'].size == 1
|
51
|
+
|
52
|
+
parsed_response['result'].first
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: office_boy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paweł Dąbrowski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.7'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.7.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.7'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.7.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rest-client
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sendgrid-ruby
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
description: Wrapper for the Sendgrid API addressed to the technical bloggers
|
62
|
+
email: dziamber@gmail.com
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- lib/office_boy.rb
|
68
|
+
- lib/office_boy/errors/not_defined_email_template.rb
|
69
|
+
- lib/office_boy/errors/not_definied_api_key.rb
|
70
|
+
- lib/office_boy/errors/not_definied_subscription_list.rb
|
71
|
+
- lib/office_boy/errors/subscriber_not_found.rb
|
72
|
+
- lib/office_boy/mail.rb
|
73
|
+
- lib/office_boy/request.rb
|
74
|
+
- lib/office_boy/subscriber.rb
|
75
|
+
- lib/office_boy/version.rb
|
76
|
+
homepage: http://github.com/rubyhero/office_boy
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 2.5.0
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.7.7
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Wrapper for the Sendgrid API addressed to the technical bloggers
|
100
|
+
test_files: []
|