sendgrid-object 1.0.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e19a523dcdbc5c6efe82406745c1b994ee713ca154f51da85e324c3d22201db1
4
- data.tar.gz: 14ac6f2d33bc077f99e389e81555d80655cbcedb5240528982ad317f9c0be819
3
+ metadata.gz: 6c49bb55dea48672ad89c27f53d16e1e5c4bc9c3cb2dee6aba924b5f847061e9
4
+ data.tar.gz: 1a22c127f140b2e915ebc2cd0aee804d2d3188c5c16c42475a34c2356bebaa51
5
5
  SHA512:
6
- metadata.gz: a0e2c5ed76f84a0b5433d4863a9266af68275536bf311b069543a34de9734e225421ca2b87185b79a17defac6b07a9cab8b9091898767f6eeb9d8346c49ecc70
7
- data.tar.gz: a1f740f02b68a1b6444e132e06c54b4a1f4b7ab72f7bab372ec67f494debf953a0973ac571e04d5ddd61209f4d17e1aef345e8330948ea0fc08c6e7f8e43cb8b
6
+ metadata.gz: bf4638be880b1cd939a2fd27030eebaaabadf6aeaa0f73074042f987014c93883145f9fccf385fadebcd2780e948c2239c62cbd76a8742b1b4f90fe2bf67764e
7
+ data.tar.gz: f6b280e2da12b426347df8875b95cc0f6722153cbff638ad17c3a43b37b73dec50abc0d66000df70711d77c2859127342f42a56a2a30756198c45d6e03da4ca2
data/README.md CHANGED
@@ -6,16 +6,6 @@ This gem provide classes for an easy use of the [sendrig-ruby](https://github.co
6
6
 
7
7
  Ruby version >= 2.4 (except version [2.6.0](https://github.com/sendgrid/sendgrid-ruby/blob/main/TROUBLESHOOTING.md#ruby-versions))
8
8
 
9
- ## Setup Environment Variables
10
-
11
- Update the development environment with your SENDGRID_API_KEY, for example:
12
-
13
- ```
14
- echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
15
- echo "sendgrid.env" >> .gitignore
16
- source ./sendgrid.env
17
- ```
18
-
19
9
  ## Installation
20
10
 
21
11
  Add this line to your application's Gemfile:
@@ -32,11 +22,23 @@ Or install it yourself as:
32
22
 
33
23
  $ gem install sendgrid-object
34
24
 
25
+ ## Configuration
26
+
27
+ You need to configure the api key with the following code. You can add it in `/config/initializers/sendgrid.rb` for example.
28
+
29
+ ```ruby
30
+ require 'sendgrid-object'
31
+
32
+ Sendgrid.config do
33
+ api_key 'YOUR_API_KEY_HERE'
34
+ end
35
+ ```
36
+
35
37
  ## Quick start
36
38
 
37
39
  ### Find a recipient
38
40
 
39
- ```
41
+ ```ruby
40
42
  recipient = Sendgrid::Recipient.new()
41
43
  recipient.find_by("email", "john@doe.com")
42
44
  => {"id"=>"ID", "email"=>"john@doe.com", "created_at"=>TIMESTAMP, "updated_at"=>TIMESTAMP, "last_emailed"=>TIMESTAMP, "last_clicked"=>TIMESTAMP, "last_opened"=>TIMESTAMP, "first_name"=>"John", "last_name"=>"Doe"}
@@ -50,7 +52,7 @@ end
50
52
 
51
53
  ### Create a recipient
52
54
 
53
- ```
55
+ ```ruby
54
56
  recipient = Sendgrid::Recipient.new()
55
57
  recipient.create({ email: "jane@doe.com" })
56
58
  => "ID"
@@ -64,7 +66,7 @@ end
64
66
 
65
67
  ### Add a recipient to an existing list
66
68
 
67
- ```
69
+ ```ruby
68
70
  recipient = Sendgrid::Recipient.new()
69
71
  recipient.find_by("email", "john@doe.com")
70
72
  list = Sendgrid::List.new()
@@ -77,7 +79,7 @@ end
77
79
 
78
80
  OR
79
81
 
80
- ```
82
+ ```ruby
81
83
  recipient = Sendgrid::Recipient.new()
82
84
  recipient.find_by("email", "john@doe.com")
83
85
  list = Sendgrid::List.new()
@@ -90,7 +92,7 @@ puts "User successfully added." unless list.errors
90
92
 
91
93
  ### Destroy a recipient
92
94
 
93
- ```
95
+ ```ruby
94
96
  recipient = Sendgrid::Recipient.new()
95
97
  recipient.find_by("email", "john@doe.com")
96
98
  => {"id"=>"ID", "email"=>"john@doe.com", "created_at"=>TIMESTAMP, "updated_at"=>TIMESTAMP, "last_emailed"=>TIMESTAMP, "last_clicked"=>TIMESTAMP, "last_opened"=>TIMESTAMP, "first_name"=>"John", "last_name"=>"Doe"}
@@ -102,7 +104,7 @@ end
102
104
 
103
105
  OR
104
106
 
105
- ```
107
+ ```ruby
106
108
  recipient = Sendgrid::Recipient.new()
107
109
  recipient.destroy("ID")
108
110
  puts "User successfully destroyed." unless recipient.errors
@@ -110,12 +112,8 @@ puts "User successfully destroyed." unless recipient.errors
110
112
 
111
113
  ## Contributing
112
114
 
113
- Bug reports and pull requests are welcome on GitHub at https://github.com/immateriel/sendgrid-object. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/sendgrid-object/blob/master/CODE_OF_CONDUCT.md).
115
+ Bug reports and pull requests are welcome on GitHub at https://github.com/immateriel/sendgrid-object. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/immateriel/sendgrid-object/blob/master/CODE_OF_CONDUCT.md).
114
116
 
115
117
  ## License
116
118
 
117
119
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
118
-
119
- ## Code of Conduct
120
-
121
- Everyone interacting in the Sendgrid::Object project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sendgrid-object/blob/master/CODE_OF_CONDUCT.md).
data/lib/sendgrid/list.rb CHANGED
@@ -3,7 +3,7 @@ class Sendgrid::List
3
3
  attr_accessor :name
4
4
 
5
5
  def initialize(data = {})
6
- @api = ::SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
6
+ @api = ::SendGrid::API.new(api_key: Sendgrid.api_key)
7
7
  @errors = nil
8
8
  reset_properties
9
9
  @name ||= data["name"]
@@ -3,7 +3,7 @@ class Sendgrid::Recipient
3
3
  attr_accessor :email, :first_name, :last_name
4
4
 
5
5
  def initialize
6
- @api = ::SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
6
+ @api = ::SendGrid::API.new(api_key: Sendgrid.api_key)
7
7
  @errors = nil
8
8
  reset_properties
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module Sendgrid
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/sendgrid.rb CHANGED
@@ -1,2 +1,22 @@
1
1
  module Sendgrid
2
+ extend self
3
+
4
+ def parameter(*names)
5
+ names.each do |name|
6
+ attr_accessor name
7
+
8
+ define_method name do |*values|
9
+ value = values.first
10
+ value ? self.send("#{name}=", value) : instance_variable_get("@#{name}")
11
+ end
12
+ end
13
+ end
14
+
15
+ def config(&block)
16
+ instance_eval &block
17
+ end
2
18
  end
19
+
20
+ Sendgrid.config do
21
+ parameter :api_key
22
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ require "bundler/setup"
2
2
  require "sendgrid-object"
3
3
  require 'webmock/rspec'
4
4
 
5
- ENV['SENDGRID_API_KEY']="ThisIsAFakeKey"
5
+ Sendgrid.api_key = "ThisIsAFakeKey"
6
6
 
7
7
  RSpec.configure do |config|
8
8
 
@@ -12,14 +12,14 @@ RSpec.configure do |config|
12
12
  headers = {
13
13
  'Accept'=>'application/json',
14
14
  'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
15
- 'Authorization'=>"Bearer #{ENV['SENDGRID_API_KEY']}",
15
+ 'Authorization'=>"Bearer #{Sendgrid.api_key}",
16
16
  'Content-Type'=>'application/json',
17
17
  'User-Agent'=>'sendgrid/6.6.1;ruby'
18
18
  }
19
19
  headers_without_content_type = {
20
20
  'Accept'=>'application/json',
21
21
  'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
22
- 'Authorization'=>"Bearer #{ENV['SENDGRID_API_KEY']}",
22
+ 'Authorization'=>"Bearer #{Sendgrid.api_key}",
23
23
  'User-Agent'=>'sendgrid/6.6.1;ruby'
24
24
  }
25
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid-object
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elodie Ailleaume
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-04 00:00:00.000000000 Z
11
+ date: 2022-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sendgrid-ruby