mass_invite 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +5 -0
- data/LICENSE +16 -0
- data/README.md +66 -0
- data/Rakefile +25 -0
- data/data/customers +32 -0
- data/lib/mass_invite.rb +24 -0
- data/lib/mass_invite/customer.rb +72 -0
- data/lib/mass_invite/location.rb +108 -0
- data/lib/mass_invite/version.rb +21 -0
- data/mass_invite.gemspec +29 -0
- data/test/lib/mass_invite/customer_test.rb +107 -0
- data/test/lib/mass_invite/location_test.rb +52 -0
- data/test/test_helper.rb +24 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d4e4d500c852dd338c938c4814d42b0caa98cd47
|
4
|
+
data.tar.gz: 5be1ffdfcea0d7c3274a701f72776c415d7f1584
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5b71a637c95ee90f1ae4e8bf82eb71107b40a7e3cf73018d2677fb5b96c4d1a49c56fac03d32d201cf984b51a8edd6b9f5ea233a34bf58e104b8d9f22695ac8
|
7
|
+
data.tar.gz: 6e0b4863792978bc68b3b56402e78adb0375815e6bc1b9c966b3cf6210c5fbd44b765b193368276ac2beb9654fc1e64c7cc7a9716f7c53b4c7e18362b551d008
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
This library can be pluggled into a bigger application and solve the problem
|
2
|
+
with mass invitation for your users/customers.
|
3
|
+
Copyright (C) 2017 Hamed Ramezanian Nik
|
4
|
+
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
This program is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Mass Invite
|
2
|
+
|
3
|
+
This library can be pluggled into a bigger application and solve the problem
|
4
|
+
with mass invitation for your users/customers.
|
5
|
+
|
6
|
+
## Requirements
|
7
|
+
Ruby >= 2.4
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
### RubyGems
|
12
|
+
|
13
|
+
Add this to the Gemfile:
|
14
|
+
|
15
|
+
gem 'mass_invite'
|
16
|
+
|
17
|
+
or install it directly:
|
18
|
+
|
19
|
+
gem install mass_invite
|
20
|
+
|
21
|
+
### Install from Git
|
22
|
+
|
23
|
+
Add the following in the Gemfile:
|
24
|
+
|
25
|
+
gem 'mass_invite', :git => 'https://github.com/iCEAGE/mass_invite.git'
|
26
|
+
|
27
|
+
|
28
|
+
## Getting Started
|
29
|
+
|
30
|
+
Please follow the [installation](#installation) procedure and then run the following code:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'mass_invite'
|
34
|
+
|
35
|
+
include MassInvite
|
36
|
+
|
37
|
+
customers = Customer.create_from_file
|
38
|
+
loc = Location.new(53.3393, -6.2576841)
|
39
|
+
|
40
|
+
customers.select{|c| c.location.distance_from(loc) < 100}.sort_by(&:user_id).each do |c|
|
41
|
+
puts "#{c.name}/#{c.user_id}"
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
## Tests
|
46
|
+
To run the tests:
|
47
|
+
````
|
48
|
+
bundle exec rake
|
49
|
+
````
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
Copyright (C) 2017 Hamed Ramezanian Nik
|
54
|
+
|
55
|
+
This program is free software: you can redistribute it and/or modify
|
56
|
+
it under the terms of the GNU Lesser General Public License as published by
|
57
|
+
the Free Software Foundation, either version 3 of the License, or
|
58
|
+
(at your option) any later version.
|
59
|
+
|
60
|
+
This program is distributed in the hope that it will be useful,
|
61
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
62
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
63
|
+
GNU Lesser General Public License for more details.
|
64
|
+
|
65
|
+
You should have received a copy of the GNU Lesser General Public License
|
66
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# This library can be pluggled into a bigger application and solve the problem
|
2
|
+
# with mass invitation for your users/customers.
|
3
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require 'rake/testtask'
|
19
|
+
|
20
|
+
Rake::TestTask.new do |t|
|
21
|
+
t.test_files = FileList['test/lib/mass_invite/*_test.rb']
|
22
|
+
t.verbose = true
|
23
|
+
end
|
24
|
+
|
25
|
+
task default: :test
|
data/data/customers
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
{"latitude": "52.986375", "user_id": 12, "name": "Christina McArdle", "longitude": "-6.043701"}
|
2
|
+
{"latitude": "51.92893", "user_id": 1, "name": "Alice Cahill", "longitude": "-10.27699"}
|
3
|
+
{"latitude": "51.8856167", "user_id": 2, "name": "Ian McArdle", "longitude": "-10.4240951"}
|
4
|
+
{"latitude": "52.3191841", "user_id": 3, "name": "Jack Enright", "longitude": "-8.5072391"}
|
5
|
+
{"latitude": "53.807778", "user_id": 28, "name": "Charlie Halligan", "longitude": "-7.714444"}
|
6
|
+
{"latitude": "53.4692815", "user_id": 7, "name": "Frank Kehoe", "longitude": "-9.436036"}
|
7
|
+
{"latitude": "54.0894797", "user_id": 8, "name": "Eoin Ahearn", "longitude": "-6.18671"}
|
8
|
+
{"latitude": "53.038056", "user_id": 26, "name": "Stephen McArdle", "longitude": "-7.653889"}
|
9
|
+
{"latitude": "54.1225", "user_id": 27, "name": "Enid Gallagher", "longitude": "-8.143333"}
|
10
|
+
{"latitude": "53.1229599", "user_id": 6, "name": "Theresa Enright", "longitude": "-6.2705202"}
|
11
|
+
{"latitude": "52.2559432", "user_id": 9, "name": "Jack Dempsey", "longitude": "-7.1048927"}
|
12
|
+
{"latitude": "52.240382", "user_id": 10, "name": "Georgina Gallagher", "longitude": "-6.972413"}
|
13
|
+
{"latitude": "53.2451022", "user_id": 4, "name": "Ian Kehoe", "longitude": "-6.238335"}
|
14
|
+
{"latitude": "53.1302756", "user_id": 5, "name": "Nora Dempsey", "longitude": "-6.2397222"}
|
15
|
+
{"latitude": "53.008769", "user_id": 11, "name": "Richard Finnegan", "longitude": "-6.1056711"}
|
16
|
+
{"latitude": "53.1489345", "user_id": 31, "name": "Alan Behan", "longitude": "-6.8422408"}
|
17
|
+
{"latitude": "53", "user_id": 13, "name": "Olive Ahearn", "longitude": "-7"}
|
18
|
+
{"latitude": "51.999447", "user_id": 14, "name": "Helen Cahill", "longitude": "-9.742744"}
|
19
|
+
{"latitude": "52.966", "user_id": 15, "name": "Michael Ahearn", "longitude": "-6.463"}
|
20
|
+
{"latitude": "52.366037", "user_id": 16, "name": "Ian Larkin", "longitude": "-8.179118"}
|
21
|
+
{"latitude": "54.180238", "user_id": 17, "name": "Patricia Cahill", "longitude": "-5.920898"}
|
22
|
+
{"latitude": "53.0033946", "user_id": 39, "name": "Lisa Ahearn", "longitude": "-6.3877505"}
|
23
|
+
{"latitude": "52.228056", "user_id": 18, "name": "Bob Larkin", "longitude": "-7.915833"}
|
24
|
+
{"latitude": "54.133333", "user_id": 24, "name": "Rose Enright", "longitude": "-6.433333"}
|
25
|
+
{"latitude": "55.033", "user_id": 19, "name": "Enid Cahill", "longitude": "-8.112"}
|
26
|
+
{"latitude": "53.521111", "user_id": 20, "name": "Enid Enright", "longitude": "-9.831111"}
|
27
|
+
{"latitude": "51.802", "user_id": 21, "name": "David Ahearn", "longitude": "-9.442"}
|
28
|
+
{"latitude": "54.374208", "user_id": 22, "name": "Charlie McArdle", "longitude": "-8.371639"}
|
29
|
+
{"latitude": "53.74452", "user_id": 29, "name": "Oliver Ahearn", "longitude": "-7.11167"}
|
30
|
+
{"latitude": "53.761389", "user_id": 30, "name": "Nick Enright", "longitude": "-7.2875"}
|
31
|
+
{"latitude": "54.080556", "user_id": 23, "name": "Eoin Gallagher", "longitude": "-6.361944"}
|
32
|
+
{"latitude": "52.833502", "user_id": 25, "name": "David Behan", "longitude": "-8.522366"}
|
data/lib/mass_invite.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This library can be pluggled into a bigger application and solve the problem
|
2
|
+
# with mass invitation for your users/customers.
|
3
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require_relative 'mass_invite/version'
|
19
|
+
require_relative 'mass_invite/customer'
|
20
|
+
require_relative 'mass_invite/location'
|
21
|
+
|
22
|
+
# MassInvite module
|
23
|
+
module MassInvite
|
24
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# This library can be pluggled into a bigger application and solve the problem
|
2
|
+
# with mass invitation for your users/customers.
|
3
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require 'json'
|
19
|
+
|
20
|
+
module MassInvite
|
21
|
+
# Customer class
|
22
|
+
class Customer
|
23
|
+
attr_reader :user_id, :name
|
24
|
+
attr_accessor :location
|
25
|
+
|
26
|
+
def initialize(user_id, name, location)
|
27
|
+
self.user_id = user_id
|
28
|
+
self.name = name
|
29
|
+
self.location = location
|
30
|
+
end
|
31
|
+
|
32
|
+
def user_id=(value)
|
33
|
+
unless value.is_a?(Integer)
|
34
|
+
raise ArgumentError, 'User ID should be an integer value.'
|
35
|
+
end
|
36
|
+
|
37
|
+
@user_id = value
|
38
|
+
end
|
39
|
+
|
40
|
+
def name=(value)
|
41
|
+
unless value.is_a?(String)
|
42
|
+
raise ArgumentError, 'Name should be a string value.'
|
43
|
+
end
|
44
|
+
|
45
|
+
raise ArgumentError, "Name can't be empty." if value.empty?
|
46
|
+
|
47
|
+
@name = value
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.create_from_file(path = nil)
|
51
|
+
default_path = File.expand_path('../../../data/customers', __FILE__)
|
52
|
+
customers_file =
|
53
|
+
if path
|
54
|
+
File.open(path)
|
55
|
+
else
|
56
|
+
File.open(default_path)
|
57
|
+
end
|
58
|
+
|
59
|
+
customers_file.each_line.map do |line|
|
60
|
+
create_from_json_string(line)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.create_from_json_string(line)
|
65
|
+
parsed_line = JSON.parse(line, symbolize_names: true)
|
66
|
+
|
67
|
+
loc = Location.new(parsed_line[:latitude],
|
68
|
+
parsed_line[:longitude])
|
69
|
+
Customer.new(parsed_line[:user_id], parsed_line[:name], loc)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# This library can be pluggled into a bigger application and solve the problem
|
2
|
+
# with mass invitation for your users/customers.
|
3
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
module MassInvite
|
19
|
+
# Location class
|
20
|
+
class Location
|
21
|
+
RAD_PER_DEG = Math::PI / 180
|
22
|
+
EARTH_RADIUS_IN_KM = 6371
|
23
|
+
LAT_LONG_REGEX = /^(\+|\-|)(\d+(\.\d+)?)$/
|
24
|
+
|
25
|
+
attr_reader :lat, :long
|
26
|
+
|
27
|
+
def initialize(lat, long)
|
28
|
+
self.lat = lat
|
29
|
+
self.long = long
|
30
|
+
end
|
31
|
+
|
32
|
+
def distance_from(location)
|
33
|
+
distance(location)
|
34
|
+
end
|
35
|
+
|
36
|
+
def lat_in_rad
|
37
|
+
@lat * RAD_PER_DEG
|
38
|
+
end
|
39
|
+
|
40
|
+
def long_in_rad
|
41
|
+
@long * RAD_PER_DEG
|
42
|
+
end
|
43
|
+
|
44
|
+
def lat=(value)
|
45
|
+
@lat = validate_lat(value)
|
46
|
+
end
|
47
|
+
|
48
|
+
def long=(value)
|
49
|
+
@long = validate_long(value)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def distance(loc)
|
55
|
+
# Delta, converted to rad
|
56
|
+
dlat_rad = (loc.lat - @lat).abs * RAD_PER_DEG
|
57
|
+
dlon_rad = (loc.long - @long).abs * RAD_PER_DEG
|
58
|
+
|
59
|
+
a = Math.sin(dlat_rad / 2)**2 + Math.cos(lat_in_rad) *
|
60
|
+
Math.cos(loc.lat_in_rad) *
|
61
|
+
Math.sin(dlon_rad / 2)**2
|
62
|
+
d = 2 * Math.asin(Math.sqrt(a))
|
63
|
+
|
64
|
+
# Delta in km
|
65
|
+
EARTH_RADIUS_IN_KM * d
|
66
|
+
end
|
67
|
+
|
68
|
+
def validate_lat(value)
|
69
|
+
lat = case value
|
70
|
+
when String
|
71
|
+
unless value =~ LAT_LONG_REGEX
|
72
|
+
raise ArgumentError, 'Latitude is not valid.'
|
73
|
+
end
|
74
|
+
|
75
|
+
value.to_f
|
76
|
+
when Float
|
77
|
+
value
|
78
|
+
else
|
79
|
+
raise ArgumentError, 'Latitude should be a float/string value.'
|
80
|
+
end
|
81
|
+
|
82
|
+
raise ArgumentError, 'Latitude is not valid.' if lat > 90.0 || lat < -90.0
|
83
|
+
|
84
|
+
lat
|
85
|
+
end
|
86
|
+
|
87
|
+
def validate_long(value)
|
88
|
+
long = case value
|
89
|
+
when String
|
90
|
+
unless value =~ LAT_LONG_REGEX
|
91
|
+
raise ArgumentError, 'Longitude is not valid.'
|
92
|
+
end
|
93
|
+
|
94
|
+
value.to_f
|
95
|
+
when Float
|
96
|
+
value
|
97
|
+
else
|
98
|
+
raise ArgumentError, 'Longitude should be a float/string value.'
|
99
|
+
end
|
100
|
+
|
101
|
+
if long > 180.0 || long < -180.0
|
102
|
+
raise ArgumentError, 'Longitude is not valid.'
|
103
|
+
end
|
104
|
+
|
105
|
+
long
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This library can be pluggled into a bigger application and solve the problem
|
2
|
+
# with mass invitation for your users/customers.
|
3
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
# Library version
|
19
|
+
module MassInvite
|
20
|
+
VERSION = '0.0.1'.freeze unless defined? MassInvite::VERSION
|
21
|
+
end
|
data/mass_invite.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require_relative 'lib/mass_invite'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'mass_invite'
|
7
|
+
gem.version = MassInvite::VERSION
|
8
|
+
gem.platform = Gem::Platform::RUBY
|
9
|
+
gem.authors = ['Hamed Ramezanian Nik']
|
10
|
+
gem.email = ['hamed.r.nik@gmail.com']
|
11
|
+
gem.summary = 'This library can be pluggled into a bigger application '\
|
12
|
+
'and solve the problem with mass invitation for your users/customers.'
|
13
|
+
gem.description = 'This library can be pluggled into a bigger application '\
|
14
|
+
'and solve the problem with mass invitation for your users/customers.'
|
15
|
+
gem.homepage = 'https://github.com/iCEAGE/mass_invite'
|
16
|
+
gem.license = 'LGPL-3.0'
|
17
|
+
|
18
|
+
gem.files = `git ls-files | grep -Ev '^(myapp|examples)'`.split("\n")
|
19
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map do |f|
|
21
|
+
File.basename(f)
|
22
|
+
end
|
23
|
+
gem.require_paths = ['lib']
|
24
|
+
|
25
|
+
gem.required_ruby_version = '>= 2.4'
|
26
|
+
|
27
|
+
gem.add_development_dependency 'rake', '~> 12.0'
|
28
|
+
gem.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.1'
|
29
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# This library can be pluggled into a bigger application and solve the problem
|
2
|
+
# with mass invitation for your users/customers.
|
3
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require_relative '../../test_helper'
|
19
|
+
|
20
|
+
class CustomerTest < MassInviteTest
|
21
|
+
def setup
|
22
|
+
@location = Location.new(53.1302756, -6.2397222)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_create_a_customer
|
26
|
+
customer = Customer.new(12, 'Hamed R. Nik', @location)
|
27
|
+
assert_kind_of Customer, customer
|
28
|
+
assert_equal customer.user_id, 12
|
29
|
+
assert_equal customer.name, 'Hamed R. Nik'
|
30
|
+
assert_equal customer.location.lat, @location.lat
|
31
|
+
assert_equal customer.location.long, @location.long
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_create_from_json
|
35
|
+
customer_line = { user_id: 14, name: 'Hamed R. Nik',
|
36
|
+
latitude: @location.lat, longitude: @location.long }
|
37
|
+
customer = Customer.create_from_json_string(customer_line.to_json)
|
38
|
+
assert_kind_of Customer, customer
|
39
|
+
assert_equal customer.user_id, 14
|
40
|
+
assert_equal customer.name, 'Hamed R. Nik'
|
41
|
+
assert_equal customer.location.lat, @location.lat
|
42
|
+
assert_equal customer.location.long, @location.long
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_create_from_json_with_invalid_location
|
46
|
+
customer_line = { user_id: 14, name: 'Hamed R. Nik',
|
47
|
+
latitude: 'something', longitude: @location.long }
|
48
|
+
assert_raises ArgumentError do
|
49
|
+
Customer.create_from_json_string(customer_line.to_json)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_create_from_json_with_nil_location
|
54
|
+
customer_line = { user_id: 14, name: 'Hamed R. Nik',
|
55
|
+
latitude: nil, longitude: @location.long }
|
56
|
+
assert_raises ArgumentError do
|
57
|
+
Customer.create_from_json_string(customer_line.to_json)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_create_from_json_with_empty_location
|
62
|
+
customer_line = { user_id: 14, name: 'Hamed R. Nik',
|
63
|
+
latitude: @location.lat, longitude: '' }
|
64
|
+
assert_raises ArgumentError do
|
65
|
+
Customer.create_from_json_string(customer_line.to_json)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_create_from_json_with_no_location
|
70
|
+
customer_line = { user_id: 14, name: 'Hamed R. Nik',
|
71
|
+
latitude: @location.lat }
|
72
|
+
assert_raises ArgumentError do
|
73
|
+
Customer.create_from_json_string(customer_line.to_json)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_create_from_malformed_json_string
|
78
|
+
customer_line = 'Malformed JSON String'
|
79
|
+
assert_raises JSON::ParserError do
|
80
|
+
Customer.create_from_json_string(customer_line)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_create_from_file
|
85
|
+
customers = Customer.create_from_file
|
86
|
+
assert_kind_of Array, customers
|
87
|
+
assert_equal customers.count, 32
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_user_id_should_be_integer
|
91
|
+
assert_raises ArgumentError do
|
92
|
+
Customer.new('10', 'Richard', @location)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_name_should_be_string
|
97
|
+
assert_raises ArgumentError do
|
98
|
+
Customer.new(34, 444, @location)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_name_should_not_be_an_empty_string
|
103
|
+
assert_raises ArgumentError do
|
104
|
+
Customer.new(34, '', @location)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# This library can be pluggled into a bigger application and solve the problem
|
2
|
+
# with mass invitation for your users/customers.
|
3
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require_relative '../../test_helper'
|
19
|
+
|
20
|
+
class LocationTest < MassInviteTest
|
21
|
+
def test_create_a_location_from_float
|
22
|
+
location = Location.new(51.92893, -10.27699)
|
23
|
+
assert_kind_of Location, location
|
24
|
+
assert_equal location.lat, 51.92893
|
25
|
+
assert_equal location.long, -10.27699
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_create_a_location_from_string
|
29
|
+
location = Location.new('51.92893', '-10.27699')
|
30
|
+
assert_kind_of Location, location
|
31
|
+
assert_equal location.lat, 51.92893
|
32
|
+
assert_equal location.long, -10.27699
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_create_a_location_with_invalid_string
|
36
|
+
assert_raises ArgumentError do
|
37
|
+
Location.new('551.92893', '-1550.27699')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_lat_and_long_should_be_valid
|
42
|
+
assert_raises ArgumentError do
|
43
|
+
Location.new(251.92893, -10.27699)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_distance_between_two_points
|
48
|
+
l1 = Location.new(53.314858, -6.289984)
|
49
|
+
l2 = Location.new(53.057425, -6.156493)
|
50
|
+
assert_equal l1.distance_from(l2).round, 30
|
51
|
+
end
|
52
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This library can be pluggled into a bigger application and solve the problem
|
2
|
+
# with mass invitation for your users/customers.
|
3
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require_relative '../lib/mass_invite'
|
19
|
+
|
20
|
+
require 'minitest/autorun'
|
21
|
+
|
22
|
+
class MassInviteTest < MiniTest::Test
|
23
|
+
include MassInvite
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mass_invite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hamed Ramezanian Nik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '12.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.10'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 5.10.1
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '5.10'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 5.10.1
|
47
|
+
description: This library can be pluggled into a bigger application and solve the
|
48
|
+
problem with mass invitation for your users/customers.
|
49
|
+
email:
|
50
|
+
- hamed.r.nik@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- ".gitignore"
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- data/customers
|
61
|
+
- lib/mass_invite.rb
|
62
|
+
- lib/mass_invite/customer.rb
|
63
|
+
- lib/mass_invite/location.rb
|
64
|
+
- lib/mass_invite/version.rb
|
65
|
+
- mass_invite.gemspec
|
66
|
+
- test/lib/mass_invite/customer_test.rb
|
67
|
+
- test/lib/mass_invite/location_test.rb
|
68
|
+
- test/test_helper.rb
|
69
|
+
homepage: https://github.com/iCEAGE/mass_invite
|
70
|
+
licenses:
|
71
|
+
- LGPL-3.0
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.4'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.6.12
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: This library can be pluggled into a bigger application and solve the problem
|
93
|
+
with mass invitation for your users/customers.
|
94
|
+
test_files:
|
95
|
+
- test/lib/mass_invite/customer_test.rb
|
96
|
+
- test/lib/mass_invite/location_test.rb
|
97
|
+
- test/test_helper.rb
|