upcloudify 0.2.1 → 0.3

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: e8c0d88922162a79fa51516d8ee28087ceb3e124
4
- data.tar.gz: fea1862b2ec0f7bf85bd7cc580a69ac252f0939c
3
+ metadata.gz: c0182ed646b50b0a9f00e18e9d857e0a7e89b060
4
+ data.tar.gz: 69771857a3449b01acb736d4f331b6f2109ff3d1
5
5
  SHA512:
6
- metadata.gz: 8fcd85a8ed939f8b4ecde3d696469e09fb383a95a346b22da7347100c93c921ad6e6143332ac3fc5325adb9446d8fc13492db5dbeddb13731331666c1dec32c0
7
- data.tar.gz: f5c9bb1804cb00f2b3a6b13448af228f1327a3e2e6c4e06dc2f8568327f994a0354ad84e969753739771b9514520dc1ff5f57f307bb85b8a5028a4121e4d3557
6
+ metadata.gz: 83697d6c71b144a0af6e4a065677c18e34b74427655ae296c37646ea3c65d8f541c1b25f769b87f566b499bd3fe08a822f234ee50c15e45822027d0967c6c038
7
+ data.tar.gz: 1a09825874d8c783f3e1900f0efd2f9750dc4e181231a969ca2af5ebb1404529dfde89d84bf8f3e27fe5bbcca9065cac65286429984ecdacf3acc6db949f8b21
data/README.md CHANGED
@@ -18,6 +18,8 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ Version 0.3 started using required named parameters and so will only run on Ruby version 2.2 and higher.
22
+
21
23
  Configure the app:
22
24
 
