event_girl_client 1.1.1 → 1.2.0

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: 338c8438e3e0c9128e741b38c68ce235c17cb684
4
- data.tar.gz: 063bde9c78788f8c75cda59f2e9174da3a7fd54d
3
+ metadata.gz: 45d48f71187bb05f54d7234c221a05162e2867c3
4
+ data.tar.gz: 0e40be2d59046a776e3a9949b5bedef83b21bbe4
5
5
  SHA512:
6
- metadata.gz: 46fb409415e99b7d8a47dca6c6fffbf0f646717747b04c742742bd5c94455133343a86d09b883229796e7d0594e27e3189253c40925cee3f4b000522cdc9204e
7
- data.tar.gz: 8ce5481f54d9d111508ebdc6fe2ce5d10c950ec95443369cdbc67e0ded17022e80e9716e63bb0ed58038999262e223a43bb38e5137a3847fe767fa4333c5d3b2
6
+ metadata.gz: 986ef878eb244739f99301f321ae95684feae7f9e7a02898c96bdbff271776f5c08d42630e6e50c408b29ca6743831475214e758e8a1545cb6d819df2084163b
7
+ data.tar.gz: 22bfed4e7ecd0d16f5cc9d404a3be5eb1154963c3c68e7e042542cbd8a1601a9ff3044b458fe9b737c7de9b12e803de6c8ab5c4a44ebd5d6dd2fd11fd689a0c2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.2.0
4
+ - Add support for optional content parameter
5
+ - EventGirl::Client.send_event is deprecated, use #send! instead
6
+ - Allows setting the url to protocol + hostname only, w/o path
7
+
3
8
  ## v1.1.1
4
9
  - Adds SSL-support
5
10
 
data/bin/event_girl CHANGED
@@ -15,7 +15,7 @@ Version = EventGirl::Client::VERSION.dup
15
15
 
16
16
  options = {}
17
17
  option_parser = OptionParser.new do |opts|
18
- opts.banner = "Usage: event_girl [options] EVENTNAME"
18
+ opts.banner = "Usage: event_girl [options] EVENTNAME OPTIONAL_DATA"
19
19
 
20
20
  opts.separator ""
21
21
  opts.separator "Options:"
@@ -57,7 +57,7 @@ end
57
57
 
58
58
  begin
59
59
  client = EventGirl::Client.new(options[:url], options[:api_token])
60
- client.send_event(ARGV[0])
60
+ client.send!(ARGV[0], ARGV[1])
61
61
  rescue => e
62
62
  puts "E: #{e.message}"
63
63
  puts e.backtrace if options[:debug]
@@ -6,7 +6,7 @@ require 'rubygems'
6
6
  module EventGirl
7
7
  class Client
8
8
 
9
- VERSION = '1.1.1'
9
+ VERSION = '1.2.0'
10
10
 
11
11
  # Class-wide configuration
12
12
  @@api_token = nil
@@ -20,19 +20,27 @@ module EventGirl
20
20
  raise ArgumentError.new('No url provided.') unless @url
21
21
  end
22
22
 
23
+ # @deprecated Use {#send!} instead.
24
+ def send_event(*args)
25
+ send!(*args)
26
+ end
27
+
23
28
  # POSTs a string to the event_girl server.
24
- def send_event(title)
29
+ def send!(title, content = nil)
25
30
  uri = URI.parse(url)
26
31
 
32
+ # Auto-correct missing trailing slash
33
+ path = uri.path == '' ? '/' : uri.path
34
+
27
35
  # This is all the post request stuff.
28
- req = Net::HTTP::Post.new(uri.path)
36
+ req = Net::HTTP::Post.new(path)
29
37
 
30
38
  # The request format and content type is json
31
39
  req['Accept'] = "application/json"
32
40
  req['Content-Type'] = "application/json"
33
41
 
34
42
  # This takes the entered api token and title. This is what is sent. It is a HASH!
35
- req.body = '{"api_token":"' + api_token + '","incoming_event":{"title":"' + title.to_s + '"}}'
43
+ req.body = '{"api_token":"' + api_token + '","incoming_event":{"title":"' + title.to_s + '","content":"' + content.to_s + '"}}'
36
44
 
37
45
  # The request is sent via HTTP to the host and port. You also get a response
38
46
  # ex: 201 (it worked)
data/spec/client_spec.rb CHANGED
@@ -43,16 +43,45 @@ describe EventGirl::Client do
43
43
  end
44
44
 
45
45
  describe '#send_event' do
46
- it 'requires the event title as argument' do
47
- expect(subject.method(:send_event).arity).to eql 1
46
+ it 'still responds to send_event' do
47
+ expect(subject).to respond_to :send_event
48
+ end
49
+
50
+ it 'delegates to #send!' do
51
+ subject.should_receive(:send!).with('foo', 'bar')
52
+ subject.send_event('foo', 'bar')
53
+ end
54
+ end
55
+
56
+ describe '#send!' do
57
+ it 'requires the event title and supports content optionally' do
58
+ expect(subject.method(:send!).arity).to eql(-2)
59
+ end
60
+
61
+ it 'adds a missing trailing slash' do
62
+ url = 'http://eg.example.com'
63
+ stub_request(:post, "#{url}/")
64
+ subject = described_class.new url
65
+ expect do
66
+ subject.send! ''
67
+ end.not_to raise_error
48
68
  end
49
69
 
50
70
  it 'sends json data' do
51
71
  title = 'event girl test'
52
- json = '{"api_token":"' + subject.api_token + '","incoming_event":{"title":"' + title + '"}}'
72
+ json = '{"api_token":"' + subject.api_token + '","incoming_event":{"title":"' + title + '","content":""}}'
73
+ stub_request(:post, subject.url).
74
+ with(body: json)
75
+ subject.send! title
76
+ end
77
+
78
+ it 'allows sending of optional content' do
79
+ title = 'event girl test'
80
+ content = 'this is additional payload data'
81
+ json = '{"api_token":"' + subject.api_token + '","incoming_event":{"title":"' + title + '","content":"' + content + '"}}'
53
82
  stub_request(:post, subject.url).
54
83
  with(body: json)
55
- subject.send_event title
84
+ subject.send! title, content
56
85
  end
57
86
 
58
87
  it 'sends json headers' do
@@ -63,7 +92,7 @@ describe EventGirl::Client do
63
92
  'Content-Type' => 'application/json'
64
93
  }
65
94
  )
66
- subject.send_event 'event girl test'
95
+ subject.send! 'event girl test'
67
96
  end
68
97
  end
69
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_girl_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Susanne Dewein
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-01 00:00:00.000000000 Z
13
+ date: 2013-10-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler