zapier_ruby 1.0.0 → 1.0.1

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: b9077d7bdc94f0cd5e7cf80325a5f915beca8c73
4
- data.tar.gz: 5dd2f60022922e9ab87da9f65dbcb96d01994097
3
+ metadata.gz: ab71df7244490a7bc808fd94be2d51afbfef6c02
4
+ data.tar.gz: 69eadf046f9d11a12800e0f53ffd6a9bcd8e9568
5
5
  SHA512:
6
- metadata.gz: a865b86cc4d45f6fbf2541001bdd58fb999a7430afb94f27608937fbc80c8b10d20630c6ab2a61c3fd438998f3463855119b2ddd09885f3e872ca1a1b3113782
7
- data.tar.gz: ae5184e84b117221186237abd0b1b618efa6ed0ddc39ff3afb9bdb770f983963130f051e0d812f219cf88cd0f428e7006920fc3afaebb41877301e481389e069
6
+ metadata.gz: 648c46940aed13ce97170a67dc577ad18de7565845542014a33d677f0c5d5c317d89783e1e0bac0e5717b7e93062b1c672a67fa6a340656e75fdbfbb70f4dfbf
7
+ data.tar.gz: 6f53cc1282d72f9678890ef53f277892760866a265690a02c11081d429f643a7a8787bad091254819a8b91d08fe0439220069160622ba6d0aae3a79fe00b97a0
@@ -1,3 +1,9 @@
1
1
  web_hooks:
2
2
  :test_zap: "xxxxxx"
3
3
  enable_logging: false
4
+
5
+ # for new zaps, grab you account id from your webhook uri
6
+ account_id: 1234
7
+
8
+ # for older zaps, use this base uri
9
+ base_uri: https://zapier.com/hooks/catch/
data/README.md CHANGED
@@ -30,8 +30,13 @@ require 'rubygems'
30
30
  require 'zapier_ruby'
31
31
 
32
32
  ZapierRuby.configure do |c|
33
- c.web_hooks = {example_zap: "webhook_id"}
33
+ c.web_hooks = { example_zap: "webhook_id" }
34
34
  c.enable_logging = false
35
+ # For new web hooks, you must provide this param
36
+ c.account_id = "1234" # Get this from the first part of your webhook URI
37
+
38
+ # For older webhooks, you should override the base uri to the old uri
39
+ c.base_uri = "https://hooks.zapier.com/hooks/catch/"
35
40
  end
36
41
 
37
42
  zapper = ZapierRuby::Zapper.new(:example_zap)
@@ -42,8 +47,7 @@ else
42
47
  puts "it remains unzapped"
43
48
  end
44
49
 
45
- standard_url = 'https://hooks.zapier.com/hooks/standard/123456/xxxxxx/'
46
- zapper = ZapierRuby::ZapperHook.new(url: standard_url)
50
+ zapper = ZapierRuby::Zapper.new(url: standard_url)
47
51
 
48
52
  if zapper.zap({hello: "world"})
49
53
  puts "zapped it"
@@ -53,7 +57,7 @@ end
53
57
 
54
58
  ```
55
59
 
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:
60
+ You can find the value to fill in for "webhook id" and "account id" in the location highlighted below ('xxxxxx' in the green box) when configuring your Zap:
57
61
 
58
62
  ![](https://github.com/pete2786/pete2786.github.io/blob/master/images/finding_webhook.png)
59
63
 
@@ -74,8 +78,15 @@ To use this gem from the command line, you can leverage the `bin/zap` Ruby execu
74
78
 
75
79
  ```yaml
76
80
  web_hooks:
77
- :example_zap: "xxxxxx"
81
+ :test_zap: "xxxxxx"
78
82
  enable_logging: false
