gnip-rule 0.1.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +1 -0
- data/CONTRIBUTING.md +9 -0
- data/README.md +19 -17
- data/lib/gnip-rule/client.rb +3 -1
- data/lib/gnip-rule/rule.rb +0 -1
- data/lib/gnip-rule/version.rb +1 -1
- data/spec/gnip-rule/client_spec.rb +0 -2
- metadata +3 -2
data/.travis.yml
CHANGED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,9 @@
|
|
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/README.md
CHANGED
@@ -1,35 +1,37 @@
|
|
1
|
-
# gnip-rule
|
2
|
-
|
1
|
+
# gnip-rule [](http://travis-ci.org/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
3
|
|
4
4
|
## Installation
|
5
|
-
|
5
|
+
`gem install gnip-rule` or add the following to your `Gemfile`:
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
gem 'gnip-rule', '~> 0.
|
8
|
+
gem 'gnip-rule', '~> 0.2'
|
9
9
|
```
|
10
10
|
|
11
|
-
##
|
11
|
+
## Usage
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
require 'gnip-rule'
|
15
15
|
|
16
|
-
|
16
|
+
rules = GnipRule::Client.new(API_URL, USERNAME, PASSWORD)
|
17
17
|
|
18
18
|
# Add as a String, Rule, or Array of either
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
24
|
|
25
25
|
# Same with delete
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
rules.delete('baz', 'tag')
|
27
|
+
rules.delete(['foo', 'bar'])
|
28
|
+
rules.delete(GnipRule::Rule.new('value', 'tag'))
|
29
29
|
|
30
|
-
# Get all
|
31
|
-
|
30
|
+
# Get all rules
|
31
|
+
rules.list()
|
32
32
|
```
|
33
33
|
|
34
34
|
## License
|
35
|
-
MIT License
|
35
|
+
Licenced under the [MIT License](http://www.opensource.org/licenses/mit-license.php)
|
36
|
+
|
37
|
+
I provide this software free of charge. If you find it helpful, please endorse me on coderwall: [](http://coderwall.com/eriwen)
|
data/lib/gnip-rule/client.rb
CHANGED
@@ -49,16 +49,18 @@ module GnipRule
|
|
49
49
|
|
50
50
|
protected
|
51
51
|
def post(url, data)
|
52
|
+
err = nil
|
52
53
|
Curl::Easy.http_post(url, data) do |curl|
|
53
54
|
curl.http_auth_types = :basic
|
54
55
|
curl.username = @username
|
55
56
|
curl.password = @password
|
56
57
|
curl.on_complete do |res|
|
57
58
|
if res.response_code >= 400
|
58
|
-
|
59
|
+
err = "Got #{res.response_code}; body: #{res.body_str}"
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
63
|
+
raise err if err
|
62
64
|
end
|
63
65
|
end
|
64
66
|
end
|
data/lib/gnip-rule/rule.rb
CHANGED
@@ -10,7 +10,6 @@ module GnipRule
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def valid?
|
13
|
-
# See http://docs.gnip.com/w/page/35663947/Power%20Track
|
14
13
|
if contains_stop_word?(@value) || too_long?(@value) || contains_negated_or?(@value) || too_many_positive_terms?(@value) || contains_empty_source?(@value)
|
15
14
|
return false
|
16
15
|
end
|
data/lib/gnip-rule/version.rb
CHANGED
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.
|
4
|
+
version: '0.2'
|
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-09-
|
12
|
+
date: 2012-09-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- .pryrc
|
83
83
|
- .rvmrc
|
84
84
|
- .travis.yml
|
85
|
+
- CONTRIBUTING.md
|
85
86
|
- Gemfile
|
86
87
|
- LICENSE
|
87
88
|
- README.md
|