perka 1.0.pre

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.
Files changed (79) hide show
  1. data/.gitignore +7 -0
  2. data/Gemfile +12 -0
  3. data/LICENSE.txt +201 -0
  4. data/README.md +17 -0
  5. data/Rakefile +70 -0
  6. data/lib/perka/client_api.rb +260 -0
  7. data/lib/perka/model/abstract_reward_confirmation.rb +15 -0
  8. data/lib/perka/model/abstract_user.rb +37 -0
  9. data/lib/perka/model/api_description.rb +22 -0
  10. data/lib/perka/model/base_entity_global.rb +27 -0
  11. data/lib/perka/model/bounce_back_target.rb +33 -0
  12. data/lib/perka/model/canned_email_outbound_message.rb +14 -0
  13. data/lib/perka/model/clerk.rb +41 -0
  14. data/lib/perka/model/composite_target.rb +22 -0
  15. data/lib/perka/model/console_message.rb +16 -0
  16. data/lib/perka/model/coupon.rb +52 -0
  17. data/lib/perka/model/coupon_campaign.rb +26 -0
  18. data/lib/perka/model/coupon_redemption.rb +26 -0
  19. data/lib/perka/model/coupon_target.rb +30 -0
  20. data/lib/perka/model/coupon_visibility.rb +29 -0
  21. data/lib/perka/model/customer.rb +41 -0
  22. data/lib/perka/model/customer_device.rb +23 -0
  23. data/lib/perka/model/endpoint_description.rb +49 -0
  24. data/lib/perka/model/entity_annotation.rb +33 -0
  25. data/lib/perka/model/entity_description.rb +31 -0
  26. data/lib/perka/model/everybody_target.rb +15 -0
  27. data/lib/perka/model/feedback_item.rb +28 -0
  28. data/lib/perka/model/first_visit_target.rb +16 -0
  29. data/lib/perka/model/idle_customer_target.rb +20 -0
  30. data/lib/perka/model/integrator_user.rb +16 -0
  31. data/lib/perka/model/internal_user.rb +15 -0
  32. data/lib/perka/model/like_to_unlock_target.rb +14 -0
  33. data/lib/perka/model/list_target.rb +17 -0
  34. data/lib/perka/model/merchant.rb +42 -0
  35. data/lib/perka/model/merchant_capability.rb +16 -0
  36. data/lib/perka/model/merchant_device.rb +29 -0
  37. data/lib/perka/model/merchant_location.rb +46 -0
  38. data/lib/perka/model/merchant_user.rb +29 -0
  39. data/lib/perka/model/nobody_target.rb +15 -0
  40. data/lib/perka/model/outbound_message.rb +14 -0
  41. data/lib/perka/model/parameter_description.rb +29 -0
  42. data/lib/perka/model/participation_target.rb +34 -0
  43. data/lib/perka/model/physical_redemption_target.rb +17 -0
  44. data/lib/perka/model/points_activity.rb +34 -0
  45. data/lib/perka/model/points_activity_confirmation.rb +24 -0
  46. data/lib/perka/model/points_catalog_item.rb +41 -0
  47. data/lib/perka/model/program.rb +35 -0
  48. data/lib/perka/model/program_tier.rb +30 -0
  49. data/lib/perka/model/program_type.rb +27 -0
  50. data/lib/perka/model/property.rb +65 -0
  51. data/lib/perka/model/punch_reward_confirmation.rb +43 -0
  52. data/lib/perka/model/push_message.rb +17 -0
  53. data/lib/perka/model/redemption_coupon_confirmation.rb +26 -0
  54. data/lib/perka/model/redemption_reward_confirmation.rb +26 -0
  55. data/lib/perka/model/reward.rb +38 -0
  56. data/lib/perka/model/reward_advancement.rb +30 -0
  57. data/lib/perka/model/reward_grant.rb +37 -0
  58. data/lib/perka/model/sms_message.rb +15 -0
  59. data/lib/perka/model/sms_outbound_message.rb +14 -0
  60. data/lib/perka/model/social_list_target.rb +14 -0
  61. data/lib/perka/model/social_service_subscription.rb +26 -0
  62. data/lib/perka/model/street_address.rb +27 -0
  63. data/lib/perka/model/tier_target.rb +24 -0
  64. data/lib/perka/model/tier_traversal.rb +30 -0
  65. data/lib/perka/model/tier_traversal_confirmation.rb +28 -0
  66. data/lib/perka/model/type.rb +33 -0
  67. data/lib/perka/model/user_credentials.rb +28 -0
  68. data/lib/perka/model/visit.rb +59 -0
  69. data/lib/perka/model/visit_confirmation.rb +47 -0
  70. data/lib/perka/model/weather_target.rb +27 -0
  71. data/lib/perka/model/yield_management_target.rb +23 -0
  72. data/lib/perka/perka_api.rb +89 -0
  73. data/lib/perka/version.rb +3 -0
  74. data/lib/perka.rb +6 -0
  75. data/lib/perka_fast.rb +68 -0
  76. data/perka.gemspec +20 -0
  77. data/spec/api_integrator_spec.rb +210 -0
  78. data/spec/model_spec.rb +24 -0
  79. metadata +178 -0
