Skip to content

Commit f8718b7

Browse files
authored
Merge pull request #4 from UsAndRufus/ed-register-with-price-plan
Allow registration with price plan
2 parents 01ec7d0 + cb3ba64 commit f8718b7

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

bin/console

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require "securerandom"
1010
PROTOCOL = "http"
1111
HOST = "localhost:3000"
1212
API_KEY = ENV["PRAYERMATE_API_KEY"]
13+
1314
EMAIL = ENV["EMAIL_FOR_TOKEN"]
1415
API_TOKEN = ENV["PRAYERMATE_API_TOKEN"]
1516

lib/prayermate_api.rb

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,15 @@ def resize_image(url, filename)
4040
HTTParty.post(api_path("images/resize"), body: { url: url, target_filename: filename }, headers: http_headers)
4141
end
4242

43-
def register(promo_code, first_name, last_name, email, roles)
44-
data = {
45-
promo_code: promo_code,
46-
first_name: first_name,
47-
last_name: last_name,
48-
email: email,
49-
password: SecureRandom.hex(8),
50-
roles: roles
51-
}
43+
def register_with_promo_code(promo_code, first_name, last_name, email, roles)
44+
register({ promo_code: promo_code }, first_name, last_name, email, roles)
45+
end
5246

53-
response = post_with_auth("auth/register", data)
54-
response[:password] = data[:password]
55-
response
47+
def register_with_price_plan(price_plan, first_name, last_name, email, roles)
48+
register({ price_plan: price_plan }, first_name, last_name, email, roles)
5649
end
5750

51+
5852
def update_input_feed(feed_id, user_feed_slug, petitions, last_modified, publish_as_draft = false)
5953
post_with_auth("input_feeds/process", {
6054
feed: {
@@ -95,6 +89,20 @@ def get_with_auth(endpoint, data = nil)
9589

9690
protected
9791

92+
def register(data, first_name, last_name, email, roles)
93+
data.merge!({
94+
first_name: first_name,
95+
last_name: last_name,
96+
email: email,
97+
password: SecureRandom.hex(8),
98+
roles: roles
99+
})
100+
101+
response = post_with_auth("auth/register", data)
102+
response[:password] = data[:password]
103+
response
104+
end
105+
98106
def api_path(endpoint)
99107
"#{self.url_prefix}/#{endpoint}"
100108
end

test/prayermate_api_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ def test_that_it_has_a_version_number
1717
@api = PrayerMateApi.api PROTOCOL, HOST, API_KEY, SESSION
1818
end
1919

20+
describe "when building a session" do
21+
it "must return the correct hash" do
22+
session = PrayerMateApi.build_session EMAIL, TOKEN
23+
assert_equal SESSION, session
24+
end
25+
end
26+
2027
describe "when calling the api method" do
2128
it "must create an api object" do
2229
api = PrayerMateApi.api PROTOCOL, HOST, API_KEY

0 commit comments

Comments
 (0)