prize_service 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Rakefile +1 -0
- data/lib/prize_service.rb +31 -0
- data/lib/prize_service/eligibility.rb +19 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDgyOTY3MThmNGVlOTA0NjQ1NzA4OTRjMWQ0OGJhODU5MzZiMjY0OA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzMwZDAyZmVkOTNkZDA4MjY5Njg5M2RmMzU0YmI4Y2ZjZDU5MDU1Mw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzIzY2NlN2Q1ZTU0NDk2YWM4MzY1ZTRlNmI2NDE2MmRkNzc2ZTk0NTMwYTYx
|
10
|
+
NTIzNjliNjViZGNiZjVjMTUyMWQ2YTM1NGI0MjdjN2I3NThkMjczOTBlMzZj
|
11
|
+
NzQ3ZTIyYzRiNzYzMTU3ZWY4Yjc5MzAyYWM0ZDdmZGJjMGI2N2M=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OGI2MmUyNjllMzYzYjc4ZmNjNzg5NDhlMWJkY2RiNzViYTFmNWI1NmNiZGI3
|
14
|
+
NTczN2VjYjAyMzQ1MzNkZTVkNzAzNjFiNTI5NGRjNTcwMjYzNmMyMTQxYTNh
|
15
|
+
MGEzODFkYTFkYzQ3YTdiNzNjYTJhZGM0MGZkYWJjYTFkYjRhOTY=
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class PrizeService
|
2
|
+
require 'net/http'
|
3
|
+
require 'prize_service/eligibility.rb'
|
4
|
+
|
5
|
+
#PrizeService.getPrizesForCustomer(customerAccountNumber, customersChannelPackages) #This is how it will be called, so implementing below as such..
|
6
|
+
def self.getPrizesForCustomer(customerAccountNumber, customersChannelPackages)
|
7
|
+
# If the given account number is invalid your service should raise an invalid account number error.
|
8
|
+
invalid_account_number = "Invalid Account Number ! !"
|
9
|
+
raise invalid_account_number if !customerAccountNumber.is_a? Integer
|
10
|
+
|
11
|
+
url = URI.parse('http://teamxhost/eligibility') #Defining the API url here
|
12
|
+
|
13
|
+
param = {
|
14
|
+
'customer_id' => customerAccountNumber #customer ID will be sent to the url to request the validity
|
15
|
+
}
|
16
|
+
|
17
|
+
begin
|
18
|
+
response = Net::HTTP.post_form(url, param) #Requesting the API :expecting a successful response in a format ..eg { result: { eligibility: true } }
|
19
|
+
if response[:result][:eligibility] == true
|
20
|
+
return Eligibility.eligibility(customersChannelPackages) # A place to calculate the eligibility given the channel info, since true is responded
|
21
|
+
else
|
22
|
+
return "Customer is not eligible for any prize" #because our request was responded false at this pt for eligibility
|
23
|
+
end
|
24
|
+
elsif response[:error]
|
25
|
+
return response[:error][:message] #One of the two messages expected here according to the spec
|
26
|
+
end
|
27
|
+
rescue
|
28
|
+
return [] # If the eligibility service fails for some other reason you should return an empty array.
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class PrizeService::Eligibility
|
2
|
+
def self.eligibility(channels)
|
3
|
+
#The channel packages are SPORTS, MOVIES, GOSSIP and KIDS
|
4
|
+
|
5
|
+
only_kids_channel = (channels.count == 1 and channels.first.eql?('KIDS'))
|
6
|
+
return "Customer is not eligible for any prize" if only_kids_channel #A customer eligible for a prize with only the kids package doesn't get to choose anything.
|
7
|
+
|
8
|
+
if channels.include?("SPORTS")
|
9
|
+
if channels.include?('MOVIES')
|
10
|
+
return ["FREE SPORTING EVENT TICKETS", "FREE MOVIE TICKETS"] #A customer eligible for a prize with the sports and movies package gets to choose between a sporting event ticket and a movie ticket.
|
11
|
+
else
|
12
|
+
return ["FREE SPORTING EVENT TICKETS"] #here's an issue.. the customer could have 'GOSSIP' channel as well at this pt with 'SPORTS', but the spec didn't mention any specific return so this could do
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
return ["FREE MOVIE TICKETS"] if channels.include?('MOVIES') || channels.include?('GOSSIP') #If we arrive here, probably channels doesn't include 'SPORTS', so it's fine
|
17
|
+
return []
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prize_service
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kibreab
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This is a simple task that supplies information about prize service of
|
14
|
+
a customer
|
15
|
+
email:
|
16
|
+
- kibreab@eagle-eyes4designs.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- Rakefile
|
22
|
+
- lib/prize_service.rb
|
23
|
+
- lib/prize_service/eligibility.rb
|
24
|
+
homepage: ''
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.1.11
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: prize service information of a customer
|
48
|
+
test_files: []
|