@@ -0,0 +1,210 @@
1
+ require 'perka'
2
+
3
+ #INTEGRATOR_ID = 'e475e342-a542-11e1-9f8d-cde92706a93d'
4
+ #INTEGRATOR_SECRET = 'integrator'
5
+ #API_BASE = 'http://localhost'
6
+
7
+ INTEGRATOR_ID = '44ff7a20-cb63-11e1-9b23-0800200c9a66'
8
+ INTEGRATOR_SECRET = 'foobar'
9
+ API_BASE = 'https://sandbox.getperka.com'
10
+
11
+ describe Perka::PerkaApi do
12
+ context "as an integrator user" do
13
+
14
+ # sets up an api instance for all of our tests to use
15
+ before(:all) do
16
+ @api = Perka::PerkaApi.new({
17
+ :flatpack => Flatpack::Core::Flatpack.new({
18
+ :pretty => true,
19
+ :verbose => true,
20
+ :entity_module => Perka::Model
21
+ }),
22
+ :server_base => API_BASE,
23
+ :verbose => true
24
+ })
25
+ @api.oauth_integrator_login(INTEGRATOR_ID, INTEGRATOR_SECRET)
26
+ end
27
+
28
+ # clear out all customer data before each test
29
+ before(:each) do
30
+ @api.integrator_destroy_delete.execute
31
+ end
32
+
33
+ it "creates a new managed customer" do
34
+ @api.oauth_integrator_login(INTEGRATOR_ID, INTEGRATOR_SECRET)
35
+
36
+ cred = Perka::Model::UserCredentials.new({
37
+ :email => 'joe@getperka.com',
38
+ :phone => '+15555555555'
39
+ })
40
+ customer = @api.integrator_customer_post(cred).execute
41
+
42
+ customer.unconfirmed_email.should eq('joe@getperka.com')
43
+ customer.unconfirmed_phone.should eq('+15555555555')
44
+
45
+ # another request with the same credentials should yield the same customer
46
+ new_customer = @api.integrator_customer_post(cred).execute
47
+ new_customer.uuid.should eq(customer.uuid)
48
+
49
+ # another request with the same email and different phone should
50
+ # also yield the same customer
51
+ cred = Perka::Model::UserCredentials.new({
52
+ :email => 'joe@getperka.com',
53
+ :phone => '+17777777777'
54
+ })
55
+ new_customer = @api.integrator_customer_post(cred).execute
56
+ new_customer.uuid.should eq(customer.uuid)
57
+
58
+ # similarly, same phone and different email
59
+ cred = Perka::Model::UserCredentials.new({
60
+ :email => 'joe+another@getperka.com',
61
+ :phone => '+15555555555'
62
+ })
63
+ new_customer = @api.integrator_customer_post(cred).execute
64
+ new_customer.uuid.should eq(customer.uuid)
65
+
66
+ # another request with unique values should yield a new customer
67
+ cred = Perka::Model::UserCredentials.new({
68
+ :email => 'joe+yet_another@getperka.com'
69
+ })
70
+ new_customer = @api.integrator_customer_post(cred).execute
71
+ new_customer.uuid.should_not eq(customer.uuid)
72
+ end
73
+
74
+ it "rewards punches to a new customer" do
75
+ @api.oauth_integrator_login(INTEGRATOR_ID, INTEGRATOR_SECRET)
76
+
77
+ # we'll first create a new customer
78
+ cred = Perka::Model::UserCredentials.new(:email => 'joe+yet_another@getperka.com')
79
+ customer = @api.integrator_customer_post(cred).execute
80
+
81
+ # determine the merchants associated with this integrator account.
82
+ merchants = @api.integrator_managed_merchants_get.execute
83
+
84
+ # lets assume this integrator has only one managed merchant
85
+ merchant = merchants.first
86
+
87
+ # By default, API endpoints DO NOT return a full object graph of data.
88
+ # For example, the above integrator_managed_merchants_get endpoint returns
89
+ # only the merchant with no associated location or program data. The
90
+ # describe_type_uuid_get endpoint is an exception to this rule, and will
91
+ # always peform a deep serialization of the entity being described. We'll
92
+ # now describe our merchant to gain access to our location and program data.
93
+ merchant = @api.describe_entity_get(merchant).execute
94
+
95
+ # The merchant's locations should now be populated
96
+ location = merchant.merchant_locations.first
97
+
98
+ # The program data should also be populated, so we can dig down and grab
99
+ # a program type that we'd like to award points for
100
+ program_type = merchant.program_tiers.first.programs.first.program_type
101
+
102
+ # now we'll switch our session over to a clerk at the merchant location.
103
+ # This will authorize our API to execute clerk enabled endpoints.
104
+ @api = @api.oauth_integrator_become("CLERK", location.uuid)
105
+
106
+ # we can now assign some loyalty punches to our new customer
107
+ visit = @api.customer_reward_put(Perka::Model::RewardGrant.new({
108
+ :customer => customer,
109
+ :reward_confirmations => [
110
+ Perka::Model::PunchRewardConfirmation.new({
111
+ :program_type => program_type,
112
+ :punches_earned => 2
113
+ })
114
+ ]
115
+ })).execute
116
+
117
+ # A new visit should have been returned describing the transaction.
118
+ # The customer and merchant location should be what we specified
119
+ visit.customer.uuid.should eq(customer.uuid)
120
+ visit.merchant_location.uuid.should eq(location.uuid)
121
+
122
+ # A new reward should have been advanced by 2 punches
123
+ visit.reward_advancements.length.should eq(1)
124
+ advancement = visit.reward_advancements.first
125
+ advancement.punches_earned.should eq(2)
126
+
127
+ # The reward should show a sum of only 2 punches since this is a new customer
128
+ advancement.reward.punches_earned.should eq(2)
129
+
130
+ # We'll now pull down the customer's reward status
131
+ rewards = @api.customer_reward_get.with_customer_uuid(customer.uuid).execute
132
+
133
+ # We should have only one non-activated, non-redeemed reward with 2 punches
134
+ rewards.length.should eq(1)
135
+ rewards.first.activated_at.should be_nil
136
+ rewards.first.redeemed_at.should be_nil
137
+ rewards.first.punches_earned.should eq(2)
138
+
139
+ # Now we'll give the customer another 9 punches, which should activate the
140
+ # reward and make it available for redemption, and will create another
141
+ # reward with a single punch
142
+ @api.customer_reward_put(Perka::Model::RewardGrant.new({
143
+ :customer => customer,
144
+ :reward_confirmations => [
145
+ Perka::Model::PunchRewardConfirmation.new({
146
+ :program_type => program_type,
147
+ :punches_earned => 9
148
+ })
149
+ ]
150
+ })).execute
151
+
152
+ # The customer should now one activated, and one non-activated reward
153
+ rewards = @api.customer_reward_get.with_customer_uuid(customer.uuid).execute
154
+ rewards.length.should eq(2)
155
+ active_reward = rewards.detect {|r| r.activated_at }
156
+ active_reward.activated_at.should_not be_nil
157
+ active_reward.redeemed_at.should be_nil
158
+ active_reward.punches_earned.should eq(10)
159
+
160
+ inactive_reward = rewards.detect {|r| !r.activated_at }
161
+ inactive_reward.activated_at.should be_nil
162
+ inactive_reward.redeemed_at.should be_nil
163
+ inactive_reward.punches_earned.should eq(1)
164
+
165
+ # We'll now redeem the active reward. We can also award
166
+ # more punches in the same transaction
167
+ @api.customer_reward_put(Perka::Model::RewardGrant.new({
168
+ :customer => customer,
169
+ :reward_confirmations => [
170
+ Perka::Model::RedemptionRewardConfirmation.new({
171
+ :reward => active_reward
172
+ }),
173
+ Perka::Model::PunchRewardConfirmation.new({
174
+ :program_type => program_type,
175
+ :punches_earned => 1
176
+ })
177
+ ]
178
+ })).execute
179
+
180
+ # The customer status should now show just one non-active
181
+ # reward with 2 punches
182
+ rewards = @api.customer_reward_get.with_customer_uuid(customer.uuid).execute
183
+ rewards.length.should eq(1)
184
+ rewards.first.activated_at.should be_nil
185
+ rewards.first.redeemed_at.should be_nil
186
+ rewards.first.punches_earned.should eq(2)
187
+ end
188
+
189
+ it "annotate entities with arbitrary JSON data" do
190
+ @api.oauth_integrator_login(INTEGRATOR_ID, INTEGRATOR_SECRET)
191
+
192
+ # first we'll grab a reference to one of our managed merchants
193
+ merchants = @api.integrator_managed_merchants_get.execute
194
+ merchant = merchants.first
195
+
196
+ # then apply an arbitrary annotation to the merchant
197
+ json = "{'foo':'bar'}"
198
+ @api.annotation_put(Perka::Model::EntityAnnotation.new({
199
+ :annotation => json,
200
+ :entity => merchant
201
+ })).execute
202
+
203
+ # which can be retreived at any time
204
+ annotation = @api.annotation_entity_get(merchant).execute
205
+ annotation.annotation.should eq(json)
206
+ end
207
+
208
+ end
209
+
210
+ end
@@ -0,0 +1,24 @@
1
+ require 'perka'
2
+
3
+ describe Perka::Model do
4
+ it "should pass a smoke test" do
5
+ c = Perka::Model::Customer.new({
6
+ :avatar_url => 'avatar',
7
+ :first_name => 'Joe',
8
+ :junk => 'junk'
9
+ })
10
+ c.last_name = 'Stelmach'
11
+
12
+ c.avatar_url.should eq('avatar')
13
+ c.first_name.should eq('Joe')
14
+ c.last_name.should eq('Stelmach')
15
+
16
+ flatpack = Flatpack::Core::Flatpack.new({
17
+ :pretty => false,
18
+ :verbose => false,
19
+ :entity_module => Perka::Model
20
+ })
21
+ flatpack.packer.pack(c)
22
+ end
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: perka
3
+ version: !ruby/object:Gem::Version
4
+ hash: 174811731
5
+ prerelease: true
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - pre
10
+ version: 1.0.pre
11
+ platform: ruby
12
+ authors:
13
+ - Joe Stelmach
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-27 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 2
32
+ - 6
33
+ version: "2.6"
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: flatpack_client
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - "="
43
+ - !ruby/object:Gem::Version
44
+ hash: 174811731
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - pre
49
+ version: 1.0.pre
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description: Write a gem description
53
+ email:
54
+ - joe@getperka.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/perka.rb
68
+ - lib/perka/client_api.rb
69
+ - lib/perka/model/abstract_reward_confirmation.rb
70
+ - lib/perka/model/abstract_user.rb
71
+ - lib/perka/model/api_description.rb
72
+ - lib/perka/model/base_entity_global.rb
73
+ - lib/perka/model/bounce_back_target.rb
74
+ - lib/perka/model/canned_email_outbound_message.rb
75
+ - lib/perka/model/clerk.rb
76
+ - lib/perka/model/composite_target.rb
77
+ - lib/perka/model/console_message.rb
78
+ - lib/perka/model/coupon.rb
79
+ - lib/perka/model/coupon_campaign.rb
80
+ - lib/perka/model/coupon_redemption.rb
81
+ - lib/perka/model/coupon_target.rb
82
+ - lib/perka/model/coupon_visibility.rb
83
+ - lib/perka/model/customer.rb
84
+ - lib/perka/model/customer_device.rb
85
+ - lib/perka/model/endpoint_description.rb
86
+ - lib/perka/model/entity_annotation.rb
87
+ - lib/perka/model/entity_description.rb
88
+ - lib/perka/model/everybody_target.rb
89
+ - lib/perka/model/feedback_item.rb
90
+ - lib/perka/model/first_visit_target.rb
91
+ - lib/perka/model/idle_customer_target.rb
92
+ - lib/perka/model/integrator_user.rb
93
+ - lib/perka/model/internal_user.rb
94
+ - lib/perka/model/like_to_unlock_target.rb
95
+ - lib/perka/model/list_target.rb
96
+ - lib/perka/model/merchant.rb
97
+ - lib/perka/model/merchant_capability.rb
98
+ - lib/perka/model/merchant_device.rb
99
+ - lib/perka/model/merchant_location.rb
100
+ - lib/perka/model/merchant_user.rb
101
+ - lib/perka/model/nobody_target.rb
102
+ - lib/perka/model/outbound_message.rb
103
+ - lib/perka/model/parameter_description.rb
104
+ - lib/perka/model/participation_target.rb
105
+ - lib/perka/model/physical_redemption_target.rb
106
+ - lib/perka/model/points_activity.rb
107
+ - lib/perka/model/points_activity_confirmation.rb
108
+ - lib/perka/model/points_catalog_item.rb
109
+ - lib/perka/model/program.rb
110
+ - lib/perka/model/program_tier.rb
111
+ - lib/perka/model/program_type.rb
112
+ - lib/perka/model/property.rb
113
+ - lib/perka/model/punch_reward_confirmation.rb
114
+ - lib/perka/model/push_message.rb
115
+ - lib/perka/model/redemption_coupon_confirmation.rb
116
+ - lib/perka/model/redemption_reward_confirmation.rb
117
+ - lib/perka/model/reward.rb
118
+ - lib/perka/model/reward_advancement.rb
119
+ - lib/perka/model/reward_grant.rb
120
+ - lib/perka/model/sms_message.rb
121
+ - lib/perka/model/sms_outbound_message.rb
122
+ - lib/perka/model/social_list_target.rb
123
+ - lib/perka/model/social_service_subscription.rb
124
+ - lib/perka/model/street_address.rb
125
+ - lib/perka/model/tier_target.rb
126
+ - lib/perka/model/tier_traversal.rb
127
+ - lib/perka/model/tier_traversal_confirmation.rb
128
+ - lib/perka/model/type.rb
129
+ - lib/perka/model/user_credentials.rb
130
+ - lib/perka/model/visit.rb
131
+ - lib/perka/model/visit_confirmation.rb
132
+ - lib/perka/model/weather_target.rb
133
+ - lib/perka/model/yield_management_target.rb
134
+ - lib/perka/perka_api.rb
135
+ - lib/perka/version.rb
136
+ - lib/perka_fast.rb
137
+ - perka.gemspec
138
+ - spec/api_integrator_spec.rb
139
+ - spec/model_spec.rb
140
+ has_rdoc: true
141
+ homepage: ""
142
+ licenses: []
143
+
144
+ post_install_message:
145
+ rdoc_options: []
146
+
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 3
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">"
162
+ - !ruby/object:Gem::Version
163
+ hash: 25
164
+ segments:
165
+ - 1
166
+ - 3
167
+ - 1
168
+ version: 1.3.1
169
+ requirements: []
170
+
171
+ rubyforge_project:
172
+ rubygems_version: 1.3.7
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: Write a gem summary
176
+ test_files:
177
+ - spec/api_integrator_spec.rb
178
+ - spec/model_spec.rb