23
25
  ``` ruby
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ require 'irb'
5
+ require 'irb/completion'
6
+ require 'upcloudify'
7
+ ARGV.clear
8
+ IRB.start
9
+ end
@@ -0,0 +1,30 @@
1
+ class Upcloudify
2
+ module Notifiers
3
+ class Slack
4
+ require "httparty"
5
+
6
+ def initialize(to: nil, url:)
7
+ @url = url
8
+ @to = to
9
+ end
10
+
11
+ def notify(text: nil)
12
+ HTTParty.post(
13
+ @url,
14
+ headers: {"Content-Type" => content_type},
15
+ body: payload.merge(text: text).to_json
16
+ )
17
+ end
18
+
19
+ def payload
20
+ { channel: @to }
21
+ end
22
+
23
+ private
24
+
25
+ def content_type
26
+ "application/json"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
- module Upcloudify
2
- VERSION = "0.2.1"
1
+ class Upcloudify
2
+ VERSION = "0.3"
3
3
  end
data/lib/upcloudify.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "upcloudify/version"
2
+ require "notifiers/slack"
3
+
2
4
  require 'gem_config'
3
5
  require 'zip/zip'
4
6
  require 'zippy'
@@ -6,21 +8,32 @@ require 'pony'
6
8
  require 'fog'
7
9
  require 'date'
8
10
 
9
- module Upcloudify
10
- include GemConfig::Base
11
+ class Upcloudify
12
+
13
+ def initialize(uploader:, notifier:)
14
+ @uploader = uploader
15
+ @notifier = notifier
16
+ end
11
17
 
12
- with_configuration do
13
- has :aws_access_key_id, default: ENV['AWS_ACCESS_KEY_ID']
14
- has :aws_secret_access_key, default: ENV['AWS_SECRET_ACCESS_KEY']
15
- has :aws_directory
18
+ def upload_and_notify(filename:, attachment:, message: "%s")
19
+ expiration = (Date.today + 7).to_time
20
+ file = @uploader.upload(filename, attachment)
21
+ @notifier.notify(text: message % file.url(expiration))
16
22
  end
17
23
 
18
24
  class S3
19
25
 
26
+ include GemConfig::Base
27
+ with_configuration do
28
+ has :aws_access_key_id, default: ENV['AWS_ACCESS_KEY_ID']
29
+ has :aws_secret_access_key, default: ENV['AWS_SECRET_ACCESS_KEY']
30
+ has :aws_directory
31
+ end
32
+
20
33
  def initialize(options = {
21
34
  aws_access_key_id: Upcloudify.configuration.aws_access_key_id,
22
35
  aws_secret_access_key: Upcloudify.configuration.aws_secret_access_key,
23
- aws_directory: Upcloudify.configuration.aws_directory
36
+ aws_directory: Upcloudify.configuration.aws_directory,
24
37
  })
25
38
  raise ArgumentError, "aws_access_key_id is required" unless options[:aws_access_key_id]
26
39
  raise ArgumentError, "aws_secret_access_key is required" unless options[:aws_secret_access_key]
@@ -80,7 +93,6 @@ module Upcloudify
80
93
  body: (options[:body] || '') + file.url(expiration) + ' '
81
94
 
82
95
  end
83
-
84
96
  end
85
97
 
86
98
  end
data/scratch ADDED
@@ -0,0 +1,2 @@
1
+
2
+ https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
@@ -0,0 +1,50 @@
1
+ require "notifiers/slack"
2
+
3
+ describe Upcloudify::Notifiers::Slack do
4
+ Given(:recipient) { "@parasquid" }
5
+ Given(:klass) { Upcloudify::Notifiers::Slack }
6
+ Given(:slack_api_url) { "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"}
7
+ context "sanity check" do
8
+ Given(:token) { "token" }
9
+ When(:instance) { klass.new(to: recipient, url: slack_api_url) }
10
+ Then { instance != nil }
11
+ end
12
+
13
+ Given(:instance) { klass.new(to: recipient, url: slack_api_url) }
14
+ describe "slack endpoint connectivity" do
15
+ context "a connection is made to the slack server" do
16
+ Given!(:slack_api_stub) { stub_request(:post, slack_api_url) }
17
+ When { instance.notify }
18
+ Then { expect(slack_api_stub).to have_been_requested }
19
+ end
20
+
21
+ context "the content type is application/json" do
22
+ Given!(:slack_api_stub) {
23
+ stub_request(:post, slack_api_url).
24
+ with(headers: {"Content-Type" => "application/json"})
25
+ }
26
+ When { instance.notify }
27
+ Then { expect(slack_api_stub).to have_been_requested }
28
+ end
29
+
30
+ context "a custom message can be sent for the notification" do
31
+ Given!(:slack_api_stub) {
32
+ stub_request(:post, slack_api_url).
33
+ with(
34
+ headers: {"Content-Type" => "application/json"},
35
+ body: { text: "abc", channel: recipient }
36
+ )
37
+ }
38
+ When { instance.notify(text: "abc") }
39
+ Then { expect(slack_api_stub).to have_been_requested }
40
+ end
41
+ end
42
+
43
+ describe "payload" do
44
+ Given(:instance) { klass.new(to: recipient, url: slack_api_url) }
45
+ context "the payload contains the username to be notified" do
46
+ When(:payload) { instance.payload }
47
+ Then { expect(payload).to include(channel: recipient) }
48
+ end
49
+ end
50
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'rspec/given'
2
+ require 'webmock/rspec'
3
+
1
4
  # This file was generated by the `rspec --init` command. Conventionally, all
2
5
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
6
  # The generated `.rspec` file contains `--require spec_helper` which will cause
@@ -44,4 +44,60 @@ describe Upcloudify::S3 do
44
44
  expect(subject.cloud(connection)).to eq files
45
45
  end
46
46
  end
47
+ end
48
+
49
+ describe Upcloudify do
50
+ describe ".upload_and_notify" do
51
+ Given(:test_file_class) {
52
+ class TestFile
53
+ def url(expiration)
54
+ "filename link"
55
+ end
56
+ end
57
+ TestFile
58
+ }
59
+ Given(:test_file) { test_file_class.new }
60
+ Given(:uploader) { double("uploader") }
61
+ Given { allow(uploader).to receive(:upload).and_return(test_file) }
62
+ Given(:notifier) { double("notifier") }
63
+ Given(:klass) { Upcloudify }
64
+ Given(:instance) { klass.new(uploader: uploader, notifier: notifier) }
65
+ context "notifications" do
66
+ Given { expect(uploader).to receive(:upload) }
67
+ context "notifies the user" do
68
+ When { expect(notifier).to receive(:notify) }
69
+ Then {
70
+ expect {
71
+ instance.upload_and_notify(filename: 'abc', attachment: '123')
72
+ }.not_to raise_error
73
+ }
74
+ end
75
+ context "the notification has a custom message" do
76
+ When { expect(notifier).to receive(:notify).with({text: "hi"}) }
77
+ Then {
78
+ expect {
79
+ instance.upload_and_notify(filename: 'abc', attachment: '123', message: "hi")
80
+ }.not_to raise_error
81
+ }
82
+ end
83
+ context "the notification can merge the file url" do
84
+ When { expect(notifier).to receive(:notify).with({text: "your report <filename link>"}) }
85
+ Then {
86
+ expect {
87
+ instance.upload_and_notify(filename: 'abc', attachment: '123', message: "your report <%s>")
88
+ }.not_to raise_error
89
+ }
90
+ end
91
+ end
92
+ context "uploads the file" do
93
+ Given { allow(notifier).to receive(:notify) }
94
+ When { expect(uploader).to receive(:upload) }
95
+ Then {
96
+ expect {
97
+ instance.upload_and_notify(filename: 'abc', attachment: '123')
98
+ }.not_to raise_error
99
+ }
100
+ end
101
+ end
102
+
47
103
  end
data/upcloudify.gemspec CHANGED
@@ -25,11 +25,14 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "pry"
26
26
  spec.add_development_dependency "rspec"
27
27
  spec.add_development_dependency "guard-rspec"
28
+ spec.add_development_dependency "rspec-given"
29
+ spec.add_development_dependency "webmock"
28
30
 
29
31
  spec.add_dependency 'gem_config'
30
32
  spec.add_dependency 'pony'
31
33
  spec.add_dependency 'zippy'
32
34
  spec.add_dependency 'zip-zip'
33
35
  spec.add_dependency 'fog'
36
+ spec.add_dependency 'httparty'
34
37
 
35
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upcloudify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - parasquid
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-23 00:00:00.000000000 Z
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-given
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: webmock
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'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: gem_config
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +178,20 @@ dependencies:
150
178
  - - ">="
151
179
  - !ruby/object:Gem::Version
152
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: httparty
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
153
195
  description: |-
154
196
  Upcloudify simplifies the process for uploading
155
197
  attachments to the cloud and emailing the recipient
@@ -167,11 +209,14 @@ files:
167
209
  - LICENSE.txt
168
210
  - README.md
169
211
  - Rakefile
212
+ - lib/notifiers/slack.rb
170
213
  - lib/upcloudify.rb
171
214
  - lib/upcloudify/version.rb
172
215
  - sample_app/Gemfile
173
216
  - sample_app/sample.rb
174
217
  - sample_app/views/index.erb
218
+ - scratch
219
+ - spec/notifiers/slack_spec.rb
175
220
  - spec/spec_helper.rb
176
221
  - spec/upcloudify_spec.rb
177
222
  - upcloudify.gemspec
@@ -195,10 +240,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
240
  version: '0'
196
241
  requirements: []
197
242
  rubyforge_project:
198
- rubygems_version: 2.4.8
243
+ rubygems_version: 2.5.1
199
244
  signing_key:
200
245
  specification_version: 4
201
246
  summary: Upload a file to the cloud and email a link for the attachment
202
247
  test_files:
248
+ - spec/notifiers/slack_spec.rb
203
249
  - spec/spec_helper.rb
204
250
  - spec/upcloudify_spec.rb