data_validation 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd652fcbccfb63f837d155464543810c3ade7572
4
+ data.tar.gz: a9a258b92ee872a592f71babae9fec82abdce74e
5
+ SHA512:
6
+ metadata.gz: fe948fc0a252e64389f9a93bc253b7923a54cad9d22d3baa7dadb5cd12ddce5385d317777b23677ac587d312c859b306cdf67af57a19e542e28279a67c6859b8
7
+ data.tar.gz: 6a8ed3522d18142d24e9fa2de01861e832a801fe83093c9ef8f8a76dd71746cf3229758524978578aac30d74e2ab870de745adfa242574c724efb2078fed415b
@@ -0,0 +1,17 @@
1
+ require 'data_validation/version'
2
+ require 'data_validation/api'
3
+ require 'data_validation/list'
4
+
5
+ class DataValidation
6
+ def initialize(key)
7
+ @api = DataValidation::API.new(key)
8
+ end
9
+
10
+ def create_list(members)
11
+ DataValidation::List.create(@api, members)
12
+ end
13
+
14
+ def get_list(slug)
15
+ DataValidation::List.get(@api, slug)
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ class DataValidation
5
+ class API
6
+ BASE_URI = "https://api.datavalidation.com/1.0"
7
+
8
+ attr_reader :key
9
+
10
+ def initialize(key)
11
+ @key = key
12
+ end
13
+
14
+ def get(uri, h = {})
15
+ HTTParty.get("#{BASE_URI}/#{uri}", headers: headers.merge(h))
16
+ end
17
+
18
+ def post(uri, body = nil, h = {})
19
+ q = {}
20
+ q[:body] = body unless body.nil?
21
+ q[:headers] = headers.merge(h)
22
+ HTTParty.post("#{BASE_URI}/#{uri}", q)
23
+ end
24
+
25
+ def valid_response?(response)
26
+ code = response.code
27
+ code >= 200 && code <= 299
28
+ end
29
+
30
+ private
31
+ def headers
32
+ {
33
+ 'Authorization' => "bearer #{@key}"
34
+ }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ class DataValidation
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,51 @@
1
+ class DataValidation
2
+ class Job
3
+ attr_reader :slug
4
+
5
+ def self.create(api, list)
6
+ job = DataValidation::Job.new(api, list)
7
+ job.create
8
+ job
9
+ end
10
+
11
+ def self.get(api, list, slug)
12
+ job = DataValidation::Job.new(api, list)
13
+ job.get(slug)
14
+ job
15
+ end
16
+
17
+ def initialize(api, list)
18
+ @api = api
19
+ @list = list
20
+ @slug = nil
21
+ end
22
+
23
+ def create
24
+ response = @api.post("list/#{@list.slug}/job/")
25
+ if @api.valid_response?(response)
26
+ raw = JSON.parse(response.body)
27
+ raw_job = raw["job"][0]
28
+ @slug = raw_job["slug"]
29
+ else
30
+ p response
31
+ raise DataValidation::Error, "could not create job for list #{@list.slug}"
32
+ end
33
+ end
34
+
35
+ def get(slug)
36
+ @slug = slug
37
+ end
38
+
39
+ def done?
40
+ response = @api.get("list/#{@list.slug}/job/#{@slug}/")
41
+ if @api.valid_response?(response)
42
+ raw = JSON.parse(response.body)
43
+ raw_job = raw["job"][0]
44
+ raw_pct = raw_job["pct_complete"]
45
+ return raw_pct == 100
46
+ else
47
+ raise DataValidationError, "could not check job progress for list #{@list.slug}, job #{@job.slug}"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,75 @@
1
+ require 'csv'
2
+ require 'data_validation/error'
3
+ require 'data_validation/member'
4
+ require 'data_validation/job'
5
+
6
+ class DataValidation
7
+ class List
8
+ attr_reader :slug
9
+
10
+ def self.create(api, members)
11
+ list = DataValidation::List.new(api)
12
+ list.create(members)
13
+ list
14
+ end
15
+
16
+ def self.get(api, slug)
17
+ list = DataValidation::List.new(api)
18
+ list.get(slug)
19
+ list
20
+ end
21
+
22
+ def create_job
23
+ DataValidation::Job.create(@api, self)
24
+ end
25
+
26
+ def get_job(slug)
27
+ DataValidation::Job.get(@api, self, slug)
28
+ end
29
+
30
+ def members
31
+ data = []
32
+ response = @api.get("list/#{@slug}/export.csv")
33
+ if @api.valid_response?(response)
34
+ body = response.body
35
+ CSV.parse(body) do |row|
36
+ address = row[1]
37
+ analysis = {}
38
+ analysis['grade'] = row[2]
39
+ analysis['click'] = row[3]
40
+ analysis['open'] = row[4]
41
+ analysis['hard'] = row[5]
42
+ analysis['optout'] = row[6]
43
+ analysis['complain'] = row[7]
44
+ analysis['trap'] = row[8]
45
+ analysis['deceased'] = row[9]
46
+ data << DataValidation::Member.new(address, analysis)
47
+ end
48
+ else
49
+ raise DataValidation::Error, "could not get members for list #{@slug}"
50
+ end
51
+ data
52
+ end
53
+
54
+ def initialize(api)
55
+ @api = api
56
+ @slug = nil
57
+ end
58
+
59
+ def create(members)
60
+ data = members.map{|m| m + ",\n"}.join()
61
+ response = @api.post("list/?header=false&email=0&metadata=false", data, { 'Content-Type' => 'text/csv' })
62
+ if @api.valid_response?(response)
63
+ raw = JSON.parse(response.body)
64
+ raw_list = raw["list"][0]
65
+ @slug = raw_list["slug"]
66
+ else
67
+ raise DataValidation::Error, "could not create list"
68
+ end
69
+ end
70
+
71
+ def get(slug)
72
+ @slug = slug
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,10 @@
1
+ class DataValidation
2
+ class Member
3
+ attr_reader :address, :analysis
4
+
5
+ def initialize(address, analysis)
6
+ @address = address
7
+ @analysis = analysis
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ class DataValidation
2
+ VERSION = "1.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data_validation
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Maxime Bacoux
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.14'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.14'
69
+ description:
70
+ email:
71
+ - max@bacoux.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/data_validation.rb
77
+ - lib/data_validation/api.rb
78
+ - lib/data_validation/error.rb
79
+ - lib/data_validation/job.rb
80
+ - lib/data_validation/list.rb
81
+ - lib/data_validation/member.rb
82
+ - lib/data_validation/version.rb
83
+ homepage: https://github.com/SparkUpFR/datavalidation-gem
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.6.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: A ruby interface over the DataValidation service.
107
+ test_files: []