zapier_ruby 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/zapier_ruby/base.rb +36 -0
- data/lib/zapier_ruby/version.rb +1 -1
- data/lib/zapier_ruby/zapper.rb +2 -34
- data/lib/zapier_ruby/zapper_hook.rb +21 -0
- data/lib/zapier_ruby.rb +3 -1
- data/spec/spec_helper.rb +14 -0
- data/spec/zapier_ruby_spec.rb +67 -0
- data/zapier_ruby.gemspec +3 -0
- metadata +61 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9077d7bdc94f0cd5e7cf80325a5f915beca8c73
|
4
|
+
data.tar.gz: 5dd2f60022922e9ab87da9f65dbcb96d01994097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a865b86cc4d45f6fbf2541001bdd58fb999a7430afb94f27608937fbc80c8b10d20630c6ab2a61c3fd438998f3463855119b2ddd09885f3e872ca1a1b3113782
|
7
|
+
data.tar.gz: ae5184e84b117221186237abd0b1b618efa6ed0ddc39ff3afb9bdb770f983963130f051e0d812f219cf88cd0f428e7006920fc3afaebb41877301e481389e069
|
data/README.md
CHANGED
@@ -41,6 +41,16 @@ if zapper.zap({hello: "world"})
|
|
41
41
|
else
|
42
42
|
puts "it remains unzapped"
|
43
43
|
end
|
44
|
+
|
45
|
+
standard_url = 'https://hooks.zapier.com/hooks/standard/123456/xxxxxx/'
|
46
|
+
zapper = ZapierRuby::ZapperHook.new(url: standard_url)
|
47
|
+
|
48
|
+
if zapper.zap({hello: "world"})
|
49
|
+
puts "zapped it"
|
50
|
+
else
|
51
|
+
puts "it remains unzapped"
|
52
|
+
end
|
53
|
+
|
44
54
|
```
|
45
55
|
|
46
56
|
You can find the value to fill in for "webhook id" in the location highlighted below ('xxxxxx' in the green box) when configuring your Zap:
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ZapierRuby
|
2
|
+
class Base
|
3
|
+
attr_accessor :logger
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def post_zap(params)
|
8
|
+
rest_client.post(params, zap_headers)
|
9
|
+
rescue RestClient::ExceptionWithResponse => err
|
10
|
+
raise ZapierServerError, err
|
11
|
+
end
|
12
|
+
|
13
|
+
def rest_client
|
14
|
+
@rest_client ||= RestClient::Resource.new(zap_url, ssl_version: 'TLSv1')
|
15
|
+
end
|
16
|
+
|
17
|
+
def zap_web_hook_id
|
18
|
+
@zap_web_hook ||= config.web_hooks[zap_name]
|
19
|
+
end
|
20
|
+
|
21
|
+
def zap_headers
|
22
|
+
{
|
23
|
+
"Accept" => " application/json",
|
24
|
+
"Content-Type" => "application/json"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def zap_url
|
29
|
+
"#{config.base_uri}#{zap_web_hook_id}/"
|
30
|
+
end
|
31
|
+
|
32
|
+
def config
|
33
|
+
ZapierRuby.config
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/zapier_ruby/version.rb
CHANGED
data/lib/zapier_ruby/zapper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module ZapierRuby
|
2
|
-
class Zapper
|
3
|
-
attr_accessor :zap_name
|
2
|
+
class Zapper < Base
|
3
|
+
attr_accessor :zap_name
|
4
4
|
|
5
5
|
def initialize(zap_name, web_hook_id=nil)
|
6
6
|
self.zap_name = zap_name
|
@@ -16,37 +16,5 @@ module ZapierRuby
|
|
16
16
|
logger.debug "Zapping #{zap_name} with params: #{params.to_s}"
|
17
17
|
post_zap(params)
|
18
18
|
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def post_zap(params)
|
23
|
-
rest_client.post(params, zap_headers)
|
24
|
-
rescue RestClient::ExceptionWithResponse => err
|
25
|
-
raise ZapierServerError, err
|
26
|
-
end
|
27
|
-
|
28
|
-
def rest_client
|
29
|
-
@rest_client ||= RestClient::Resource.new(zap_url, ssl_version: 'TLSv1')
|
30
|
-
end
|
31
|
-
|
32
|
-
def zap_web_hook_id
|
33
|
-
@zap_web_hook ||= config.web_hooks[zap_name]
|
34
|
-
end
|
35
|
-
private :zap_web_hook_id
|
36
|
-
|
37
|
-
def zap_headers
|
38
|
-
{
|
39
|
-
"Accept" => " application/json",
|
40
|
-
"Content-Type" => "application/json"
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
def zap_url
|
45
|
-
"#{config.base_uri}#{zap_web_hook_id}/"
|
46
|
-
end
|
47
|
-
|
48
|
-
def config
|
49
|
-
ZapierRuby.config
|
50
|
-
end
|
51
19
|
end
|
52
20
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ZapierRuby
|
2
|
+
class ZapperHook < Base
|
3
|
+
attr_accessor :opt_hash
|
4
|
+
|
5
|
+
def initialize(opt_hash={})
|
6
|
+
self.opt_hash = opt_hash
|
7
|
+
self.logger = LoggerDecorator.new(config.enable_logging)
|
8
|
+
end
|
9
|
+
|
10
|
+
def zap(params={})
|
11
|
+
logger.debug "Zapping #{zap_url} with params: #{params.inspect}"
|
12
|
+
post_zap(params)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def zap_url
|
18
|
+
"#{opt_hash[:url]}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/zapier_ruby.rb
CHANGED
@@ -7,7 +7,9 @@ require 'zapier_ruby/version'
|
|
7
7
|
require 'zapier_ruby/exceptions'
|
8
8
|
require 'zapier_ruby/logger_decorator'
|
9
9
|
require 'zapier_ruby/config'
|
10
|
+
require 'zapier_ruby/base'
|
10
11
|
require 'zapier_ruby/zapper'
|
12
|
+
require 'zapier_ruby/zapper_hook'
|
11
13
|
|
12
14
|
module ZapierRuby
|
13
15
|
class << self
|
@@ -21,6 +23,6 @@ module ZapierRuby
|
|
21
23
|
|
22
24
|
def self.configure_with(path_to_yaml_file)
|
23
25
|
self.config ||= ZapierRuby::Config.new
|
24
|
-
config.configure_with(path_to_yaml_file)
|
26
|
+
config.configure_with(path_to_yaml_file)
|
25
27
|
end
|
26
28
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'ZapierRuby' do
|
4
|
+
let(:body) { { message: 'Hey zapier' } }
|
5
|
+
let(:result) do
|
6
|
+
{
|
7
|
+
"status": "success",
|
8
|
+
"attempt": "5c304977-e06d-4580-86a3-xxxxxxxxxx",
|
9
|
+
"id": "096e7041-5510-4f5b-9597-xxxxxxxxxx",
|
10
|
+
"request_id": "5c304977-e06d-4580-86a3-xxxxxxxxxx"
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'Zapper' do
|
15
|
+
let(:zapper) { ZapierRuby::Zapper }
|
16
|
+
let(:catch_url) { 'https://zapier.com/hooks/catch/webhook_id/' }
|
17
|
+
let(:instance) { zapper.new(:example_zap) }
|
18
|
+
|
19
|
+
describe '#zap_url' do
|
20
|
+
it { expect(instance.send(:zap_url)).to eq catch_url }
|
21
|
+
|
22
|
+
it 'web_hook_id has val' do
|
23
|
+
url = zapper.new(:nil, 'webhook_id/uuiq').send(:zap_url)
|
24
|
+
|
25
|
+
expect(url).to eq 'https://zapier.com/hooks/catch/webhook_id/uuiq/'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it '.base_uri' do
|
30
|
+
expect(ZapierRuby.config.base_uri).to eq "https://zapier.com/hooks/catch/"
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#zap' do
|
34
|
+
it 'ZapierMisConfiguration'do
|
35
|
+
expect {
|
36
|
+
zapper.new(:typo_zap_name).zap
|
37
|
+
}.to raise_error(ZapierRuby::ZapierMisConfiguration)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'http require' do
|
41
|
+
stub_request(:post, catch_url).with(body: body).to_return(body: result.to_json)
|
42
|
+
response = instance.zap(body)
|
43
|
+
|
44
|
+
expect(response.code).to eq 200
|
45
|
+
expect(JSON.parse(response)['status']).to eq 'success'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'ZapperHook' do
|
51
|
+
let(:zapper_hook) { ZapierRuby::ZapperHook }
|
52
|
+
let(:hookurl) { 'https://hooks.zapier.com/hooks/standard/1234/uuiq/' }
|
53
|
+
let(:instance) { zapper_hook.new(url: hookurl) }
|
54
|
+
|
55
|
+
it '#zap_url' do
|
56
|
+
expect(instance.send('zap_url')).to eq hookurl
|
57
|
+
end
|
58
|
+
|
59
|
+
it '#zap' do
|
60
|
+
stub_request(:post, hookurl).with(body: body).to_return(body: result.to_json)
|
61
|
+
response = instance.zap(body)
|
62
|
+
|
63
|
+
expect(response.code).to eq 200
|
64
|
+
expect(JSON.parse(response)['status']).to eq 'success'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/zapier_ruby.gemspec
CHANGED
@@ -22,4 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "webmock"
|
27
|
+
spec.add_development_dependency "pry"
|
25
28
|
end
|
metadata
CHANGED
@@ -1,57 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zapier_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Peterson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.7'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
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'
|
55
97
|
description: Simple gem to integrate Zapier webhooks with a Ruby project.
|
56
98
|
email:
|
57
99
|
- pete2786@umn.edu
|
@@ -60,19 +102,23 @@ executables:
|
|
60
102
|
extensions: []
|
61
103
|
extra_rdoc_files: []
|
62
104
|
files:
|
63
|
-
- .gitignore
|
64
|
-
- .zapier_ruby.yml.example
|
105
|
+
- ".gitignore"
|
106
|
+
- ".zapier_ruby.yml.example"
|
65
107
|
- Gemfile
|
66
108
|
- LICENSE.txt
|
67
109
|
- README.md
|
68
110
|
- Rakefile
|
69
111
|
- bin/zap
|
70
112
|
- lib/zapier_ruby.rb
|
113
|
+
- lib/zapier_ruby/base.rb
|
71
114
|
- lib/zapier_ruby/config.rb
|
72
115
|
- lib/zapier_ruby/exceptions.rb
|
73
116
|
- lib/zapier_ruby/logger_decorator.rb
|
74
117
|
- lib/zapier_ruby/version.rb
|
75
118
|
- lib/zapier_ruby/zapper.rb
|
119
|
+
- lib/zapier_ruby/zapper_hook.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
- spec/zapier_ruby_spec.rb
|
76
122
|
- zapier_ruby.gemspec
|
77
123
|
homepage: http://pete2786.github.io
|
78
124
|
licenses:
|
@@ -84,12 +130,12 @@ require_paths:
|
|
84
130
|
- lib
|
85
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
132
|
requirements:
|
87
|
-
- -
|
133
|
+
- - ">="
|
88
134
|
- !ruby/object:Gem::Version
|
89
135
|
version: '0'
|
90
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
137
|
requirements:
|
92
|
-
- -
|
138
|
+
- - ">="
|
93
139
|
- !ruby/object:Gem::Version
|
94
140
|
version: '0'
|
95
141
|
requirements: []
|
@@ -98,4 +144,6 @@ rubygems_version: 2.6.14
|
|
98
144
|
signing_key:
|
99
145
|
specification_version: 4
|
100
146
|
summary: Simple gem to integrate Zapier webhooks with a Ruby project.
|
101
|
-
test_files:
|
147
|
+
test_files:
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/zapier_ruby_spec.rb
|