gnip-rules 2.0.1 → 2.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 736a9e73eb51a1272e83dacf4685e36cf282bc11
4
- data.tar.gz: cbb8d004e582c6eb236c707138925b05f9ae1c00
3
+ metadata.gz: 76ed77a083a74831fc31654bb2ffc4f286cb58e2
4
+ data.tar.gz: d36cccea30ab321a08a8e2beca47019e4c1b898f
5
5
  SHA512:
6
- metadata.gz: 756072af31498d47fc17a004d69ec249926157af643bba36061bfcd0041323be0e25edb5089239875fe3e8fea71edfea964e764401b84c74f736c87636e038a0
7
- data.tar.gz: b6a12643c1de15a4f9da0194bc93c53a820fc9b7b36fdf89c3de9c3fa52ef5ab4bce63c21041f55ea52507d37a0ba1712826bcb75f6b35f9d342fa5c97f6b5de
6
+ metadata.gz: 082fc5014ed9c1f901902634fa4b46eabe1fbf8dde7f02d39143333f2f2ed87006c33a16a9279eb0ed20e42a02c3dbb818ac526fc76a51d927c9200004283ebb
7
+ data.tar.gz: 2e14033b0096088442baa4eff5cc1adaaf8f4c90279112536cf8e846ce334dc03d5da01c82e9737521782b758b1f4c85783701e47413a5ddbd8e7187c24ba8b6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.1.0
@@ -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
@@ -5,6 +5,7 @@ require 'json'
5
5
  require 'gnip-rules/api'
6
6
  require 'gnip-rules/response'
7
7
  require 'gnip-rules/rule'
8
+ require 'gnip-rules/validation'
8
9
 
9
10
  module Gnip
10
11
  class Rules
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.1
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-09-28 00:00:00.000000000 Z
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