electric_profile_ruby 1.10.0 → 1.11.0
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/lib/electric_profile_ruby/client.rb +14 -0
- data/lib/electric_profile_ruby/reward.rb +103 -0
- data/lib/electric_profile_ruby/version.rb +1 -1
- data/lib/electric_profile_ruby.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 124e4c2f8ec7c8dff15b73e31331a00cb81117a3
|
4
|
+
data.tar.gz: a53cbf29d5e00ce9bde9849fd9fb6e0f01356006
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71c53203c77943ba5d4f7131f26ab0283f8f4e7033e992982007110240f1316a4176238264c3e929612f8894f5c3d8629cba8f104a73403678b9a2b765b760f4
|
7
|
+
data.tar.gz: 67e24c352f0d18836f40f65dedd820d1bdfc7914c7b50d972cb66acf93c9ba2629d3d1e04dd8ea873f0413a85a31e37be39a79bfc05d02d198b3862254d38516
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -79,6 +79,20 @@ module ElectricProfile
|
|
79
79
|
perform_request(uri, http_request)
|
80
80
|
end
|
81
81
|
|
82
|
+
def create_reward(reward_attributes)
|
83
|
+
uri = URI(@api_url + 'reward')
|
84
|
+
http_request = Net::HTTP::Post.new uri, @http_headers
|
85
|
+
http_request.body = { "data" => reward_attributes }.to_json
|
86
|
+
perform_request(uri, http_request)
|
87
|
+
end
|
88
|
+
|
89
|
+
def update_reward(reward_attributes)
|
90
|
+
uri = URI(@api_url + 'reward')
|
91
|
+
http_request = Net::HTTP::Put.new uri, @http_headers
|
92
|
+
http_request.body = { "data" => reward_attributes }.to_json
|
93
|
+
perform_request(uri, http_request)
|
94
|
+
end
|
95
|
+
|
82
96
|
private
|
83
97
|
def perform_request(uri, http_request)
|
84
98
|
use_ssl = @api_url.include? "https"
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module ElectricProfile
|
2
|
+
|
3
|
+
class Reward
|
4
|
+
attr_accessor :id, :customerId, :rewardProfileId, :amount, :currency, :type, :recipientEmail, :recipientId, :autoClaim, :autoDeliver, :delivered, :deliveryErrors, :transactionId, :error
|
5
|
+
TYPES = ['rewardlink', 'amazon', 'paypal', 'bitcoin', 'habitat']
|
6
|
+
|
7
|
+
def initialize(atts)
|
8
|
+
atts = atts.inject({}){ |memo, (k, v) | memo[k.to_sym] = v; memo }
|
9
|
+
@id = atts[:id]
|
10
|
+
@customerId = atts[:customerId]
|
11
|
+
@rewardProfileId = atts[:rewardProfileId]
|
12
|
+
@amount = atts[:amount]
|
13
|
+
@currency = atts[:currency]
|
14
|
+
@type = atts[:type]
|
15
|
+
@recipientEmail = atts[:recipientEmail]
|
16
|
+
@recipientId = atts[:recipientId]
|
17
|
+
@autoClaim = atts[:autoClaim]
|
18
|
+
@autoDeliver = atts[:autoDeliver]
|
19
|
+
@delivered = atts[:delivered]
|
20
|
+
@deliveryErrors = atts[:deliveryErrors]
|
21
|
+
@transactionId = atts[:transactionId]
|
22
|
+
end
|
23
|
+
|
24
|
+
def save
|
25
|
+
if @id
|
26
|
+
save_existing
|
27
|
+
else
|
28
|
+
save_new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def save_new
|
33
|
+
initialize_client
|
34
|
+
attributes = {
|
35
|
+
rewardProfileId: @rewardProfileId,
|
36
|
+
amount: @amount,
|
37
|
+
currency: @currency,
|
38
|
+
type: @type,
|
39
|
+
recipientEmail: @recipientEmail,
|
40
|
+
recipientId: @recipientId,
|
41
|
+
autoClaim: @autoClaim,
|
42
|
+
autoDeliver: @autoDeliver
|
43
|
+
}
|
44
|
+
if @client.create_reward(attributes)
|
45
|
+
@id = @client.data["data"]["id"]
|
46
|
+
@customerId = @client.data["data"]["customerId"]
|
47
|
+
true
|
48
|
+
else
|
49
|
+
@error = @client.error
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def save_existing
|
55
|
+
initialize_client
|
56
|
+
attributes = {
|
57
|
+
id: @id,
|
58
|
+
customerId: @customerId,
|
59
|
+
rewardProfileId: @rewardProfileId,
|
60
|
+
amount: @amount,
|
61
|
+
currency: @currency,
|
62
|
+
type: @type,
|
63
|
+
recipientEmail: @recipientEmail,
|
64
|
+
recipientId: @recipientId,
|
65
|
+
autoClaim: @autoClaim,
|
66
|
+
autoDeliver: @autoDeliver,
|
67
|
+
delivered: @delivered,
|
68
|
+
deliveryErrors: @deliveryErrors,
|
69
|
+
transactionId: @transactionId
|
70
|
+
}
|
71
|
+
if @client.update_reward(attributes)
|
72
|
+
true
|
73
|
+
else
|
74
|
+
@error = @client.error
|
75
|
+
false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.find(id)
|
80
|
+
client = Client.new
|
81
|
+
if client.fetch_reward(id)
|
82
|
+
new client.data
|
83
|
+
else
|
84
|
+
raise StandardError, client.error
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.all
|
89
|
+
client = Client.new
|
90
|
+
if client.fetch_rewards
|
91
|
+
client.data["Items"].map { |atts| new atts }
|
92
|
+
else
|
93
|
+
raise StandardError, client.error
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def initialize_client
|
98
|
+
@client ||= Client.new
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: electric_profile_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Alston
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/electric_profile_ruby/profiler.rb
|
105
105
|
- lib/electric_profile_ruby/question.rb
|
106
106
|
- lib/electric_profile_ruby/respondent_profiler.rb
|
107
|
+
- lib/electric_profile_ruby/reward.rb
|
107
108
|
- lib/electric_profile_ruby/version.rb
|
108
109
|
homepage: http://www.bovitzinc.com
|
109
110
|
licenses:
|