grove-rb 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Bryan Goines
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,10 +1,16 @@
1
1
  # Grove.io Client for Ruby
2
2
 
3
+ ### Install
4
+
5
+ add this line to your Gemfile
6
+
7
+ gem 'grove-rb'
8
+
3
9
  Just read the 2 LOC then you will be fine.
4
10
 
5
11
  ``` ruby
6
12
  # grovebot.rb
7
- grove = Grove.new(GROVE_CHANNEL_KEY, "GroveBot")
13
+ grove = Grove.new(GROVE_CHANNEL_KEY, :service => 'myGroveClient', :icon_url => 'http://example.com/icon.png')
8
14
  grove.post "Hello World!"
9
15
  ```
10
16
 
data/lib/grove.rb CHANGED
@@ -1,19 +1,35 @@
1
1
  require 'faraday'
2
2
 
3
3
  class Grove
4
- attr_accessor :channel_key, :service_name
4
+ attr_reader :channel_key, :last_status
5
+ attr_accessor :service, :icon_url, :url
5
6
 
6
7
  GROVE_API_URI = "https://grove.io/api/notice/%s/"
8
+ DEFAULT_SERVICE_NAME = 'Grove-rb'
7
9
 
8
- def initialize(channel_key, service_name = nil)
10
+ def initialize(channel_key, options = {})
9
11
  @channel_key = channel_key
10
- @service_name = service_name || "Grove-rb"
11
- @last_status = ""
12
+ @service = options[:service] || DEFAULT_SERVICE_NAME
13
+ @icon_url = options[:icon_url]
14
+ @url = options[:url]
15
+ end
16
+
17
+ def channel_key=(new_channel_key)
18
+ @client = nil
19
+ @channel_key = new_channel_key
12
20
  end
13
21
 
14
22
  def post(message)
15
- response = client.post "", {:service => service_name, :message => message}
16
- @last_status = response.status
23
+ options = {
24
+ :message => message,
25
+ :service => service,
26
+ :icon_url => icon_url,
27
+ :url => url
28
+ }
29
+
30
+ options = options.delete_if { |k,v| v.nil? }
31
+
32
+ client.post "", options
17
33
  end
18
34
 
19
35
  def success?
data/lib/grove/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Grove
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,100 @@
1
+ require File.dirname( __FILE__ ) + '/../lib/grove-rb'
2
+
3
+ describe Grove do
4
+ let(:channel_key) { '12345678901234567890123456789012' }
5
+ let(:client) { stub }
6
+
7
+ context "when initializing" do
8
+ it "should set the channel_key" do
9
+ g = Grove.new(channel_key)
10
+
11
+ g.channel_key.should == channel_key
12
+ end
13
+
14
+ it "should set the service" do
15
+ g = Grove.new(channel_key, :service => 'asdf')
16
+
17
+ g.service.should == 'asdf'
18
+ end
19
+
20
+ it "should have a default service" do
21
+ g = Grove.new(channel_key)
22
+
23
+ g.service.should == 'Grove-rb'
24
+ end
25
+
26
+ it "should set the icon_url" do
27
+ icon_url = 'http://domain.com/image.jpg'
28
+
29
+ g = Grove.new(channel_key, :icon_url => icon_url)
30
+
31
+ g.icon_url.should == icon_url
32
+ end
33
+
34
+ it "should set the url" do
35
+ url = 'http://domain.com'
36
+
37
+ g = Grove.new(channel_key, :url => url)
38
+
39
+ g.url.should == url
40
+ end
41
+
42
+ end
43
+
44
+ context "when modifying existing attributes" do
45
+ let(:g) { Grove.new( channel_key )}
46
+
47
+ it "should set service" do
48
+ lambda { g.service = 'new servicename' }.should change { g.service }
49
+ end
50
+
51
+ it "should set icon_url" do
52
+ lambda { g.icon_url = 'new icon url' }.should change { g.icon_url }
53
+ end
54
+
55
+ it "should set url" do
56
+ lambda { g.url = 'new url' }.should change { g.url }
57
+ end
58
+
59
+ context "when changing the channel_key" do
60
+
61
+ it "should use the new key with calls" do
62
+ Faraday.should_receive(:new).and_return { client }
63
+ client.should_receive(:post).at_least(:once)
64
+ g.post('hi')
65
+
66
+ new_channel_key = channel_key.reverse
67
+
68
+ g.channel_key = new_channel_key
69
+
70
+ Faraday.should_receive(:new).with { |options|
71
+ options[:url].should match %r{#{new_channel_key}}
72
+ }.and_return(client)
73
+
74
+ g.post('hi')
75
+ end
76
+
77
+ it "should use the new key with calls" do
78
+ g = Grove.new(channel_key)
79
+
80
+ lambda { g.channel_key = 'asdf' }.should change { g.channel_key }
81
+ end
82
+
83
+ end
84
+ end
85
+
86
+ context "posting messages" do
87
+
88
+ it "should put the message in the options" do
89
+ Faraday.stub(:new).and_return(client)
90
+ client.should_receive(:post).with('', { :message => 'asdf', :service => Grove::DEFAULT_SERVICE_NAME })
91
+ Grove.new(channel_key).post('asdf')
92
+ end
93
+
94
+ it "should post to the correct API url" do
95
+ Faraday.should_receive(:new).with( :url => (Grove::GROVE_API_URI % channel_key)).and_return(client)
96
+ client.should_receive(:post)
97
+ Grove.new(channel_key).post('hi')
98
+ end
99
+ end
100
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grove-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-20 00:00:00.000000000 Z
12
+ date: 2012-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
16
- requirement: &70310847146480 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: 0.7.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70310847146480
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.7.6
25
30
  description:
26
31
  email: bryann83@gmail.com
27
32
  executables: []
@@ -29,12 +34,13 @@ extensions: []
29
34
  extra_rdoc_files: []
30
35
  files:
31
36
  - Gemfile
32
- - Gemfile.lock
33
37
  - grove-rb.gemspec
34
38
  - lib/grove/version.rb
35
39
  - lib/grove-rb.rb
36
40
  - lib/grove.rb
41
+ - LICENSE
37
42
  - README.md
43
+ - spec/grove_spec.rb
38
44
  homepage: http://github.com/bry4n/grove-rb
39
45
  licenses: []
40
46
  post_install_message:
@@ -55,8 +61,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
61
  version: '0'
56
62
  requirements: []
57
63
  rubyforge_project:
58
- rubygems_version: 1.8.10
64
+ rubygems_version: 1.8.23
59
65
  signing_key:
60
66
  specification_version: 3
61
67
  summary: Grove.io client for Ruby
62
68
  test_files: []
69
+ has_rdoc:
data/Gemfile.lock DELETED
@@ -1,22 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- grove-rb (0.1.0)
5
- faraday (~> 0.7.6)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- addressable (2.2.7)
11
- faraday (0.7.6)
12
- addressable (~> 2.2)
13
- multipart-post (~> 1.1)
14
- rack (~> 1.1)
15
- multipart-post (1.1.5)
16
- rack (1.4.1)
17
-
18
- PLATFORMS
19
- ruby
20
-
21
- DEPENDENCIES
22
- grove-rb!