thisdata 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c34091bf99a2ccce9303d2c1a3952c0c1b2a990e
4
- data.tar.gz: abf7211329821a58bcecf4fb21045562ea24f350
3
+ metadata.gz: 7dcdcde8de9993cf31989f0b1f8d44d58ecb5b12
4
+ data.tar.gz: 66da007fd238510bbab8967a3107a0f509e21b72
5
5
  SHA512:
6
- metadata.gz: 16a1310073c2fff9cd51ca8dc9c1b60b12e389cbd3b9906ef73156d8f74090fe890c06395a8e38de1b8cf6fab455fd12f8c82af7f8e7e4c42acfcddffd036cc6
7
- data.tar.gz: 3e1b4fa3752eafd370c4f398d56e3232aa1b3aa06e28ae0280331d19f05b7673294aa04c3d5301c38dd146ae14d32d84506a36faa6fdf18aa6081daa511febd6
6
+ metadata.gz: 6dac75e9d1960a4cf841fed96653d8b0c421ffc223a63b0e3116818b7f7e3e7c2282921a147492d53a47186901fdc4093a457d99c381e68b1059a6e81ddcf08c
7
+ data.tar.gz: 0cf6a8b109ca9b392be6e34e819e582a94123beef84f2e3adb41e75e14855defa014c5737feda7424f42bded94483eb692e27f90638149aa63412b43c88f3d25
data/README.md CHANGED
@@ -100,6 +100,54 @@ events.first.user.id
100
100
  => "112233"
101
101
  ```
102
102
 
103
+ #### Managing custom Rules
104
+ You can get, create, update and delete custom rules. Note that no error handling is done
105
+ within the API wrapper so you will need to watch out for error `messages` in the
106
+ response body of each call.
107
+
108
+ Create a rule
109
+ ```ruby
110
+ # returns an OpenStruct rule
111
+
112
+ rule = ThisData::Rule.create({
113
+ name: "Blacklist all ipv4 addresses",
114
+ description: "Blocks every possible ipv4 address",
115
+ type: "blacklist",
116
+ target: "location.ip",
117
+ filters: ["0.0.0.0/0"]
118
+ })
119
+
120
+ puts rule.id
121
+ puts rule.name
122
+ ...
123
+ ```
124
+
125
+ List all rules
126
+ ```ruby
127
+ rules = ThisData::Rule.all
128
+ ```
129
+
130
+ Find a single rule
131
+ ```ruby
132
+ rule = ThisData::Rule.find(1234567)
133
+ ```
134
+
135
+ Update a rule
136
+ ```ruby
137
+ # id is reqired. Other params are optional
138
+
139
+ ThisData::Rule.update({
140
+ id: "123456",
141
+ filters: ["0.0.0.0/0",""]
142
+ })
143
+ ```
144
+
145
+ Delete a rule
146
+ ```ruby
147
+ # returns bool
148
+ ThisData::Rule.delete(123456)
149
+ ```
150
+
103
151
  ### Rails
104
152
 
105
153
  #### Set Up
@@ -48,6 +48,12 @@ module ThisData
48
48
  self.class.post(path, query: query, headers: @headers, body: body)
49
49
  end
50
50
 
51
+ # Perform a DELETE request against the ThisData API, with the API key
52
+ # prepopulated
53
+ def delete(path)
54
+ self.class.delete(path, query: @default_query, headers: @headers)
55
+ end
56
+
51
57
  private
52
58
 
53
59
  def version
@@ -0,0 +1,62 @@
1
+ # A wrapper for the GET /rules API
2
+ #
3
+ # Note: No error handling is included in this wrapper
4
+ #
5
+ module ThisData
6
+ class Rule
7
+
8
+ # Fetch an array of Rules from the ThisData API
9
+ # Available options can be found at
10
+ # http://help.thisdata.com/docs/v1rules
11
+ #
12
+ # Returns: Array of OpenStruct Rule objects
13
+ def self.find(id)
14
+ response = ThisData::Client.new.get("#{ThisData::RULES_ENDPOINT}/#{id}")
15
+ OpenStruct.new( response.parsed_response)
16
+ end
17
+
18
+ # Fetch an array of Rules from the ThisData API
19
+ # Available options can be found at
20
+ # http://help.thisdata.com/docs/v1rules
21
+ #
22
+ # Returns: Array of OpenStruct Rule objects
23
+ def self.all
24
+ response = ThisData::Client.new.get(ThisData::RULES_ENDPOINT)
25
+ response.parsed_response.collect do |rule_hash|
26
+ OpenStruct.new(rule_hash)
27
+ end
28
+ end
29
+
30
+ # Create a new rule on the ThisData API
31
+ # Available options can be found at
32
+ # http://help.thisdata.com/docs/v1rules-1
33
+ #
34
+ # Returns: OpenStruct Rule object
35
+ def self.create(rule)
36
+ response = ThisData::Client.new.post(ThisData::RULES_ENDPOINT, body: JSON.generate(rule))
37
+ OpenStruct.new(response.parsed_response)
38
+ end
39
+
40
+ # Update a rule on the ThisData API
41
+ # Available options can be found at
42
+ # http://help.thisdata.com/docs/v1rulesid-1
43
+ #
44
+ # Returns: OpenStruct Rule object
45
+ def self.update(rule)
46
+ rule_id = OpenStruct.new(rule).id
47
+ response = ThisData::Client.new.post("#{ThisData::RULES_ENDPOINT}/#{rule_id}", body: JSON.generate(rule))
48
+ OpenStruct.new(response.parsed_response)
49
+ end
50
+
51
+ # Delete a rule on the ThisData API
52
+ # Available options can be found at
53
+ # http://help.thisdata.com/docs/v1rulesid-2
54
+ #
55
+ # Returns: OpenStruct Rule object
56
+ def self.destroy(id)
57
+ response = ThisData::Client.new.delete("#{ThisData::RULES_ENDPOINT}/#{id}")
58
+ response.code.eql?(204)
59
+ end
60
+
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module ThisData
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/this_data.rb CHANGED
@@ -2,6 +2,7 @@ require "httparty"
2
2
  require "logger"
3
3
  require "json"
4
4
 
5
+ require "this_data/rule"
5
6
  require "this_data/event"
6
7
  require "this_data/version"
7
8
  require "this_data/verbs"
@@ -15,6 +16,7 @@ module ThisData
15
16
  # API Endpoint Paths
16
17
  EVENTS_ENDPOINT = '/events'
17
18
  VERIFY_ENDPOINT = '/verify'
19
+ RULES_ENDPOINT = '/rules'
18
20
 
19
21
  # Risk level constants, defined at http://help.thisdata.com/docs/apiv1verify#what-does-the-risk_level-mean
20
22
  RISK_LEVEL_GREEN = 'green'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thisdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ThisData Ltd
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-26 00:00:00.000000000 Z
12
+ date: 2017-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -132,6 +132,7 @@ files:
132
132
  - lib/this_data/client.rb
133
133
  - lib/this_data/configuration.rb
134
134
  - lib/this_data/event.rb
135
+ - lib/this_data/rule.rb
135
136
  - lib/this_data/track_request.rb
136
137
  - lib/this_data/verbs.rb
137
138
  - lib/this_data/version.rb
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
159
  version: '0'
159
160
  requirements: []
160
161
  rubyforge_project:
161
- rubygems_version: 2.4.8
162
+ rubygems_version: 2.2.2
162
163
  signing_key:
163
164
  specification_version: 4
164
165
  summary: Ruby wrapper for ThisData's Login Intelligence API