sendgrid-threads 0.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.
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "SendgridThreads" do
4
+ it "has a version" do
5
+ expect(SendgridThreads::VERSION).not_to be_nil
6
+ end
7
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe SendgridThreads::Api do
4
+
5
+ let(:connection_mock) { instance_double("Api") }
6
+ let(:connection_params) do
7
+ {key: 'foobar', secret: 'abc123'}
8
+ end
9
+
10
+ before(:all) do
11
+ Timecop.freeze(Time.utc(2015, 11, 01, 12))
12
+ end
13
+
14
+ after(:all) do
15
+ Timecop.return
16
+ end
17
+
18
+ it "initializes a valid connection" do
19
+ expect(SendgridThreads::Client).to receive(:new).with(connection_params).and_return(connection_mock)
20
+ SendgridThreads::Api.new(connection_params)
21
+ end
22
+
23
+ describe "v1" do
24
+ let(:user_id) { "12345678" }
25
+ let(:traits) do
26
+ {email: "test@example.com", name: "Sendgrid Tester"}
27
+ end
28
+ let(:properties) do
29
+ {plan: 1, subscription: 2}
30
+ end
31
+
32
+ before do
33
+ allow(SendgridThreads::Client).to receive(:new).with(connection_params).and_return(connection_mock)
34
+ end
35
+
36
+ subject { SendgridThreads::Api.new(connection_params) }
37
+
38
+ it "#identify" do
39
+ expect(connection_mock).to receive(:post).with(
40
+ "identify", {userId: user_id, traits: traits, timestamp: "2015-11-01T12:00:00.000Z"}
41
+ )
42
+ subject.identify(user_id, traits)
43
+ end
44
+
45
+ it "#track" do
46
+ expect(connection_mock).to receive(:post).with(
47
+ "track", {userId: user_id, event: "event", timestamp: "2015-11-01T12:00:00.000Z", properties: properties }
48
+ )
49
+ subject.track(user_id, "event", properties)
50
+ end
51
+
52
+ it "#page_view" do
53
+ expect(connection_mock).to receive(:post).with(
54
+ "page", {userId: user_id, name: "Page Name", timestamp: "2015-11-01T12:00:00.000Z", properties: properties }
55
+ )
56
+ subject.page_view(user_id, "Page Name", properties)
57
+ end
58
+
59
+ it "#remove" do
60
+ expect(connection_mock).to receive(:post).with(
61
+ "remove", {userId: user_id, timestamp: "2015-11-01T12:00:00.000Z" }
62
+ )
63
+ subject.remove(user_id)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe SendgridThreads::Client do
4
+
5
+ it 'should accept a key and a secret' do
6
+ expect(SendgridThreads::Client.new(key: 'test', secret: 'test')).to be_an_instance_of(SendgridThreads::Client)
7
+ end
8
+
9
+ it 'should build the default url' do
10
+ expect(SendgridThreads::Client.new.url).to eq('https://input.threads.io')
11
+ end
12
+
13
+ it 'should build a custom url' do
14
+ expect(SendgridThreads::Client.new(url: 'http://foo.example.com').url).to eq('http://foo.example.com')
15
+ end
16
+
17
+ it 'accepts a block' do
18
+ expect { |b| SendgridThreads::Client.new(&b) }.to yield_control
19
+ end
20
+
21
+ describe "raise exceptions" do
22
+ before do
23
+ stub_request(:post, "https://foobar:abc123@input.threads.io/v1/mock").
24
+ to_return(body: {message: 'error', errors: ['Bad username / password']}.to_json, status: 400, headers: {'X-TEST' => 'yes'})
25
+ end
26
+
27
+ it 'should raise a SendgridThreads::Exception by default' do
28
+ client = SendgridThreads::Client.new(key: 'foobar', secret: 'abc123')
29
+ expect {client.post("mock")}.to raise_error(SendgridThreads::Exception)
30
+ end
31
+
32
+ it 'should not raise a SendgridThreads::Exception if raise_exceptions is disabled' do
33
+ client = SendgridThreads::Client.new(key: 'foobar', secret: 'abc123', raise_exceptions: false)
34
+ expect {client.post("mock")}.not_to raise_error
35
+ end
36
+ end
37
+
38
+ describe "#post" do
39
+ it 'should make a request to sendgrid' do
40
+ stub_request(:post, "https://foobar:abc123@input.threads.io/v1/mock").
41
+ with(:body => {"attrs"=>2, "params"=>1}).
42
+ to_return(body: {message: 'success'}.to_json, status: 200, headers: {'X-TEST' => 'yes'})
43
+
44
+ client = SendgridThreads::Client.new(key: 'foobar', secret: 'abc123')
45
+ res = client.post("mock", {params: 1, attrs: 2})
46
+ expect(res.status).to eq(200)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,36 @@
1
+ require 'simplecov'
2
+ require 'sendgrid-threads'
3
+ require 'byebug'
4
+ require 'webmock/rspec'
5
+ require 'timecop'
6
+ require 'active_support/all'
7
+
8
+ module SimpleCov::Configuration
9
+ def clean_filters
10
+ @filters = []
11
+ end
12
+ end
13
+
14
+ SimpleCov.configure do
15
+ clean_filters
16
+ load_adapter 'test_frameworks'
17
+ end
18
+
19
+ ENV["COVERAGE"] && SimpleCov.start do
20
+ WebMock.disable_net_connect!(allow: "codeclimate.com")
21
+ CodeClimate::TestReporter.start
22
+ end
23
+
24
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
25
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
26
+
27
+ require 'rspec'
28
+ require "codeclimate-test-reporter"
29
+
30
+ # Requires supporting files with custom matchers and macros, etc,
31
+ # in ./support/ and its subdirectories.
32
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
33
+
34
+ RSpec.configure do |config|
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sendgrid-threads
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Paluy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
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
+ - !ruby/object:Gem::Dependency
126
+ name: timecop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: codeclimate-test-reporter
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: This Gem allows you to send Threads events using native Ruby https://docs.threads.io/
154
+ email: dpaluy@gmail.com
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files:
158
+ - LICENSE.txt
159
+ - README.md
160
+ files:
161
+ - ".codeclimate.yml"
162
+ - ".document"
163
+ - ".rspec"
164
+ - ".rubocop.yml"
165
+ - ".travis.yml"
166
+ - Gemfile
167
+ - Gemfile.lock
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - VERSION
172
+ - lib/sendgrid-threads.rb
173
+ - lib/sendgrid_threads/api.rb
174
+ - lib/sendgrid_threads/client.rb
175
+ - lib/sendgrid_threads/config.rb
176
+ - lib/sendgrid_threads/engine.rb
177
+ - lib/sendgrid_threads/exceptions.rb
178
+ - sendgrid-threads.gemspec
179
+ - spec/sendgrid-threads_spec.rb
180
+ - spec/sendgrid_threads/api_spec.rb
181
+ - spec/sendgrid_threads/client_spec.rb
182
+ - spec/spec_helper.rb
183
+ homepage: http://github.com/dpaluy/sendgrid-threads
184
+ licenses:
185
+ - MIT
186
+ metadata: {}
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ requirements: []
202
+ rubyforge_project:
203
+ rubygems_version: 2.4.5.1
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: Ruby Gem for the SendGrid Threads API https://threads.io/
207
+ test_files: []