gnip-rule 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,7 +58,7 @@ module GnipRule
58
58
  end
59
59
 
60
60
  def too_many_positive_terms?
61
- @value.scan(/\b\w+|\"[\-\s\w]+\"\b/).size > 10
61
+ @value.scan(/\b\w+|\"[\-\s\w]+\"\b/).size > 30
62
62
  end
63
63
 
64
64
  def contains_empty_source?
@@ -1,3 +1,3 @@
1
1
  module GnipRule
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnip-rule
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-04 00:00:00.000000000 Z
12
+ date: 2013-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.9.2
21
+ version: 10.0.3
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.9.2
29
+ version: 10.0.3
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 2.10.0
37
+ version: 2.13.0
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 2.10.0
45
+ version: 2.13.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: webmock
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 1.4.0
69
+ version: 1.6.2
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 1.4.0
77
+ version: 1.6.2
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: guard-rspec
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +82,7 @@ dependencies:
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 1.2.0
85
+ version: 2.5.0
86
86
  type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 1.2.0
93
+ version: 2.5.0
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: fuubar
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -162,7 +162,7 @@ dependencies:
162
162
  requirements:
163
163
  - - ~>
164
164
  - !ruby/object:Gem::Version
165
- version: 1.7.0
165
+ version: 1.7.7
166
166
  type: :runtime
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
@@ -170,7 +170,7 @@ dependencies:
170
170
  requirements:
171
171
  - - ~>
172
172
  - !ruby/object:Gem::Version
173
- version: 1.7.0
173
+ version: 1.7.7
174
174
  description: Ruby library for working with the Gnip Rules API
175
175
  email:
176
176
  - me@eriwen.com
@@ -178,24 +178,10 @@ executables: []
178
178
  extensions: []
179
179
  extra_rdoc_files: []
180
180
  files:
181
- - .gitignore
182
- - .pryrc
183
- - .rvmrc
184
- - .travis.yml
185
- - CONTRIBUTING.md
186
- - Gemfile
187
- - Guardfile
188
- - LICENSE
189
- - README.md
190
- - Rakefile
191
- - gnip-rule.gemspec
192
- - lib/gnip-rule.rb
193
181
  - lib/gnip-rule/client.rb
194
182
  - lib/gnip-rule/rule.rb
195
183
  - lib/gnip-rule/version.rb
196
- - spec/gnip-rule/client_spec.rb
197
- - spec/gnip-rule/rule_spec.rb
198
- - spec/spec-helper.rb
184
+ - lib/gnip-rule.rb
199
185
  homepage: https://github.com/eriwen/gnip-rule
200
186
  licenses: []
201
187
  post_install_message:
@@ -216,12 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
202
  version: '0'
217
203
  requirements: []
218
204
  rubyforge_project: gnip-rule
219
- rubygems_version: 1.8.24
205
+ rubygems_version: 1.8.25
220
206
  signing_key:
221
207
  specification_version: 3
222
208
  summary: Ruby library for working with the Gnip Rules API
223
- test_files:
224
- - spec/gnip-rule/client_spec.rb
225
- - spec/gnip-rule/rule_spec.rb
226
- - spec/spec-helper.rb
227
- has_rdoc:
209
+ test_files: []
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- *.gem
2
- .bundle
3
- .idea
4
- Gemfile.lock
5
- pkg/*
6
- .rbx
data/.pryrc DELETED
@@ -1,2 +0,0 @@
1
- $: << "/Users/eric/src/gnip-rule/lib/"
2
- require 'gnip-rule'
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.3@gnip-rule --create
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 1.8.7
5
- - jruby-19mode
6
- - rbx-19mode
7
- script: rspec spec
@@ -1,9 +0,0 @@
1
- When submitting pull requests, please do the following to make it easier to incorporate your changes:
2
-
3
- * Include unit and/or functional specs that validate changes you're making.
4
- * Rebase your changes onto the HEAD of my fork if you can do so cleanly.
5
- * If submitting additional functionality, provide an example of how to use it.
6
- * Please keep code style consistent with surrounding code.
7
-
8
- ## Testing
9
- You can run all tests by simply running `bundle exec rspec spec` from your favorite shell.
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- # Specify your gem's dependencies in gnip-rule.gemspec
4
- gemspec
data/Guardfile DELETED
@@ -1,5 +0,0 @@
1
- guard 'rspec', :cli => '--drb --format Fuubar --color', :version => 2 do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
- watch('spec/spec_helper.rb') { "spec" }
5
- end
data/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2012 Eric Wendelin
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- this software and associated documentation files (the "Software"), to deal in
5
- the Software without restriction, including without limitation the rights to
6
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
- of the Software, and to permit persons to whom the Software is furnished to do
8
- so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- SOFTWARE.
data/README.md DELETED
@@ -1,40 +0,0 @@
1
- # gnip-rule [![Build Status](https://secure.travis-ci.org/eriwen/gnip-rule.png)](http://travis-ci.org/eriwen/gnip-rule) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/eriwen/gnip-rule)
2
- This gem simplifies the effort to add/delete/list rules using the [Gnip Rules API](http://support.gnip.com/customer/portal/articles/477713-rules-methods-documentation). It handles HTTP request/response and helps your rules conform to Gnip's restrictions.
3
-
4
- ## Installation
5
- `gem install gnip-rule` or add the following to your `Gemfile`:
6
-
7
- ```ruby
8
- gem 'gnip-rule', '~> 0.3.1'
9
- ```
10
-
11
- ## Usage
12
-
13
- ```ruby
14
- require 'gnip-rule'
15
-
16
- rules = GnipRule::Client.new(API_URL, USERNAME, PASSWORD)
17
-
18
- # Add as a String, Rule, or Array of either
19
- rules.add('foo')
20
- rules.add('bar', 'tag')
21
- rules.add(['foo', 'bar', 'baz'], 'tag')
22
- rules.add(GnipRule::Rule.new('value', 'tag'))
23
- rules.add([GnipRule::Rule.new('foo', 'bar'), GnipRule::Rule.new('baz', 'tag2')])
24
-
25
- # Same with delete
26
- rules.delete('baz', 'tag')
27
- rules.delete(['foo', 'bar'])
28
- rules.delete(GnipRule::Rule.new('value', 'tag'))
29
-
30
- # Get all rules
31
- rules_list = rules.list()
32
- rules_list.each { |rule| rule.valid? }
33
- jsonified = rules_list.map { |rule| rule.as_json `}
34
- rules_tagged_foo = rules_list.select { |rule| rule.tag == 'foo' }
35
- ```
36
-
37
- ## License
38
- Licenced under the [MIT License](http://www.opensource.org/licenses/mit-license.php)
39
-
40
- I provide this software free of charge. If you find it helpful, please endorse me on coderwall: [![endorse](http://api.coderwall.com/eriwen/endorsecount.png)](http://coderwall.com/eriwen)
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- require 'rspec/core/rake_task'
5
-
6
- desc "Run all RSpec tests"
7
- RSpec::Core::RakeTask.new(:spec)
8
-
9
- task :default => :spec
10
- task :test => [:spec]
@@ -1,44 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path('../lib', __FILE__)
3
- require 'gnip-rule/version'
4
-
5
- Gem::Specification.new do |s|
6
- s.name = 'gnip-rule'
7
- s.version = GnipRule::VERSION
8
-
9
- s.platform = Gem::Platform::RUBY
10
- s.authors = ['Eric Wendelin']
11
- s.email = ['me@eriwen.com']
12
- s.homepage = 'https://github.com/eriwen/gnip-rule'
13
- s.summary = %q{Ruby library for working with the Gnip Rules API}
14
- s.description = s.summary
15
-
16
- s.rubyforge_project = 'gnip-rule'
17
-
18
- s.files = `git ls-files`.split("\n")
19
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
- s.require_paths = ['lib']
22
-
23
- s.add_development_dependency 'rake', '~> 0.9.2'
24
- s.add_development_dependency 'rspec', '~> 2.10.0'
25
- s.add_development_dependency 'webmock', '~> 1.8.11'
26
- s.add_development_dependency 'guard', '~> 1.4.0'
27
- s.add_development_dependency 'guard-rspec', '~> 1.2.0'
28
- s.add_development_dependency 'fuubar', '~> 1.1.0'
29
-
30
- if RbConfig::CONFIG['host_os'] =~ /darwin/
31
- s.add_development_dependency 'rb-fsevent'
32
- s.add_development_dependency 'ruby_gntp'
33
- elsif RbConfig::CONFIG['host_os'] =~ /linux/
34
- s.add_development_dependency 'rb-inotify'
35
- s.add_development_dependency 'libnotify'
36
- elsif RbConfig::CONFIG['host_os'] =~ /msmin|mingw/
37
- s.add_development_dependency 'wdm'
38
- s.add_development_dependency 'rb-notifu'
39
- end
40
-
41
- s.add_dependency 'rest-client', '~> 1.6.7'
42
- s.add_dependency 'json', '~> 1.7.0'
43
- s.add_dependency 'jruby-openssl' if RUBY_PLATFORM == 'java'
44
- end
@@ -1,90 +0,0 @@
1
- require 'spec-helper'
2
-
3
- require 'gnip-rule/client'
4
-
5
- describe GnipRule::Client do
6
- let(:xml_base_url) { 'https://api.gnip.com:443/accounts/foo/publishers/twitter/streams/track/prod/rules.xml' }
7
- let(:base_url) { 'https://api.gnip.com:443/accounts/foo/publishers/twitter/streams/track/prod/rules.json' }
8
- let(:base_url_with_auth) { 'https://username:password@api.gnip.com:443/accounts/foo/publishers/twitter/streams/track/prod/rules.json' }
9
-
10
- describe '.new' do
11
- it 'should convert XML URLs to JSON' do
12
- GnipRule::Client.new(xml_base_url, 'username', 'password').url.should == base_url
13
- end
14
-
15
- it 'should not munch JSON URLs' do
16
- GnipRule::Client.new(base_url, 'username', 'password').url.should == base_url
17
- end
18
-
19
- end
20
-
21
- describe 'instance' do
22
- subject { GnipRule::Client.new(base_url, 'username', 'password') }
23
-
24
- describe '#add' do
25
- it 'should POST rule to the given URL with given credentials' do
26
- stub_request(:post, base_url_with_auth).
27
- with(:body => '{"rules":[{"value":"value","tag":"tag"}]}').
28
- to_return(:status => 200, :body => '', :headers => {})
29
- subject.add('value', 'tag')
30
- end
31
-
32
- it 'should raise an error if Gnip returns HTTP error' do
33
- stub_request(:post, base_url_with_auth).
34
- with(:body => '{"rules":[{"value":"value","tag":"tag"}]}').
35
- to_return(:status => 401, :body => 'Error message', :headers => {})
36
- lambda { subject.add('value', 'tag') }.should raise_error
37
- end
38
- end
39
-
40
- describe '#delete' do
41
- it 'should POST rule json to a URL with given credentials' do
42
- stub_request(:post, "#{base_url_with_auth}?_method=delete").
43
- with(:body => '{"rules":[{"value":"value","tag":"tag"}]}').
44
- to_return(:status => 200, :body => '', :headers => {})
45
- subject.delete('value', 'tag')
46
- end
47
- end
48
-
49
- describe '#list' do
50
- it 'should GET a URL with given credentials' do
51
- stub_request(:get, base_url_with_auth).
52
- to_return(:status => 200, :body => '{"rules":[{"value":"foo","tag":"baz"},{"value":"bar","tag":"baz"}]}')
53
- rules = subject.list()
54
- rules.size.should == 2
55
- rules.map { |r| r.valid?.should == true }
56
- end
57
-
58
- it 'should raise an error if Gnip returns HTTP error' do
59
- stub_request(:get, base_url).
60
- with(:body => '{"rules":[{"value":"value","tag":"tag"}]}').
61
- to_return(:status => 401, :body => 'Error message', :headers => {})
62
- lambda { subject.list() }.should raise_error
63
- end
64
- end
65
-
66
- describe '#jsonify_rules' do
67
- it 'should JSONify Strings' do
68
- json = subject.gen_json_payload('foo', 'bar')
69
- json.should == '{"rules":[{"value":"foo","tag":"bar"}]}'
70
- end
71
-
72
- it 'should JSONify Rules' do
73
- json = subject.gen_json_payload(GnipRule::Rule.new('baz', 'foo'))
74
- json.should == '{"rules":[{"value":"baz","tag":"foo"}]}'
75
- end
76
-
77
- it 'should JSONify an Array of Strings with a tag' do
78
- json = subject.gen_json_payload(['foo', 'bar'], 'baz')
79
- json.should == '{"rules":[{"value":"foo","tag":"baz"},{"value":"bar","tag":"baz"}]}'
80
- end
81
-
82
- it 'should JSONify an Array of Rules' do
83
- rule1 = GnipRule::Rule.new('baz', 'foo')
84
- rule2 = GnipRule::Rule.new('bar', 'thing')
85
- json = subject.gen_json_payload([rule1, rule2])
86
- json.should == '{"rules":[{"value":"baz","tag":"foo"},{"value":"bar","tag":"thing"}]}'
87
- end
88
- end
89
- end
90
- end
@@ -1,58 +0,0 @@
1
- require 'spec-helper'
2
-
3
- require 'gnip-rule/rule'
4
-
5
- describe GnipRule::Rule do
6
- describe '#initialize' do
7
- it 'should allow an optional tag' do
8
- rule = GnipRule::Rule.new('value')
9
- rule.tag.should be_nil
10
-
11
- rule_with_tag = GnipRule::Rule.new('value', 'tag')
12
- rule_with_tag.tag.should == 'tag'
13
- end
14
- end
15
-
16
- describe '#valid?' do
17
- it 'should consider rules with "stop words" to be invalid' do
18
- GnipRule::Rule.new('an value').should_not be_valid
19
- end
20
- it 'should consider rules that are too long to be invalid' do
21
- rule = GnipRule::Rule.new('01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789')
22
- rule.should_not be_valid
23
- end
24
- it 'should consider empty sources to be invalid' do
25
- GnipRule::Rule.new('foo source: bar').should_not be_valid
26
- end
27
- it 'should consider negative ORs to be invalid' do
28
- GnipRule::Rule.new('-iphone OR ipad').should_not be_valid
29
- end
30
- it 'should consider rules with more than 10 positive terms invalid' do
31
- GnipRule::Rule.new('one two three four five six seven eight nine ten eleven').should_not be_valid
32
- end
33
- it 'should consider stop words within quotes to be valid' do
34
- GnipRule::Rule.new('"foo the bar" baz').should be_valid
35
- end
36
- it 'should consider rules without "stop words" to be valid' do
37
- GnipRule::Rule.new('value').should be_valid
38
- end
39
- end
40
-
41
- describe '#to_json' do
42
- it 'should omit tag if tag not defined' do
43
- rule = GnipRule::Rule.new('foo')
44
- rule.to_json.should == '{"value":"foo"}'
45
- end
46
- it 'should add tag if defined' do
47
- rule = GnipRule::Rule.new('foo', 'bar')
48
- rule.to_json.should == '{"value":"foo","tag":"bar"}'
49
- end
50
- end
51
-
52
- describe '#to_rule' do
53
- it 'should return itself' do
54
- rule = GnipRule::Rule.new('foo', 'bar')
55
- rule.to_rule.should == rule
56
- end
57
- end
58
- end
@@ -1,7 +0,0 @@
1
- require 'bundler'
2
- Bundler.setup
3
-
4
- require 'rspec'
5
- require 'webmock/rspec'
6
-
7
- WebMock.disable_net_connect!