View on GitHub

Gnip-rule

Ruby library for working with the Gnip Rules API

download .ZIPdownload .TGZ

This gem simplifies the effort to add/delete/list rules using the Gnip Rules API. It handles HTTP request/response and helps your rules conform to Gnip's restrictions.

Install it

gem install gnip-rule or add the following to your Gemfile:

gem 'gnip-rule', '~> 0.4.2'

Use it

require 'gnip-rule'

rules = GnipRule::Client.new(API_URL, USERNAME, PASSWORD)

# Add as a String, Rule, or Array of either
rules.add('foo')
rules.add('bar', 'tag')
rules.add(['foo', 'bar', 'baz'], 'tag')
rules.add(GnipRule::Rule.new('value', 'tag'))
rules.add([GnipRule::Rule.new('foo', 'bar'), GnipRule::Rule.new('baz', 'tag2')])

# Same with delete
rules.delete('baz', 'tag')
rules.delete(['foo', 'bar'])
rules.delete(GnipRule::Rule.new('value', 'tag'))

# Get all rules
rules_list = rules.list()
rules_list.each { |rule| rule.valid? }
jsonified = rules_list.map { |rule| rule.as_json `}
rules_tagged_foo = rules_list.select { |rule| rule.tag == 'foo' }

Compatibility

This gem is tested to be compatible with:

License

Licenced under the MIT License