datadoctorwrapper 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gem 'json'
3
+ # Specify your gem's dependencies in datadoctorwrapper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Datadoctorwrapper
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'datadoctorwrapper'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install datadoctorwrapper
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'datadoctorwrapper/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "datadoctorwrapper"
8
+ gem.version = Datadoctorwrapper::VERSION
9
+ gem.authors = ["Vivek Porwal"]
10
+ gem.email = ["vivekporwal04@gmail.com"]
11
+ gem.description = %q{"DataDoctorWrapper is a wrapper for DataDoctor,which is a product by Better Technology Labs LLP."}
12
+ gem.summary = %q{"Its provides you the simplest way to push records and to get status and result for the same from DataDoctor."}
13
+ gem.homepage = ""
14
+ gem.add_development_dependency "json"
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
20
+
@@ -0,0 +1,3 @@
1
+ module Datadoctorwrapper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,173 @@
1
+ require "datadoctorwrapper/version"
2
+ require "json"
3
+ require "net/http"
4
+ require "open-uri"
5
+ AVAILABLE_SERVICES = ['emailifiedhq','toolsberry','contactplus','companyplus','phonester']
6
+ SERVICE_URL = {'toolsberry' => "http://submit.toolsberry.com",'emailifiedhq' => "http://submit.emailifiedhq.com",'contactplus' => "http://submit.contactpl.us",'companyplus' => "http://submit.companypl.us",'phonester' => "http://submit.phonesterit.com"}
7
+ module DataDoctorWrapper
8
+ class Client
9
+ def initialize(apikey)
10
+ @api_key = apikey
11
+ end
12
+ def push service,records
13
+ @array_of_service_with_job_id_hashes_to_return = []
14
+ if AVAILABLE_SERVICES.include? service
15
+ case service
16
+ when 'emailifiedhq'
17
+ collect_in_emailifiedhq_records records
18
+ when 'toolsberry'
19
+ collect_in_toolsberry_records records
20
+ when 'contactplus'
21
+ collect_in_contactplus_records records
22
+ when 'companyplus'
23
+ collect_in_companyplus_records records
24
+ when 'phonester'
25
+ collect_in_phonester_records records
26
+ end
27
+ else
28
+ raise "\nERROR : Invalid Service."
29
+ end
30
+ job_id = send_to service
31
+ return job_id
32
+ end
33
+ def status service,jobid
34
+ if @available_services.include? service
35
+ url = SERVICE_URL[service]
36
+ status = get_status url,jobid
37
+ return status
38
+ else
39
+ raise "\nERROR : Invalid Service."
40
+ end
41
+ end
42
+ def result service,jobid
43
+ if @available_services.include? service
44
+ url = SERVICE_URL[service]
45
+ result = get_result url,jobid
46
+ return result
47
+ else
48
+ raise "\nERROR : Invalid Service."
49
+ end
50
+ end
51
+ private
52
+ def record_format_verifier service,record
53
+ return false unless record[:uid]
54
+ case service
55
+ when 'emailifiedhq'
56
+ if record [:email]
57
+ return true
58
+ else
59
+ return false unless record[:first_name]
60
+ return false unless record[:last_name]
61
+ return false unless record[:company_url]
62
+ end
63
+ when 'toolsberry'
64
+ return false unless record[:url]
65
+ when 'contactplus'
66
+ return false unless record[:first_name]
67
+ return false unless record[:last_name]
68
+ return false unless record[:company_name]
69
+ when 'companyplus'
70
+ return false unless record[:url]
71
+ when 'phonester'
72
+ return false unless record[:number]
73
+ end
74
+ return true
75
+ end
76
+ def get_status url,jobId
77
+ uri = URI(url)
78
+ req = Net::HTTP::Get.new("/services/status.json?apikey=#{@api_key}&jobid=#{jobId}", initheader = {'Content-Type' =>'application/json'})
79
+ response = Net::HTTP.new(uri.host, uri.port).start {|http| http.request(req) }
80
+ result = JSON.parse(response.body)
81
+ status = result['result']
82
+ return status
83
+ rescue OpenURI::HTTPError => e
84
+ puts e.message
85
+ end
86
+ def get_result url,jobId
87
+ uri = URI(url)
88
+ req = Net::HTTP::Get.new("/services/result.json?apikey=#{@api_key}&jobid=#{jobId}", initheader = {'Content-Type' =>'application/json'})
89
+ response = Net::HTTP.new(uri.host, uri.port).start {|http| http.request(req) }
90
+ result = JSON.parse(response.body)
91
+ result = result['result']
92
+ rescue OpenURI::HTTPError => e
93
+ puts e.message
94
+ end
95
+ def post url,records
96
+ tries = 0
97
+ begin
98
+ tries += 1
99
+ uri = URI(url)
100
+ req = Net::HTTP::Post.new("/services/job.json?apikey=#{@api_key}", initheader = {'Content-Type' =>'application/json'})
101
+ req.body = records.to_json
102
+ response = Net::HTTP.new(uri.host, uri.port).start {|http| http.request(req) }
103
+ job_id = get_job_id response
104
+ return job_id
105
+ rescue OpenURI::HTTPError => e
106
+ puts e.message
107
+ if (tries < 4)
108
+ sleep(2**tries)
109
+ retry
110
+ end
111
+ end
112
+ end
113
+ def get_job_id response
114
+ result = JSON.parse(response.body)
115
+ job_id = result['result'] if result['result'].include?'jobid'
116
+ job_id = result['error'] if result.include?'error'
117
+ return job_id
118
+ rescue RuntimeError => e
119
+ puts e.message
120
+ end
121
+ def collect_in_toolsberry_records records
122
+ @record_data_to_process = {:records => [],:technologies => []}
123
+ records[:records].each_with_index do |record , record_no|
124
+ raise "\nArgument Error : Record format is not correct at Record_Index:: #{record_no} ::#{record}" unless record_format_verifier('toolsberry',record)
125
+ @record_data_to_process[:records] << {:uid => record[:uid],:url => record[:url]}
126
+ end
127
+ @record_data_to_process[:technologies] << records[:technologies]
128
+ @record_data_to_process[:technologies] = @record_data_to_process[:technologies].flatten
129
+ end
130
+ def collect_in_emailifiedhq_records records
131
+ @record_data_to_process = {:records => []}
132
+ records[:records].each_with_index do |record , record_no|
133
+ raise "\nArgument Error : Record format is not correct at Record_Index:: #{record_no} ::#{record}" unless record_format_verifier('emailifiedhq',record)
134
+ if record[:email]
135
+ @record_data_to_process[:records] << {:uid => record[:uid],:email => record[:email]}
136
+ else
137
+ @record_data_to_process[:records] << {:uid => record[:uid],:first_name => record[:first_name],:middle_name => record[:middle_name] ||"",:last_name => record[:last_name], :company_url => record[:company_url]}
138
+ end
139
+ end
140
+ end
141
+ def collect_in_contactplus_records records
142
+ @record_data_to_process = {:service => "segment",:records => [],:keywords => []}
143
+ records[:records].each_with_index do |record , record_no|
144
+ raise "\nArgument Error : Record format is not correct at Record_Index:: #{record_no} ::#{record}" unless record_format_verifier('contactplus',record)
145
+ @record_data_to_process[:records] << {:uid => record[:uid],:firstName => record[:first_name],:lastName => record[:last_name],:companyName => record[:company_name]}
146
+ end
147
+ @record_data_to_process[:keywords] << records[:keywords]
148
+ @record_data_to_process[:keywords] = @record_data_to_process[:keywords].flatten
149
+ end
150
+ def collect_in_companyplus_records records
151
+ @record_data_to_process = {:records => [],:keywords => []}
152
+ records[:records].each_with_index do |record , record_no|
153
+ raise "\nArgument Error : Record format is not correct at Record_Index:: #{record_no} ::#{record}" unless record_format_verifier('companyplus',record)
154
+ @record_data_to_process[:records] << {:uid => record[:uid],:url => record[:url]}
155
+ end
156
+ @record_data_to_process[:keywords] << records[:keywords]
157
+ @record_data_to_process[:keywords] = @record_data_to_process[:keywords].flatten
158
+ end
159
+ def collect_in_phonester_records records
160
+ @record_data_to_process = {:records => []}
161
+ records[:records].each_with_index do |record , record_no|
162
+ raise "\nArgument Error : Record format is not correct at Record_Index:: #{record_no} ::#{record}" unless record_format_verifier('phonester',record)
163
+ @record_data_to_process[:records] << {:uid => record[:uid],:number => record[:number]}
164
+ end
165
+ end
166
+ def send_to service
167
+ job_id = post SERVICE_URL[service],@record_data_to_process
168
+ return job_id
169
+ rescue RuntimeError => e
170
+ puts e.message
171
+ end
172
+ end
173
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datadoctorwrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vivek Porwal
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: ! '"DataDoctorWrapper is a wrapper for DataDoctor,which is a product
31
+ by Better Technology Labs LLP."'
32
+ email:
33
+ - vivekporwal04@gmail.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - datadoctorwrapper.gemspec
44
+ - lib/datadoctorwrapper.rb
45
+ - lib/datadoctorwrapper/version.rb
46
+ homepage: ''
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.24
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: ! '"Its provides you the simplest way to push records and to get status and
70
+ result for the same from DataDoctor."'
71
+ test_files: []