quarantino 0.0.1 → 0.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/lib/quarantino/report.rb +38 -0
- data/lib/quarantino/version.rb +1 -1
- data/spec/report_spec.rb +74 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/responses/report.json +1 -0
- metadata +17 -10
@@ -0,0 +1,38 @@
|
|
1
|
+
module Quarantino
|
2
|
+
class Report
|
3
|
+
attr_reader :attributes
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def create(params)
|
7
|
+
Quarantino.new(params)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(params)
|
12
|
+
@attributes ||= request(params)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def request(params)
|
18
|
+
validate(params)
|
19
|
+
|
20
|
+
response = connection.post do |req|
|
21
|
+
req.url '/reports'
|
22
|
+
req.headers['Content-Type'] = 'application/json'
|
23
|
+
req.headers['X-API-Key'] = ENV['QUARANTINO_API_KEY'] if ENV['QUARANTINO_API_KEY']
|
24
|
+
req.body = {report: {session_attributes: params}}.to_json
|
25
|
+
end
|
26
|
+
|
27
|
+
JSON.parse(response.body)
|
28
|
+
end
|
29
|
+
|
30
|
+
def connection
|
31
|
+
@connection ||= Faraday.new(:url => 'http://quarantino.herokuapp.com')
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate(params)
|
35
|
+
raise ArgumentError, "Please configure QUARANTINO_API_KEY in your environment." unless ENV['QUARANTINO_API_KEY']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/quarantino/version.rb
CHANGED
data/spec/report_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Quarantino::Report do
|
4
|
+
|
5
|
+
before do
|
6
|
+
stub_request(
|
7
|
+
:post,
|
8
|
+
"http://quarantino.herokuapp.com/reports"
|
9
|
+
).to_return(
|
10
|
+
:status => 200,
|
11
|
+
:body => File.open('./spec/support/responses/report.json')
|
12
|
+
)
|
13
|
+
|
14
|
+
@session_attributes = {
|
15
|
+
"ip"=>"93.54.11.50",
|
16
|
+
"city"=>"London",
|
17
|
+
"region"=>"London",
|
18
|
+
"postal_code"=>"EC1N 2JT",
|
19
|
+
"country"=>"United Kingdom",
|
20
|
+
"forwarded_ip"=>nil, "email_md5"=>"ANB",
|
21
|
+
"username_md5"=>"ASD",
|
22
|
+
"password_md5"=>"[FILTERED]",
|
23
|
+
"app_session_id"=>"1234",
|
24
|
+
"user_agent"=>"Mozilla",
|
25
|
+
"accept_language"=>"English-US"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#new" do
|
30
|
+
it "requests a report" do
|
31
|
+
report = Quarantino::Report.new(@session_attributes)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "uses the API_KEY environment variable" do
|
35
|
+
with_env 'QUARANTINO_API_KEY', 'ABC' do
|
36
|
+
report = Quarantino::Report.new(@session_attributes)
|
37
|
+
|
38
|
+
a_request(
|
39
|
+
:post,
|
40
|
+
"http://quarantino.herokuapp.com/reports"
|
41
|
+
).with(
|
42
|
+
:headers => {'Content-Type' => 'application/json', 'X-API-Key' => ENV['QUARANTINO_API_KEY']}
|
43
|
+
).should have_been_made
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "warns about a missing API_KEY environment variable" do
|
48
|
+
with_env 'QUARANTINO_API_KEY', nil do
|
49
|
+
lambda {
|
50
|
+
report = Quarantino::Report.new(@session_attributes)
|
51
|
+
}.should raise_error ArgumentError
|
52
|
+
|
53
|
+
a_request(
|
54
|
+
:post,
|
55
|
+
"http://quarantino.herokuapp.com/reports"
|
56
|
+
).should_not have_been_made
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#attributes" do
|
62
|
+
it "sets the attributes from the report" do
|
63
|
+
report = Quarantino::Report.new(@session_attributes)
|
64
|
+
report.attributes.should == JSON.parse(File.open('./spec/support/responses/report.json').read)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def with_env(key, value, &block)
|
69
|
+
old_env = ENV[key]
|
70
|
+
ENV[key] = value
|
71
|
+
yield
|
72
|
+
ENV[key] = old_env
|
73
|
+
end
|
74
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'quarantino'
|
4
|
+
require 'rspec'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
|
8
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
9
|
+
# in spec/support/ and its subdirectories.
|
10
|
+
Dir[File.join(File.expand_path('../support', __FILE__), '**/*.rb')].each {|f| require f}
|
11
|
+
|
12
|
+
ENV['QUARANTINO_API_KEY'] = 'TEST-API-KEY'
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.color_enabled = true
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"anonymous_proxy":false,"city_postal_match":null,"country_code":"GB","country_match":true,"created_at":"2012-08-21T15:27:15Z","distance":0,"error":null,"high_risk_country":false,"high_risk_email":false,"high_risk_username":false,"id":1,"ip_accuracy_radius":15,"ip_area_code":"0","ip_asnum":"AS35228 Avatar Broadband Limited","ip_city":"London","ip_city_conf":56,"ip_continent_code":"EU","ip_corporate_proxy":false,"ip_country_name":"United Kingdom","ip_domain":"bethere.co.uk","ip_isp":"Be Un Limited","ip_latitude":"51.5142","ip_longitude":"-0.0931","ip_metro_code":"0","ip_net_speed_cell":"Cable/DSL","ip_org":"Be Un Limited","ip_postal_code":null,"ip_region":"H9","ip_region_name":"London, City of","ip_time_zone":"Europe/London","ip_user_type":"residential","score":"1.16","session_id":1,"ship_city_postal_match":null,"transparent_proxy":null,"updated_at":"2012-08-21T15:27:15Z"}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quarantino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-08-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
16
|
-
requirement: &
|
16
|
+
requirement: &70094379356060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70094379356060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70094379354440 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70094379354440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70094379352280 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.2.9
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70094379352280
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: webmock
|
49
|
-
requirement: &
|
49
|
+
requirement: &70094379365280 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70094379365280
|
58
58
|
description: Client for Quarantino
|
59
59
|
email:
|
60
60
|
- sam@samoliver.com
|
@@ -68,8 +68,12 @@ files:
|
|
68
68
|
- README.md
|
69
69
|
- Rakefile
|
70
70
|
- lib/quarantino.rb
|
71
|
+
- lib/quarantino/report.rb
|
71
72
|
- lib/quarantino/version.rb
|
72
73
|
- quarantino.gemspec
|
74
|
+
- spec/report_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
- spec/support/responses/report.json
|
73
77
|
homepage: http://github.com/widernet/quarantino-client
|
74
78
|
licenses: []
|
75
79
|
post_install_message:
|
@@ -94,4 +98,7 @@ rubygems_version: 1.8.17
|
|
94
98
|
signing_key:
|
95
99
|
specification_version: 3
|
96
100
|
summary: ''
|
97
|
-
test_files:
|
101
|
+
test_files:
|
102
|
+
- spec/report_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
- spec/support/responses/report.json
|