developerreply 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 04298150d520fff66cbb73a76de10843dcc70a41
4
+ data.tar.gz: b753fd4cd272b59528c0ac50ed2e6296480de585
5
+ SHA512:
6
+ metadata.gz: ab225192a54a2cd28447ec9b36a75546c14172ebe34f97e23ca516d5bf0a3640d63adf11ae9baed8cbaabdc756ab93c69ab2db2a0b774f9d10fbda2d49d3054d
7
+ data.tar.gz: b1b2ef51111f3df20584b97e42311561cae41d6b138f1b176235afd1549981cdde4d970027b1d463aa7913a0de5d09e424bd24a0bcecf5269c7901e63063e1bc
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .env
19
+ .idea
20
+ bin
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in digitalocean.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Scott Motte
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # developerreply
2
+
3
+ ![](https://raw.githubusercontent.com/scottmotte/developerreply/master/developerreply.jpg)
4
+
5
+ Rubygem for adding hosts & urls to SendGrid's Parse Incoming Email settings (/developer/reply).
6
+
7
+ ## Usage
8
+
9
+ ```ruby
10
+ Developerreply.username = "your_sendgrid_username"
11
+ Developerreply.password = "your_sendgrid_password"
12
+ Developerreply.create({hostname: "domain.com", url: "http://webhook.com/wherever"})
13
+ ```
14
+
15
+ ## Development
16
+
17
+ ```
18
+ bundle install --binstubs=bin
19
+ export SENDGRID_USERNAME=yourusername
20
+ export SENDGRID_PASSWORD=yourpassword
21
+ bin/rspec
22
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'developerreply/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "developerreply"
8
+ gem.version = Developerreply::VERSION
9
+ gem.authors = ["scottmotte"]
10
+ gem.email = ["mot@mot.la"]
11
+ gem.description = %q{Ruby bindings for the SendGrid /developer/reply call.}
12
+ gem.summary = %q{Ruby bindings for the SendGrid /developer/reply call.}
13
+ gem.homepage = "http://github.com/scottmotte/developerreply"
14
+
15
+ gem.add_dependency "faraday", "~> 0.8.9"
16
+ gem.add_dependency "faraday_middleware", "~> 0.9.0"
17
+
18
+ gem.add_development_dependency "foreman"
19
+ gem.add_development_dependency "pry"
20
+ gem.add_development_dependency "rake"
21
+ gem.add_development_dependency "rspec"
22
+
23
+ gem.files = `git ls-files`.split($/)
24
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
25
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
26
+ gem.require_paths = ["lib"]
27
+ end
Binary file
@@ -0,0 +1,3 @@
1
+ module Developerreply
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,92 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "developerreply/version"
4
+
5
+ module Developerreply
6
+ extend self
7
+
8
+ def username=(username)
9
+ @username = username
10
+ setup_request!
11
+
12
+ @username
13
+ end
14
+
15
+ def username
16
+ return @username if @username
17
+ "username_required"
18
+ end
19
+
20
+ def password=(password)
21
+ @password = password
22
+ setup_request!
23
+
24
+ @password
25
+ end
26
+
27
+ def password
28
+ return @password if @password
29
+ "password_required"
30
+ end
31
+
32
+ def request=(request)
33
+ @request = request
34
+ end
35
+
36
+ def request
37
+ @request
38
+ end
39
+
40
+ def create(options={})
41
+ cookie = attempt_login_and_return_cookie
42
+
43
+ hostname = options[:hostname]
44
+ url = options[:url]
45
+ payload = "reply_option[hostname]=#{hostname}&reply_option[url]=#{url}"
46
+
47
+ resp = Developerreply.request.post do |req|
48
+ req.path = "/developer/reply"
49
+ req.body = payload
50
+ req.headers["Cookie"] = cookie
51
+ end
52
+
53
+ if resp.status == 302 # for SendGrid's response here, a 302 is a successful create... yea, I know.
54
+ return true
55
+ else
56
+ raise "Unable to create hostname and url at /developer/reply"
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def login_payload
63
+ "login[username]=#{Developerreply.username}&login[password]=#{Developerreply.password}"
64
+ end
65
+
66
+ def attempt_login_and_return_cookie
67
+ cookie = ""
68
+
69
+ resp = Developerreply.request.post '/login', login_payload
70
+
71
+ if resp.status == 302 # for SendGrid's auth, a 302 is a successful login where a 200 is not successful... yeah, I know.
72
+ set_cookie_header = resp.headers["set-cookie"]
73
+ cookie = set_cookie_header.split(";")[0]
74
+ end
75
+
76
+ raise "Authentication failed" if cookie == ""
77
+
78
+ cookie
79
+ end
80
+
81
+ def setup_request!
82
+ options = {
83
+ :url => "https://sendgrid.com",
84
+ :ssl => {:verify => false}
85
+ }
86
+
87
+ Developerreply.request = ::Faraday::Connection.new(options) do |builder|
88
+ builder.adapter ::Faraday.default_adapter
89
+ end
90
+ end
91
+ end
92
+
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Developerreply do
4
+ subject { Developerreply }
5
+
6
+ describe "defaults" do
7
+ before do
8
+ subject.username = nil
9
+ subject.password = nil
10
+ end
11
+
12
+ it { expect(subject::VERSION).to eq("0.0.1") }
13
+ end
14
+
15
+ describe "setting values" do
16
+ let(:username) { "username" }
17
+ let(:password) { "password" }
18
+
19
+ before do
20
+ subject.username = username
21
+ subject.password = password
22
+ end
23
+
24
+ it { expect(subject.username).to eq(username) }
25
+ it { expect(subject.password).to eq(password) }
26
+ end
27
+
28
+ describe ".create" do
29
+ let(:username) { ENV["SENDGRID_USERNAME"] }
30
+ let(:password) { ENV["SENDGRID_PASSWORD"] }
31
+
32
+ let(:hostname) { "#{Time.now.to_i}.webhook.email" }
33
+ let(:url) { "http://domain-#{Time.now.to_i}.com/inbound" }
34
+
35
+ before do
36
+ subject.username = username
37
+ subject.password = password
38
+ end
39
+
40
+ it do
41
+ resp = subject.create({hostname: hostname, url: url})
42
+ expect(resp).to eq(true)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'pry'
4
+ require 'developerreply'
5
+ require 'securerandom'
6
+
7
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: developerreply
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - scottmotte
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.9
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: foreman
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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: rake
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: rspec
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
+ description: Ruby bindings for the SendGrid /developer/reply call.
98
+ email:
99
+ - mot@mot.la
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - developerreply.gemspec
111
+ - developerreply.jpg
112
+ - lib/developerreply.rb
113
+ - lib/developerreply/version.rb
114
+ - spec/developerreply_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: http://github.com/scottmotte/developerreply
117
+ licenses: []
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.4.1
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Ruby bindings for the SendGrid /developer/reply call.
139
+ test_files:
140
+ - spec/developerreply_spec.rb
141
+ - spec/spec_helper.rb