gnip-rules 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/gnip-rules/response.rb +8 -0
- data/lib/gnip-rules/validation.rb +77 -0
- data/lib/gnip-rules/validation_response.rb +70 -0
- data/lib/gnip-rules.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76ed77a083a74831fc31654bb2ffc4f286cb58e2
|
4
|
+
data.tar.gz: d36cccea30ab321a08a8e2beca47019e4c1b898f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 082fc5014ed9c1f901902634fa4b46eabe1fbf8dde7f02d39143333f2f2ed87006c33a16a9279eb0ed20e42a02c3dbb818ac526fc76a51d927c9200004283ebb
|
7
|
+
data.tar.gz: 2e14033b0096088442baa4eff5cc1adaaf8f4c90279112536cf8e846ce334dc03d5da01c82e9737521782b758b1f4c85783701e47413a5ddbd8e7187c24ba8b6
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0
|
1
|
+
2.1.0
|
data/lib/gnip-rules/response.rb
CHANGED
@@ -16,6 +16,14 @@ module Gnip
|
|
16
16
|
http_party_response["rules"].collect { |r| Hashie::Mash.new r }
|
17
17
|
end
|
18
18
|
|
19
|
+
def summary
|
20
|
+
Hashie::Mash.new http_party_response["summary"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def detail
|
24
|
+
http_party_response["detail"].collect { |r| Hashie::Mash.new r }
|
25
|
+
end
|
26
|
+
|
19
27
|
def created?
|
20
28
|
code == 201
|
21
29
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'httparty'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require 'gnip-rules/api'
|
6
|
+
require 'gnip-rules/validation_response'
|
7
|
+
require 'gnip-rules/rule'
|
8
|
+
|
9
|
+
|
10
|
+
module Gnip
|
11
|
+
class Validation
|
12
|
+
include HTTParty
|
13
|
+
|
14
|
+
headers 'Accept' => 'application/json', 'Content-Type' => 'application/json'
|
15
|
+
format :json
|
16
|
+
|
17
|
+
#debug_output $stdout
|
18
|
+
|
19
|
+
def initialize( configuration = nil, username = nil, password = nil, uri = nil, timeout = 60 )
|
20
|
+
@configuration_file = configuration
|
21
|
+
unless username && password && uri
|
22
|
+
load_credentials!
|
23
|
+
username = @config["username"]
|
24
|
+
password = @config["password"]
|
25
|
+
uri = uri || @config["validation_url"]
|
26
|
+
end
|
27
|
+
|
28
|
+
self.class.basic_auth username , password
|
29
|
+
self.class.base_uri uri
|
30
|
+
self.class.default_timeout timeout
|
31
|
+
end
|
32
|
+
|
33
|
+
def default_timeout(timeout)
|
34
|
+
self.class.default_timeout timeout
|
35
|
+
self.class.default_options
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate(rules)
|
39
|
+
options = ActiveSupport::JSON.encode( {rules: rules} )
|
40
|
+
Gnip::ValidationResponse.new self.class.post('', body: options)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def load_credentials!
|
46
|
+
if File.exists?( @configuration_file )
|
47
|
+
@config = YAML.load_file( @configuration_file )[environment.to_s]
|
48
|
+
else
|
49
|
+
raise Exception.new( <<-RUBY
|
50
|
+
You must provide a configuration file at config/gnip.yml
|
51
|
+
|
52
|
+
development: &development
|
53
|
+
username: omg@omg.com
|
54
|
+
password: your_password
|
55
|
+
account: your_account
|
56
|
+
streaming_url: 'https://gnip-stream.twitter.com/stream/powertrack/accounts/YOUR_ACCOUNT/publishers/twitter/Sandbox.json'
|
57
|
+
rules_api: 'https://gnip-api.twitter.com/rules/powertrack/accounts/YOUR_ACCOUNT/publishers/twitter/Sandbox.json'
|
58
|
+
validation_url: 'https://gnip-api.twitter.com/rules/powertrack/accounts/<accountName>/<streamLabel>/validation.json'
|
59
|
+
|
60
|
+
RUBY
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def environment
|
66
|
+
if defined?(Rails)
|
67
|
+
Rails.env
|
68
|
+
elsif defined?(RAILS_ENV)
|
69
|
+
RAILS_ENV
|
70
|
+
elsif defined?(RACK_ENV)
|
71
|
+
RACK_ENV
|
72
|
+
else
|
73
|
+
:development
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
include Forwardable
|
2
|
+
|
3
|
+
module Gnip
|
4
|
+
class ValidationResponse
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegators :@http_party_response, :response, :request, :body, :headers, :code
|
8
|
+
|
9
|
+
attr_reader :http_party_response
|
10
|
+
|
11
|
+
def initialize(http_party_response)
|
12
|
+
@http_party_response = http_party_response
|
13
|
+
end
|
14
|
+
|
15
|
+
def summary
|
16
|
+
Hashie::Mash.new http_party_response["summary"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def total_valid
|
20
|
+
summary.valid
|
21
|
+
end
|
22
|
+
|
23
|
+
def total_invalid
|
24
|
+
summary.not_valid
|
25
|
+
end
|
26
|
+
|
27
|
+
def detail
|
28
|
+
http_party_response["detail"].collect { |r| Hashie::Mash.new r }
|
29
|
+
end
|
30
|
+
|
31
|
+
def created?
|
32
|
+
code == 201
|
33
|
+
end
|
34
|
+
|
35
|
+
def unauthorized?
|
36
|
+
code == 401
|
37
|
+
end
|
38
|
+
|
39
|
+
def rate_limited?
|
40
|
+
code == 429
|
41
|
+
end
|
42
|
+
|
43
|
+
def unavailable?
|
44
|
+
code == 503
|
45
|
+
end
|
46
|
+
|
47
|
+
def bad_request?
|
48
|
+
code == 400
|
49
|
+
end
|
50
|
+
|
51
|
+
def unprocessable?
|
52
|
+
code == 422
|
53
|
+
end
|
54
|
+
|
55
|
+
def ok?
|
56
|
+
code == 200
|
57
|
+
end
|
58
|
+
|
59
|
+
def success?
|
60
|
+
ok?
|
61
|
+
end
|
62
|
+
|
63
|
+
def error
|
64
|
+
http_party_response["error"]
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
data/lib/gnip-rules.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnip-rules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spencer Markowski
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -87,6 +87,8 @@ files:
|
|
87
87
|
- lib/gnip-rules/api.rb
|
88
88
|
- lib/gnip-rules/response.rb
|
89
89
|
- lib/gnip-rules/rule.rb
|
90
|
+
- lib/gnip-rules/validation.rb
|
91
|
+
- lib/gnip-rules/validation_response.rb
|
90
92
|
- lib/gnip-rules/version.rb
|
91
93
|
- test/helper.rb
|
92
94
|
- test/test_gnip-rules.rb
|