83
+
84
+ # for new zaps, grab you account id from your webhook uri
85
+ account_id: 1234
86
+
87
+ # for older zaps, use this base uri
88
+ base_uri: https://zapier.com/hooks/catch/
89
+
79
90
  ```
80
91
 
81
92
  You must pass `zap [zap_name] [Message]` to the executable. For example:
data/bin/zap CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby
2
2
  require_relative '../lib/zapier_ruby'
3
3
 
4
4
  FILE_NAME = ".zapier_ruby.yml"
@@ -12,4 +12,4 @@ end
12
12
  zap_name = ARGV[0].nil? ? raise("Must supply a zap name") : ARGV[0].to_sym
13
13
  message = ARGV[1] || "No message supplied."
14
14
 
15
- ZapierRuby::Zapper.new(zap_name).zap({Message: message})
15
+ puts ZapierRuby::Zapper.new(zap_name).zap({Message: message})
data/lib/zapier_ruby.rb CHANGED
@@ -1,4 +1,6 @@
1
- require 'rest_client'
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
2
4
  require 'yaml'
3
5
  require 'delegate'
4
6
  require 'logger'
@@ -9,7 +11,6 @@ require 'zapier_ruby/logger_decorator'
9
11
  require 'zapier_ruby/config'
10
12
  require 'zapier_ruby/base'
11
13
  require 'zapier_ruby/zapper'
12
- require 'zapier_ruby/zapper_hook'
13
14
 
14
15
  module ZapierRuby
15
16
  class << self
@@ -5,15 +5,17 @@ module ZapierRuby
5
5
  private
6
6
 
7
7
  def post_zap(params)
8
- rest_client.post(params, zap_headers)
9
- rescue RestClient::ExceptionWithResponse => err
8
+ uri = URI.parse(zap_url)
9
+ logger.debug(uri)
10
+ http = Net::HTTP.new(uri.host, uri.port)
11
+ http.use_ssl = true
12
+ request = Net::HTTP::Post.new(uri.request_uri, zap_headers)
13
+ request.body = params.to_json
14
+ http.request(request)
15
+ rescue StandardError => err
10
16
  raise ZapierServerError, err
11
17
  end
12
18
 
13
- def rest_client
14
- @rest_client ||= RestClient::Resource.new(zap_url, ssl_version: 'TLSv1')
15
- end
16
-
17
19
  def zap_web_hook_id
18
20
  @zap_web_hook ||= config.web_hooks[zap_name]
19
21
  end
@@ -26,7 +28,11 @@ module ZapierRuby
26
28
  end
27
29
 
28
30
  def zap_url
29
- "#{config.base_uri}#{zap_web_hook_id}/"
31
+ if config.account_id
32
+ "#{config.base_uri}/#{config.account_id}/#{zap_web_hook_id}/"
33
+ else
34
+ "#{config.base_uri}/#{zap_web_hook_id}/"
35
+ end
30
36
  end
31
37
 
32
38
  def config
@@ -1,12 +1,13 @@
1
1
  module ZapierRuby
2
2
  class Config
3
- attr_accessor :base_uri, :web_hooks, :enable_logging, :logger
3
+ attr_accessor :base_uri, :web_hooks, :enable_logging, :logger, :account_id
4
4
 
5
5
  def initialize
6
- self.base_uri = "https://zapier.com/hooks/catch/"
6
+ self.base_uri = "https://hooks.zapier.com/hooks/catch"
7
7
  self.web_hooks = { example_webhook: "webhook_id" }
8
8
  self.enable_logging = true
9
9
  self.logger = Logger.new(STDOUT)
10
+ self.account_id = nil
10
11
  end
11
12
 
12
13
  def configure_with(path_to_yaml_file)
@@ -1,3 +1,3 @@
1
1
  module ZapierRuby
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -10,5 +10,6 @@ ZapierRuby.configure do |c|
10
10
  c.enable_logging = false
11
11
  end
12
12
 
13
- RSpec.configure do |config|
13
+ RSpec.configure do |config|
14
+
14
15
  end
@@ -13,7 +13,7 @@ require 'spec_helper'
13
13
 
14
14
  describe 'Zapper' do
15
15
  let(:zapper) { ZapierRuby::Zapper }
16
- let(:catch_url) { 'https://zapier.com/hooks/catch/webhook_id/' }
16
+ let(:catch_url) { 'https://hooks.zapier.com/hooks/catch/webhook_id/' }
17
17
  let(:instance) { zapper.new(:example_zap) }
18
18
 
19
19
  describe '#zap_url' do
@@ -22,12 +22,12 @@ require 'spec_helper'
22
22
  it 'web_hook_id has val' do
23
23
  url = zapper.new(:nil, 'webhook_id/uuiq').send(:zap_url)
24
24
 
25
- expect(url).to eq 'https://zapier.com/hooks/catch/webhook_id/uuiq/'
25
+ expect(url).to eq 'https://hooks.zapier.com/hooks/catch/webhook_id/uuiq/'
26
26
  end
27
27
  end
28
28
 
29
29
  it '.base_uri' do
30
- expect(ZapierRuby.config.base_uri).to eq "https://zapier.com/hooks/catch/"
30
+ expect(ZapierRuby.config.base_uri).to eq "https://hooks.zapier.com/hooks/catch"
31
31
  end
32
32
 
33
33
  describe '#zap' do
@@ -41,27 +41,27 @@ require 'spec_helper'
41
41
  stub_request(:post, catch_url).with(body: body).to_return(body: result.to_json)
42
42
  response = instance.zap(body)
43
43
 
44
- expect(response.code).to eq 200
45
- expect(JSON.parse(response)['status']).to eq 'success'
44
+ expect(response.code).to eq "200"
45
+ expect(JSON.parse(response.body)['status']).to eq 'success'
46
46
  end
47
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
48
 
55
- it '#zap_url' do
56
- expect(instance.send('zap_url')).to eq hookurl
49
+ describe 'with account id' do
50
+ it 'has account id in url' do
51
+ ZapierRuby.configure { |c| c.account_id = "12345" }
52
+ url = zapper.new(:nil, 'uuiq').send(:zap_url)
53
+ expect(url).to eq 'https://hooks.zapier.com/hooks/catch/12345/uuiq/'
54
+ ZapierRuby.configure { |c| c.account_id = nil }
55
+ end
57
56
  end
58
57
 
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'
58
+ describe 'with base uri configured' do
59
+ it 'has account id in url' do
60
+ ZapierRuby.configure { |c| c.base_uri = "https://test.com" }
61
+ url = zapper.new(:nil, 'uuiq').send(:zap_url)
62
+ expect(url).to eq 'https://test.com/uuiq/'
63
+ ZapierRuby.configure { |c| c.base_uri = nil }
64
+ end
65
65
  end
66
66
  end
67
67
  end
data/zapier_ruby.gemspec CHANGED
@@ -18,8 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "rest-client"
22
-
23
21
  spec.add_development_dependency "bundler", "~> 1.7"
24
22
  spec.add_development_dependency "rake", "~> 10.0"
25
23
  spec.add_development_dependency "rspec"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zapier_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Peterson
@@ -10,20 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2019-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rest-client
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -116,7 +102,6 @@ files:
116
102
  - lib/zapier_ruby/logger_decorator.rb
117
103
  - lib/zapier_ruby/version.rb
118
104
  - lib/zapier_ruby/zapper.rb
119
- - lib/zapier_ruby/zapper_hook.rb
120
105
  - spec/spec_helper.rb
121
106
  - spec/zapier_ruby_spec.rb
122
107
  - zapier_ruby.gemspec
@@ -1,21 +0,0 @@
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