Skip to content

Commit

Permalink
Merge pull request #4 from UsAndRufus/ed-register-with-price-plan
Browse files Browse the repository at this point in the history
Allow registration with price plan
  • Loading branch information
UsAndRufus authored Aug 13, 2018
2 parents 01ec7d0 + cb3ba64 commit f8718b7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require "securerandom"
PROTOCOL = "http"
HOST = "localhost:3000"
API_KEY = ENV["PRAYERMATE_API_KEY"]

EMAIL = ENV["EMAIL_FOR_TOKEN"]
API_TOKEN = ENV["PRAYERMATE_API_TOKEN"]

Expand Down
32 changes: 20 additions & 12 deletions lib/prayermate_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,15 @@ def resize_image(url, filename)
HTTParty.post(api_path("images/resize"), body: { url: url, target_filename: filename }, headers: http_headers)
end

def register(promo_code, first_name, last_name, email, roles)
data = {
promo_code: promo_code,
first_name: first_name,
last_name: last_name,
email: email,
password: SecureRandom.hex(8),
roles: roles
}
def register_with_promo_code(promo_code, first_name, last_name, email, roles)
register({ promo_code: promo_code }, first_name, last_name, email, roles)
end

response = post_with_auth("auth/register", data)
response[:password] = data[:password]
response
def register_with_price_plan(price_plan, first_name, last_name, email, roles)
register({ price_plan: price_plan }, first_name, last_name, email, roles)
end


def update_input_feed(feed_id, user_feed_slug, petitions, last_modified, publish_as_draft = false)
post_with_auth("input_feeds/process", {
feed: {
Expand Down Expand Up @@ -95,6 +89,20 @@ def get_with_auth(endpoint, data = nil)

protected

def register(data, first_name, last_name, email, roles)
data.merge!({
first_name: first_name,
last_name: last_name,
email: email,
password: SecureRandom.hex(8),
roles: roles
})

response = post_with_auth("auth/register", data)
response[:password] = data[:password]
response
end

def api_path(endpoint)
"#{self.url_prefix}/#{endpoint}"
end
Expand Down
7 changes: 7 additions & 0 deletions test/prayermate_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def test_that_it_has_a_version_number
@api = PrayerMateApi.api PROTOCOL, HOST, API_KEY, SESSION
end

describe "when building a session" do
it "must return the correct hash" do
session = PrayerMateApi.build_session EMAIL, TOKEN
assert_equal SESSION, session
end
end

describe "when calling the api method" do
it "must create an api object" do
api = PrayerMateApi.api PROTOCOL, HOST, API_KEY
Expand Down

0 comments on commit f8718b7

Please sign in to comment.